Commit 4374edd7 authored by Geoffrey Métais's avatar Geoffrey Métais

Local folders favorites on TV

parent 31307700
......@@ -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()
......@@ -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
......@@ -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()
})
}
......
......@@ -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)));
......
......@@ -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"));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment