[Android] Allow using the app without the permission on TV
Nicolas Pomepuy
git at videolan.org
Mon Jul 5 11:12:29 UTC 2021
vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Fri Jun 18 14:20:51 2021 +0200| [801264b3e47f1ad1ffdee491297b82c1c35d1531] | committer: Nicolas Pomepuy
Allow using the app without the permission on TV
> https://code.videolan.org/videolan/vlc-android/commit/801264b3e47f1ad1ffdee491297b82c1c35d1531
---
.../main/java/org/videolan/resources/Constants.kt | 1 +
.../src/main/res/drawable/ic_permission_big.xml | 9 ++++++++
.../org/videolan/television/ui/MainTvActivity.kt | 4 ----
.../org/videolan/television/ui/MainTvFragment.kt | 1 -
.../videolan/television/viewmodel/MainTvModel.kt | 24 +++++++++++++++++-----
.../src/org/videolan/vlc/gui/helpers/UiTools.kt | 1 +
6 files changed, 30 insertions(+), 10 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 9643dbfb6..d50e2c952 100644
--- a/application/resources/src/main/java/org/videolan/resources/Constants.kt
+++ b/application/resources/src/main/java/org/videolan/resources/Constants.kt
@@ -130,6 +130,7 @@ const val HEADER_TV_SHOW = 31L
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 ID_SETTINGS = 10L
const val ID_ABOUT_TV = 11L
const val ID_LICENCE = 12L
diff --git a/application/resources/src/main/res/drawable/ic_permission_big.xml b/application/resources/src/main/res/drawable/ic_permission_big.xml
new file mode 100644
index 000000000..2979b13b0
--- /dev/null
+++ b/application/resources/src/main/res/drawable/ic_permission_big.xml
@@ -0,0 +1,9 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="90dp"
+ android:height="90dp"
+ android:viewportWidth="24"
+ android:viewportHeight="24">
+ <path
+ android:fillColor="#757575"
+ android:pathData="M12,17c1.1,0 2,-0.9 2,-2s-0.9,-2 -2,-2 -2,0.9 -2,2 0.9,2 2,2zM18,8h-1L17,6c0,-2.76 -2.24,-5 -5,-5S7,3.24 7,6h1.9c0,-1.71 1.39,-3.1 3.1,-3.1 1.71,0 3.1,1.39 3.1,3.1v2L6,8c-1.1,0 -2,0.9 -2,2v10c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2L20,10c0,-1.1 -0.9,-2 -2,-2zM18,20L6,20L6,10h12v10z" />
+</vector>
diff --git a/application/television/src/main/java/org/videolan/television/ui/MainTvActivity.kt b/application/television/src/main/java/org/videolan/television/ui/MainTvActivity.kt
index 864797a65..e30abf75b 100644
--- a/application/television/src/main/java/org/videolan/television/ui/MainTvActivity.kt
+++ b/application/television/src/main/java/org/videolan/television/ui/MainTvActivity.kt
@@ -76,10 +76,6 @@ class MainTvActivity : BaseTvActivity() {
Util.checkCpuCompatibility(this)
- // Delay access permission dialog prompt to avoid background corruption
- if (!Permissions.canReadStorage(this))
- handler.postDelayed({ Permissions.checkReadStoragePermission(this at MainTvActivity) }, 1000)
-
setContentView(R.layout.tv_main)
val fragmentManager = supportFragmentManager
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 8ec1ebe4d..ce252233b 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
@@ -24,7 +24,6 @@ package org.videolan.television.ui
import android.content.Intent
import android.os.Bundle
-import android.util.Log
import android.view.View
import androidx.core.content.ContextCompat
import androidx.leanback.app.BackgroundManager
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 62633dd87..1fcb5a6fa 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
@@ -58,6 +58,7 @@ import org.videolan.vlc.media.PlaylistManager
import org.videolan.vlc.mediadb.models.BrowserFav
import org.videolan.vlc.repository.BrowserFavRepository
import org.videolan.vlc.repository.DirectoryRepository
+import org.videolan.vlc.util.Permissions
import org.videolan.vlc.util.convertFavorites
import org.videolan.vlc.util.isSchemeFile
import org.videolan.vlc.util.scanAllowed
@@ -145,6 +146,11 @@ class MainTvModel(app: Application) : AndroidViewModel(app), Medialibrary.OnMedi
}
private fun updateVideos() = viewModelScope.launch {
+ if (!Permissions.canReadStorage(context)) {
+ (videos as MutableLiveData).value =
+ listOf(DummyItem(HEADER_PERMISSION, context.getString(R.string.permission_media), context.getString(R.string.permission_ask_again)))
+ return at launch
+ }
val allMovies = withContext(Dispatchers.IO) { mediaMetadataRepository.getMovieCount() }
val allTvshows = withContext(Dispatchers.IO) { mediaMetadataRepository.getTvshowsCount() }
val videoNb = context.getFromMl { videoCount }
@@ -204,11 +210,18 @@ class MainTvModel(app: Application) : AndroidViewModel(app), Medialibrary.OnMedi
}
private fun updateAudioCategories() {
- val list = mutableListOf<MediaLibraryItem>(
- DummyItem(CATEGORY_ARTISTS, context.getString(R.string.artists), ""),
- DummyItem(CATEGORY_ALBUMS, context.getString(R.string.albums), ""),
- DummyItem(CATEGORY_GENRES, context.getString(R.string.genres), ""),
- DummyItem(CATEGORY_SONGS, context.getString(R.string.tracks), "")
+ val list = if (!Permissions.canReadStorage(context)) mutableListOf<MediaLibraryItem>(
+ DummyItem(
+ HEADER_PERMISSION,
+ context.getString(R.string.permission_media),
+ context.getString(R.string.permission_ask_again)
+ )
+ )
+ else mutableListOf<MediaLibraryItem>(
+ DummyItem(CATEGORY_ARTISTS, context.getString(R.string.artists), ""),
+ DummyItem(CATEGORY_ALBUMS, context.getString(R.string.albums), ""),
+ DummyItem(CATEGORY_GENRES, context.getString(R.string.genres), ""),
+ DummyItem(CATEGORY_SONGS, context.getString(R.string.tracks), "")
)
(audioCategories as MutableLiveData).value = list
}
@@ -277,6 +290,7 @@ class MainTvModel(app: Application) : AndroidViewModel(app), Medialibrary.OnMedi
}
}
is DummyItem -> when {
+ item.id == HEADER_PERMISSION -> Permissions.checkReadStoragePermission(activity)
item.id == HEADER_STREAM -> {
val intent = Intent(activity, TVActivity::class.java)
intent.putExtra(MainTvActivity.BROWSER_TYPE, HEADER_STREAM)
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.kt b/application/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.kt
index ac1d2f9a1..a7db40768 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.kt
@@ -742,6 +742,7 @@ fun getTvIconRes(mediaLibraryItem: MediaLibraryItem) = when (mediaLibraryItem.it
MediaLibraryItem.TYPE_DUMMY -> {
when (mediaLibraryItem.id) {
HEADER_VIDEO -> R.drawable.ic_video_collection_big
+ HEADER_PERMISSION -> R.drawable.ic_permission_big
HEADER_DIRECTORIES -> R.drawable.ic_menu_folder_big
HEADER_NETWORK -> R.drawable.ic_menu_network_big
HEADER_SERVER -> R.drawable.ic_menu_network_add_big
More information about the Android
mailing list