[Android] Add a PIN lock item to the TV main screen

Nicolas Pomepuy git at videolan.org
Wed Jul 12 08:30:36 UTC 2023


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Tue Jul  4 13:02:35 2023 +0200| [b12917ec1c522fd48702fc5caef7bc62ca161a4e] | committer: Duncan McNamara

Add a PIN lock item to the TV main screen

Fixes #2966

> https://code.videolan.org/videolan/vlc-android/commit/b12917ec1c522fd48702fc5caef7bc62ca161a4e
---

 .../main/java/org/videolan/resources/Constants.kt  |  1 +
 .../src/main/res/drawable/ic_menu_pin_lock_big.xml | 33 ++++++++++++++++++++++
 .../resources/src/main/res/values/strings.xml      |  1 +
 .../org/videolan/television/ui/MainTvFragment.kt   | 20 +++++++++++--
 4 files changed, 53 insertions(+), 2 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 e7739d6631..d70a0a496e 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 ID_REFRESH = 13L
 const val ID_ALL_MOVIES = 14L
 const val ID_ALL_TVSHOWS = 15L
 const val ID_SPONSOR = 16L
+const val ID_PIN_LOCK = 17L
 const val CATEGORY_NOW_PLAYING = 20L
 const val CATEGORY_ARTISTS = 21L
 const val CATEGORY_ALBUMS = 22L
diff --git a/application/resources/src/main/res/drawable/ic_menu_pin_lock_big.xml b/application/resources/src/main/res/drawable/ic_menu_pin_lock_big.xml
new file mode 100644
index 0000000000..e9c6d66064
--- /dev/null
+++ b/application/resources/src/main/res/drawable/ic_menu_pin_lock_big.xml
@@ -0,0 +1,33 @@
+<!--
+  ~ *************************************************************************
+  ~  pin_lock.xml
+  ~ **************************************************************************
+  ~ Copyright © 2023 VLC authors and VideoLAN
+  ~ Author: Nicolas POMEPUY
+  ~ This program is free software; you can redistribute it and/or modify
+  ~ it under the terms of the GNU General Public License as published by
+  ~ the Free Software Foundation; either version 2 of the License, or
+  ~ (at your option) any later version.
+  ~
+  ~ This program is distributed in the hope that it will be useful,
+  ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
+  ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  ~ GNU General Public License for more details.
+  ~
+  ~ You should have received a copy of the GNU General Public License
+  ~ along with this program; if not, write to the Free Software
+  ~ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+  ~ ***************************************************************************
+  ~
+  ~
+  -->
+
+<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="@color/white"
+            android:pathData="M12,2L4,5v6.09c0,5.05 3.41,9.76 8,10.91c4.59,-1.15 8,-5.86 8,-10.91V5L12,2zM18,11.09c0,4 -2.55,7.7 -6,8.83c-3.45,-1.13 -6,-4.82 -6,-8.83V6.31l6,-2.12l6,2.12V11.09zM8.82,10.59L7.4,12l3.54,3.54l5.66,-5.66l-1.41,-1.41l-4.24,4.24L8.82,10.59z" />
+</vector>
diff --git a/application/resources/src/main/res/values/strings.xml b/application/resources/src/main/res/values/strings.xml
index 0d3d363e6d..2e26980647 100644
--- a/application/resources/src/main/res/values/strings.xml
+++ b/application/resources/src/main/res/values/strings.xml
@@ -978,6 +978,7 @@
     <string name="restricted_access">Access restricted</string>
     <string name="unlock">Unlock</string>
     <string name="lock_with_pin">Re-enable PIN lock</string>
+    <string name="lock_with_pin_short">PIN lock</string>
     <string name="restrict_settings">Restrict settings access</string>
     <string name="search_prefs">Search settings</string>
     <string name="video_match_frame_rate_title">Match Display Frame Rate</string>
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 d7496eddb0..662e3da5fc 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
@@ -22,6 +22,8 @@
 
 package org.videolan.television.ui
 
+//import org.videolan.vlc.donations.BillingStatus
+//import org.videolan.vlc.donations.VLCBilling
 import android.content.Intent
 import android.os.Bundle
 import android.view.View
@@ -45,9 +47,8 @@ import org.videolan.television.viewmodel.MainTvModel.Companion.getMainTvModel
 import org.videolan.vlc.BuildConfig
 import org.videolan.vlc.R
 import org.videolan.vlc.RecommendationsService
-//import org.videolan.vlc.donations.BillingStatus
-//import org.videolan.vlc.donations.VLCBilling
 import org.videolan.vlc.gui.helpers.UiTools.showDonations
+import org.videolan.vlc.gui.helpers.hf.PinCodeDelegate
 import org.videolan.vlc.gui.video.VideoPlayerActivity
 import org.videolan.vlc.reloadLibrary
 import org.videolan.vlc.util.Permissions
@@ -156,6 +157,8 @@ class MainTvFragment : BrowseSupportFragment(), OnItemViewSelectedListener, OnIt
         otherAdapter = ArrayObjectAdapter(GenericCardPresenter(ctx))
         val miscHeader = HeaderItem(HEADER_MISC, getString(R.string.other))
 
+        val lockItem = GenericCardItem(ID_PIN_LOCK, getString(R.string.lock_with_pin_short), "", R.drawable.ic_menu_pin_lock_big, R.color.tv_card_content_dark)
+        if (PinCodeDelegate.pinUnlocked.value == true) otherAdapter.add(lockItem)
         otherAdapter.add(GenericCardItem(ID_SETTINGS, getString(R.string.preferences), "", R.drawable.ic_menu_preferences_big, R.color.tv_card_content_dark))
         if (Permissions.canReadStorage(requireActivity())) otherAdapter.add(GenericCardItem(ID_REFRESH, getString(R.string.refresh), "", R.drawable.ic_menu_tv_scan, R.color.tv_card_content_dark))
         otherAdapter.add(GenericCardItem(ID_ABOUT_TV, getString(R.string.about), "${getString(R.string.app_name_full)} ${BuildConfig.VLC_VERSION_NAME}", R.drawable.ic_menu_info_big, R.color.tv_card_content_dark))
@@ -163,6 +166,18 @@ class MainTvFragment : BrowseSupportFragment(), OnItemViewSelectedListener, OnIt
 //        VLCBilling.getInstance(requireActivity().application).addStatusListener {
 //            manageDonationVisibility(donateCard)
 //        }
+
+        PinCodeDelegate.pinUnlocked.observe(requireActivity()) {
+            if (it) {
+                if ((otherAdapter.get(0) as GenericCardItem).id != ID_PIN_LOCK) {
+                    otherAdapter.add(0, lockItem)
+                }
+            } else {
+                if ((otherAdapter.get(0) as GenericCardItem).id == ID_PIN_LOCK) {
+                    otherAdapter.removeItems(0, 1)
+                }
+            }
+        }
         manageDonationVisibility(donateCard)
         miscRow = ListRow(miscHeader, otherAdapter)
         rowsAdapter.add(miscRow)
@@ -311,6 +326,7 @@ class MainTvFragment : BrowseSupportFragment(), OnItemViewSelectedListener, OnIt
                     }
                     ID_ABOUT_TV -> activity.startActivity(Intent(activity, AboutActivity::class.java))
                     ID_SPONSOR -> activity.showDonations()
+                    ID_PIN_LOCK -> PinCodeDelegate.pinUnlocked.postValue(false)
                 }
             }
             HEADER_NOW_PLAYING -> {



More information about the Android mailing list