mirror of
https://github.com/videolan/vlc-android
synced 2024-12-04 15:23:51 +08:00
Prevent displaying media content when the permission is not granted
This commit is contained in:
parent
dbab387fcf
commit
7c11e62985
@ -25,6 +25,7 @@ import android.content.SharedPreferences
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.*
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.view.ActionMode
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
@ -147,6 +148,15 @@ class VideoGridFragment : MediaBrowserFragment<VideosViewModel>(), SwipeRefreshL
|
||||
lifecycleScope.launch {
|
||||
waitForML()
|
||||
viewModel.provider.pagedList.observe(this@VideoGridFragment) {
|
||||
// if (!Permissions.canReadVideos(AppContextProvider.appContext)) {
|
||||
// if (viewModel.provider.isEmpty())
|
||||
// viewModel.provider.clear()
|
||||
// else
|
||||
// lifecycleScope.launch(Dispatchers.Main) {
|
||||
// updateEmptyView()
|
||||
// }
|
||||
// return@observe
|
||||
// }
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
(it as? PagedList<MediaLibraryItem>)?.let { pagedList -> videoListAdapter.submitList(pagedList) }
|
||||
updateEmptyView()
|
||||
|
@ -38,6 +38,7 @@ class AlbumsProvider(val parent : MediaLibraryItem?, context: Context, model: So
|
||||
override fun canSortByReleaseDate() = true
|
||||
override fun canSortByArtist() = true
|
||||
override fun canSortByInsertionDate()= true
|
||||
override val isAudioPermDependant = true
|
||||
|
||||
init {
|
||||
sort = Settings.getInstance(context).getInt(sortKey, if (parent is Artist) Medialibrary.SORT_RELEASEDATE else Medialibrary.SORT_DEFAULT)
|
||||
|
@ -28,6 +28,7 @@ import org.videolan.tools.Settings
|
||||
import org.videolan.vlc.viewmodels.SortableModel
|
||||
|
||||
class ArtistsProvider(context: Context, model: SortableModel, var showAll: Boolean) : MedialibraryProvider<Artist>(context, model) {
|
||||
override val isAudioPermDependant = true
|
||||
|
||||
override fun getAll() : Array<Artist> = medialibrary.getArtists(showAll, sort, desc, Settings.includeMissing, onlyFavorites)
|
||||
|
||||
|
@ -26,6 +26,9 @@ import org.videolan.tools.Settings
|
||||
import org.videolan.vlc.viewmodels.SortableModel
|
||||
|
||||
class FoldersProvider(context: Context, model: SortableModel, val type: Int) : MedialibraryProvider<Folder>(context, model) {
|
||||
|
||||
override val isVideoPermDependant = true
|
||||
|
||||
override fun getAll() : Array<Folder> = medialibrary.getFolders(type, sort, desc, Settings.includeMissing, onlyFavorites, getTotalCount(), 0)
|
||||
|
||||
override fun getTotalCount() = if (model.filterQuery.isNullOrEmpty()) medialibrary.getFoldersCount(type) else medialibrary.getFoldersCount(model.filterQuery)
|
||||
|
@ -28,6 +28,7 @@ import org.videolan.tools.Settings
|
||||
import org.videolan.vlc.viewmodels.SortableModel
|
||||
|
||||
class GenresProvider(context: Context, model: SortableModel) : MedialibraryProvider<Genre>(context, model) {
|
||||
override val isAudioPermDependant = true
|
||||
|
||||
override fun getAll() : Array<Genre> = medialibrary.getGenres(sort, desc, Settings.includeMissing, onlyFavorites)
|
||||
|
||||
|
@ -63,6 +63,9 @@ abstract class MedialibraryProvider<T : MediaLibraryItem>(val context: Context,
|
||||
field = value
|
||||
}
|
||||
|
||||
open val isVideoPermDependant = false
|
||||
open val isAudioPermDependant = false
|
||||
|
||||
protected open val sortKey : String = this.javaClass.simpleName
|
||||
var sort = settings.getInt(sortKey, Medialibrary.SORT_DEFAULT)
|
||||
var desc = settings.getBoolean("${sortKey}_desc", false)
|
||||
@ -148,6 +151,11 @@ abstract class MedialibraryProvider<T : MediaLibraryItem>(val context: Context,
|
||||
|
||||
fun refresh(): Boolean {
|
||||
if ((isRefreshing && medialibrary.isWorking) || !medialibrary.isStarted || !this::dataSource.isInitialized) return false
|
||||
if (isVideoPermDependant && !Permissions.canReadVideos(context)) return false
|
||||
if (isAudioPermDependant && !Permissions.canReadAudios(context)) {
|
||||
loading.postValue(false)
|
||||
return false
|
||||
}
|
||||
privateHeaders.clear()
|
||||
if (!dataSource.isInvalid) {
|
||||
isRefreshing = true
|
||||
@ -175,6 +183,11 @@ abstract class MedialibraryProvider<T : MediaLibraryItem>(val context: Context,
|
||||
inner class MLDataSource : PositionalDataSource<T>() {
|
||||
|
||||
override fun loadInitial(params: LoadInitialParams, callback: LoadInitialCallback<T>) {
|
||||
if (isVideoPermDependant && !Permissions.canReadVideos(context)) return callback.onResult(emptyList(), 0, 0)
|
||||
if (isAudioPermDependant && !Permissions.canReadAudios(context)) {
|
||||
loading.postValue(false)
|
||||
return callback.onResult(emptyList(), 0, 0)
|
||||
}
|
||||
val page = getPage(params.requestedLoadSize, params.requestedStartPosition)
|
||||
val count = if (page.size < params.requestedLoadSize) page.size else getTotalCount()
|
||||
try {
|
||||
|
@ -40,6 +40,7 @@ class TracksProvider(val parent : MediaLibraryItem?, context: Context, model: So
|
||||
override fun canSortByName() = parent !is Playlist
|
||||
override fun canSortByFileNameName() = parent !is Playlist
|
||||
override fun canSortByTrackId() = parent is Album
|
||||
override val isAudioPermDependant = true
|
||||
|
||||
init {
|
||||
sort = Settings.getInstance(context).getInt(sortKey, Medialibrary.SORT_DEFAULT)
|
||||
|
@ -15,6 +15,7 @@ class VideoGroupsProvider(context: Context, model: SortableModel) : Medialibrary
|
||||
override fun canSortByInsertionDate() = true
|
||||
override fun canSortByLastModified() = true
|
||||
override fun canSortByMediaNumber() = true
|
||||
override val isVideoPermDependant = true
|
||||
|
||||
override fun getAll() : Array<VideoGroup> = medialibrary.getVideoGroups(sort, desc, Settings.includeMissing, onlyFavorites, getTotalCount(), 0)
|
||||
|
||||
|
@ -36,6 +36,7 @@ class VideosProvider(val folder : Folder?, val group: VideoGroup?, context: Cont
|
||||
override fun canSortByDuration() = true
|
||||
override fun canSortByLastModified() = folder == null
|
||||
override fun canSortByInsertionDate() = group == null
|
||||
override val isVideoPermDependant = true
|
||||
|
||||
override fun getTotalCount() = if (model.filterQuery == null) when {
|
||||
folder !== null -> folder.mediaCount(Folder.TYPE_FOLDER_VIDEO)
|
||||
|
Loading…
Reference in New Issue
Block a user