[Android] Favs: display only network if no permissions
Duncan McNamara
git at videolan.org
Mon Feb 14 09:15:39 UTC 2022
vlc-android | branch: master | Duncan McNamara <dcn.mcnamara at gmail.com> | Fri Feb 11 11:31:23 2022 +0100| [774010f03dde80aa91450a77faea6d5173d68a69] | committer: Duncan McNamara
Favs: display only network if no permissions
When the user hasn't given storage permission, favorites should be
displayed, but only from network
> https://code.videolan.org/videolan/vlc-android/commit/774010f03dde80aa91450a77faea6d5173d68a69
---
.../src/main/java/org/videolan/vlc/mediadb/BrowserFavDao.kt | 2 +-
.../org/videolan/television/ui/MediaItemDetailsFragment.kt | 7 ++-----
.../src/org/videolan/vlc/repository/BrowserFavRepository.kt | 12 +++++++++---
3 files changed, 12 insertions(+), 9 deletions(-)
diff --git a/application/mediadb/src/main/java/org/videolan/vlc/mediadb/BrowserFavDao.kt b/application/mediadb/src/main/java/org/videolan/vlc/mediadb/BrowserFavDao.kt
index b63847196..aef1a7065 100644
--- a/application/mediadb/src/main/java/org/videolan/vlc/mediadb/BrowserFavDao.kt
+++ b/application/mediadb/src/main/java/org/videolan/vlc/mediadb/BrowserFavDao.kt
@@ -41,7 +41,7 @@ interface BrowserFavDao {
fun getAll(): Flow<List<BrowserFav>>
@Query("SELECT * from fav_table where type = 0")
- fun getAllNetworkFavs(): LiveData<List<BrowserFav>>
+ fun getAllNetworkFavs(): Flow<List<BrowserFav>>
@Query("SELECT * from fav_table where type = 1")
fun getAllLocalFavs(): LiveData<List<BrowserFav>>
diff --git a/application/television/src/main/java/org/videolan/television/ui/MediaItemDetailsFragment.kt b/application/television/src/main/java/org/videolan/television/ui/MediaItemDetailsFragment.kt
index 326a6aaea..26eea5ed6 100644
--- a/application/television/src/main/java/org/videolan/television/ui/MediaItemDetailsFragment.kt
+++ b/application/television/src/main/java/org/videolan/television/ui/MediaItemDetailsFragment.kt
@@ -33,10 +33,7 @@ import androidx.fragment.app.activityViewModels
import androidx.leanback.app.BackgroundManager
import androidx.leanback.app.DetailsSupportFragment
import androidx.leanback.widget.*
-import androidx.lifecycle.AndroidViewModel
-import androidx.lifecycle.MediatorLiveData
-import androidx.lifecycle.ViewModelProvider
-import androidx.lifecycle.lifecycleScope
+import androidx.lifecycle.*
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.channels.actor
@@ -464,7 +461,7 @@ class MediaItemDetailsModel(context: Application) : AndroidViewModel(context), C
}
init {
- browserFavUpdated.addSource(repository.networkFavs) { favList ->
+ browserFavUpdated.addSource(repository.networkFavs.asLiveData()) { favList ->
val convertFavorites = convertFavorites(favList)
if (oldList.isEmpty()) oldList.addAll(convertFavorites)
if (listenForNetworkFav)
diff --git a/application/vlc-android/src/org/videolan/vlc/repository/BrowserFavRepository.kt b/application/vlc-android/src/org/videolan/vlc/repository/BrowserFavRepository.kt
index ef3aadd7e..260980c37 100644
--- a/application/vlc-android/src/org/videolan/vlc/repository/BrowserFavRepository.kt
+++ b/application/vlc-android/src/org/videolan/vlc/repository/BrowserFavRepository.kt
@@ -36,6 +36,7 @@ import org.videolan.tools.SingletonHolder
import org.videolan.vlc.database.BrowserFavDao
import org.videolan.vlc.database.MediaDatabase
import org.videolan.vlc.mediadb.models.BrowserFav
+import org.videolan.vlc.util.Permissions
import org.videolan.vlc.util.convertFavorites
import java.util.*
@@ -46,7 +47,12 @@ class BrowserFavRepository(private val browserFavDao: BrowserFavDao) {
val networkFavs by lazy { browserFavDao.getAllNetworkFavs() }
- val browserFavorites by lazy { browserFavDao.getAll() }
+ val browserFavorites by lazy {
+ if (Permissions.canReadStorage(AppContextProvider.appContext))
+ browserFavDao.getAll()
+ else
+ browserFavDao.getAllNetworkFavs()
+ }
val localFavorites by lazy { browserFavDao.getAllLocalFavs() }
@@ -60,9 +66,9 @@ class BrowserFavRepository(private val browserFavDao: BrowserFavDao) {
val networkFavorites by lazy {
MediatorLiveData<List<MediaWrapper>>().apply {
- addSource(networkFavs) { value = convertFavorites(it).filterNetworkFavs() }
+ addSource(networkFavs.asLiveData()) { value = convertFavorites(it).filterNetworkFavs() }
addSource(networkMonitor.connectionFlow.asLiveData()) {
- val favList = convertFavorites(networkFavs.value)
+ val favList = convertFavorites(networkFavs.asLiveData().value)
if (favList.isNotEmpty()) value = if (it.connected) favList.filterNetworkFavs() else emptyList()
}
}
More information about the Android
mailing list