[Android] Split favorites from browser in the TV main screen
Nicolas Pomepuy
git at videolan.org
Tue Feb 13 10:19:45 UTC 2024
vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Wed Feb 7 14:25:39 2024 +0100| [1473b54ee6730d829861c4e9caf77372502389c2] | committer: Duncan McNamara
Split favorites from browser in the TV main screen
> https://code.videolan.org/videolan/vlc-android/commit/1473b54ee6730d829861c4e9caf77372502389c2
---
.../src/main/java/org/videolan/resources/Constants.kt | 1 +
.../main/java/org/videolan/television/ui/MainTvFragment.kt | 11 ++++++++++-
.../java/org/videolan/television/viewmodel/MainTvModel.kt | 7 +++++--
3 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/application/resources/src/main/java/org/videolan/resources/Constants.kt b/application/resources/src/main/java/org/videolan/resources/Constants.kt
index c18d1bd94d..be3caaa708 100644
--- a/application/resources/src/main/java/org/videolan/resources/Constants.kt
+++ b/application/resources/src/main/java/org/videolan/resources/Constants.kt
@@ -154,6 +154,7 @@ const val HEADER_RECENTLY_PLAYED = 32L
const val HEADER_RECENTLY_ADDED = 33L
const val HEADER_NOW_PLAYING = 34L
const val HEADER_PERMISSION = 35L
+const val HEADER_FAVORITES = 36L
const val ID_SETTINGS = 10L
const val ID_ABOUT_TV = 11L
const val ID_REFRESH = 13L
diff --git a/application/television/src/main/java/org/videolan/television/ui/MainTvFragment.kt b/application/television/src/main/java/org/videolan/television/ui/MainTvFragment.kt
index 69d15193f7..44bf516467 100644
--- a/application/television/src/main/java/org/videolan/television/ui/MainTvFragment.kt
+++ b/application/television/src/main/java/org/videolan/television/ui/MainTvFragment.kt
@@ -97,6 +97,7 @@ class MainTvFragment : BrowseSupportFragment(), OnItemViewSelectedListener, OnIt
private lateinit var categoriesAdapter: ArrayObjectAdapter
private lateinit var historyAdapter: ArrayObjectAdapter
private lateinit var playlistAdapter: ArrayObjectAdapter
+ private lateinit var favoritesAdapter: ArrayObjectAdapter
private lateinit var browserAdapter: ArrayObjectAdapter
private lateinit var otherAdapter: ArrayObjectAdapter
@@ -107,6 +108,7 @@ class MainTvFragment : BrowseSupportFragment(), OnItemViewSelectedListener, OnIt
private lateinit var audioRow: ListRow
private lateinit var historyRow: ListRow
private lateinit var playlistRow: ListRow
+ private lateinit var favoritesRow: ListRow
private lateinit var browsersRow: ListRow
private lateinit var miscRow: ListRow
@@ -177,6 +179,10 @@ class MainTvFragment : BrowseSupportFragment(), OnItemViewSelectedListener, OnIt
playlistRow = ListRow(playlistHeader, playlistAdapter)
// rowsAdapter.add(playlistRow)
+ favoritesAdapter = ArrayObjectAdapter(CardPresenter(ctx))
+ val favoritesHeader = HeaderItem(HEADER_PLAYLISTS, getString(R.string.favorites))
+ favoritesRow = ListRow(favoritesHeader, favoritesAdapter)
+
//Browser section
browserAdapter = ArrayObjectAdapter(CardPresenter(ctx))
val browserHeader = HeaderItem(HEADER_NETWORK, getString(R.string.browsing))
@@ -241,6 +247,9 @@ class MainTvFragment : BrowseSupportFragment(), OnItemViewSelectedListener, OnIt
browserAdapter.setItems(it, diffCallback)
addAndCheckLoadedLines(HEADER_NETWORK)
}
+ model.favoritesList.observe(requireActivity()) {
+ favoritesAdapter.setItems(it, diffCallback)
+ }
model.audioCategories.observe(requireActivity()) {
categoriesAdapter.setItems(it.toList(), diffCallback)
addAndCheckLoadedLines(HEADER_CATEGORIES)
@@ -297,7 +306,7 @@ class MainTvFragment : BrowseSupportFragment(), OnItemViewSelectedListener, OnIt
}
private fun resetLines() {
- val adapters = listOf(nowPlayingRow, recentlyPlayedRow, recentlyAdddedRow, videoRow, audioRow, playlistRow, historyRow, browsersRow, miscRow).filter {
+ val adapters = listOf(nowPlayingRow, recentlyPlayedRow, recentlyAdddedRow, videoRow, audioRow, playlistRow, historyRow, favoritesRow, browsersRow, miscRow).filter {
when {
!displayRecentlyPlayed && it == recentlyPlayedRow -> false
!displayRecentlyAdded && it == recentlyAdddedRow -> false
diff --git a/application/television/src/main/java/org/videolan/television/viewmodel/MainTvModel.kt b/application/television/src/main/java/org/videolan/television/viewmodel/MainTvModel.kt
index 4718a0243a..a8c366787d 100644
--- a/application/television/src/main/java/org/videolan/television/viewmodel/MainTvModel.kt
+++ b/application/television/src/main/java/org/videolan/television/viewmodel/MainTvModel.kt
@@ -86,6 +86,7 @@ class MainTvModel(app: Application) : AndroidViewModel(app), Medialibrary.OnMedi
val nowPlaying: LiveData<List<MediaLibraryItem>> = MutableLiveData()
val videos: LiveData<List<MediaLibraryItem>> = MutableLiveData()
val audioCategories: LiveData<List<MediaLibraryItem>> = MutableLiveData()
+ val favoritesList: LiveData<List<MediaLibraryItem>> = MutableLiveData()
val browsers: LiveData<List<MediaLibraryItem>> = MutableLiveData()
val history: LiveData<List<MediaWrapper>> = MutableLiveData()
val playlist: LiveData<List<MediaLibraryItem>> = MutableLiveData()
@@ -230,12 +231,14 @@ class MainTvModel(app: Application) : AndroidViewModel(app), Medialibrary.OnMedi
}
private suspend fun updateBrowsers() {
- val list = mutableListOf<MediaLibraryItem>()
+ val favList = mutableListOf<MediaLibraryItem>()
updatedFavoriteList.forEach {
it.description = it.uri.scheme
it.addFlags(FAVORITE_FLAG)
- list.add(it)
+ favList.add(it)
}
+ (favoritesList as MutableLiveData).value = favList
+ val list = mutableListOf<MediaLibraryItem>()
val directories = DirectoryRepository.getInstance(context).getMediaDirectoriesList(context).toMutableList()
if (!showInternalStorage && directories.isNotEmpty()) directories.removeAt(0)
directories.forEach { if (it.location.scanAllowed()) list.add(it) }
More information about the Android
mailing list