[Android] Local folders favorites on TV

Geoffrey Métais git at videolan.org
Tue Oct 16 18:00:11 CEST 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Oct 16 17:59:47 2018 +0200| [4374edd71b598bce9e9ce333ddb2a6dc9276976f] | committer: Geoffrey Métais

Local folders favorites on TV

> https://code.videolan.org/videolan/vlc-android/commit/4374edd71b598bce9e9ce333ddb2a6dc9276976f
---

 vlc-android/src/org/videolan/vlc/database/MediaDatabase.kt       | 3 ++-
 vlc-android/src/org/videolan/vlc/database/Migrations.kt          | 2 +-
 vlc-android/src/org/videolan/vlc/gui/tv/MainTvFragment.kt        | 7 ++++---
 .../src/org/videolan/vlc/gui/tv/MediaItemDetailsFragment.java    | 9 ++++++---
 vlc-android/src/org/videolan/vlc/util/FileUtils.java             | 6 ++----
 5 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/database/MediaDatabase.kt b/vlc-android/src/org/videolan/vlc/database/MediaDatabase.kt
index 5e4c6c74e..de1187058 100644
--- a/vlc-android/src/org/videolan/vlc/database/MediaDatabase.kt
+++ b/vlc-android/src/org/videolan/vlc/database/MediaDatabase.kt
@@ -31,6 +31,7 @@ import org.videolan.vlc.database.models.BrowserFav
 import org.videolan.vlc.database.models.CustomDirectory
 import org.videolan.vlc.database.models.ExternalSub
 import org.videolan.vlc.database.models.Slave
+import org.videolan.vlc.util.AndroidDevices
 
 private const val DB_NAME = "vlc_database"
 
@@ -55,7 +56,7 @@ private fun buildDatabase(context: Context) = Room.databaseBuilder(context.appli
                 migration_21_22, migration_22_23, migration_23_24, migration_24_25,
                 migration_25_26, migration_26_27, migration_27_28)
         .addCallback(object : RoomDatabase.Callback() {
-            override fun onCreate(db: SupportSQLiteDatabase) { populateDB(context) }
+            override fun onCreate(db: SupportSQLiteDatabase) { if (!AndroidDevices.isTv) populateDB(context) }
         })
         .build()
 
diff --git a/vlc-android/src/org/videolan/vlc/database/Migrations.kt b/vlc-android/src/org/videolan/vlc/database/Migrations.kt
index 30bd9514b..20de47527 100644
--- a/vlc-android/src/org/videolan/vlc/database/Migrations.kt
+++ b/vlc-android/src/org/videolan/vlc/database/Migrations.kt
@@ -204,5 +204,5 @@ fun populateDB(context: Context) = GlobalScope.launch(Dispatchers.IO) {
             AndroidDevices.MediaFolders.EXTERNAL_PUBLIC_PODCAST_DIRECTORY_URI,
             AndroidDevices.MediaFolders.EXTERNAL_PUBLIC_DOWNLOAD_DIRECTORY_URI,
             AndroidDevices.MediaFolders.WHATSAPP_VIDEOS_FILE_URI)
-    for (uri in uris) favRepo.addLocalFavItem(uri, uri.lastPathSegment)
+    for (uri in uris) favRepo.addLocalFavItem(uri, uri.lastPathSegment ?: "")
 }
\ No newline at end of file
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/MainTvFragment.kt b/vlc-android/src/org/videolan/vlc/gui/tv/MainTvFragment.kt
index 0e4ef3667..22ec517e9 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/MainTvFragment.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/MainTvFragment.kt
@@ -45,6 +45,7 @@ import org.videolan.vlc.BuildConfig
 import org.videolan.vlc.ExternalMonitor
 import org.videolan.vlc.R
 import org.videolan.vlc.RecommendationsService
+import org.videolan.vlc.database.models.BrowserFav
 import org.videolan.vlc.gui.preferences.PreferencesFragment
 import org.videolan.vlc.gui.tv.MainTvActivity.ACTIVITY_RESULT_PREFERENCES
 import org.videolan.vlc.gui.tv.MainTvActivity.BROWSER_TYPE
@@ -88,7 +89,7 @@ class MainTvFragment : BrowseSupportFragment(), OnItemViewSelectedListener, OnIt
     private lateinit var browserFavRepository: BrowserFavRepository
 
     private var updatedFavoritList: List<MediaWrapper> = listOf()
-    private lateinit var favorites: LiveData<List<MediaWrapper>>
+    private lateinit var favorites: LiveData<List<BrowserFav>>
 
     override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
@@ -109,9 +110,9 @@ class MainTvFragment : BrowseSupportFragment(), OnItemViewSelectedListener, OnIt
         nowPlayingDelegate = NowPlayingDelegate(this)
 
         browserFavRepository = BrowserFavRepository.getInstance(requireContext())
-        favorites = browserFavRepository.networkFavorites
+        favorites = browserFavRepository.browserFavorites
         favorites.observe(this, Observer{
-            it?.let{ list ->  updatedFavoritList = list }
+            updatedFavoritList = convertFavorites(it)
             updateBrowsers()
         })
     }
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/MediaItemDetailsFragment.java b/vlc-android/src/org/videolan/vlc/gui/tv/MediaItemDetailsFragment.java
index d6a572fc0..077ee5f05 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/MediaItemDetailsFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/MediaItemDetailsFragment.java
@@ -145,7 +145,10 @@ public class MediaItemDetailsFragment extends DetailsSupportFragment implements
                         activity.finish();
                         break;
                     case ID_FAVORITE_ADD:
-                        mBrowserFavRepository.addNetworkFavItem(Uri.parse(mMedia.getLocation()), mMedia.getTitle(), mMedia.getArtworkUrl());
+                        final Uri uri = Uri.parse(mMedia.getLocation());
+                        final boolean local = "file".equals(uri.getScheme());
+                        if (local) mBrowserFavRepository.addLocalFavItem(uri, mMedia.getTitle(), mMedia.getArtworkUrl());
+                        else mBrowserFavRepository.addNetworkFavItem(uri, mMedia.getTitle(), mMedia.getArtworkUrl());
                         detailsOverview.removeAction(actionAdd);
                         detailsOverview.addAction(actionDelete);
                         mRowsAdapter.notifyArrayItemRangeChanged(0, mRowsAdapter.size());
@@ -184,7 +187,7 @@ public class MediaItemDetailsFragment extends DetailsSupportFragment implements
                         break;
                     case ID_PLAY_FROM_START:
                         VideoPlayerActivity.start(getActivity(), media.getUri(), true);
-                        getActivity().finish();
+                        activity.finish();
                         break;
                 }
             }
@@ -221,7 +224,7 @@ public class MediaItemDetailsFragment extends DetailsSupportFragment implements
                             if (cover == null)
                                 detailsOverview.setImageDrawable(ContextCompat.getDrawable(activity, R.drawable.ic_default_cone));
                             else
-                                detailsOverview.setImageBitmap(getActivity(), cover);
+                                detailsOverview.setImageBitmap(activity, cover);
 
                             detailsOverview.addAction(new Action(ID_PLAY, getString(R.string.play)));
                             detailsOverview.addAction(new Action(ID_LISTEN, getString(R.string.listen)));
diff --git a/vlc-android/src/org/videolan/vlc/util/FileUtils.java b/vlc-android/src/org/videolan/vlc/util/FileUtils.java
index 9447acb8a..26480e8b2 100644
--- a/vlc-android/src/org/videolan/vlc/util/FileUtils.java
+++ b/vlc-android/src/org/videolan/vlc/util/FileUtils.java
@@ -262,11 +262,9 @@ public class FileUtils {
     }
 
     public static boolean canSave(MediaWrapper mw) {
-        if (mw == null || mw.getUri() == null)
-            return false;
+        if (mw == null || mw.getUri() == null) return false;
         final String scheme = mw.getUri().getScheme();
-        return !TextUtils.equals(scheme, "file") &&
-                (TextUtils.equals(scheme, "smb")
+        return (TextUtils.equals(scheme, "file") || TextUtils.equals(scheme, "smb")
                         || TextUtils.equals(scheme, "nfs") || TextUtils.equals(scheme, "ftp")
                         || TextUtils.equals(scheme, "ftps") || TextUtils.equals(scheme, "sftp"));
     }



More information about the Android mailing list