[Android] Add an unlock safe mode option item

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


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Thu Jul  6 08:33:08 2023 +0200| [164aabf700da009eead73f69f319f4fbba7bf5bb] | committer: Duncan McNamara

Add an unlock safe mode option item

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

 .../src/main/res/drawable/ic_am_pin_unlock.xml     | 33 ++++++++++++++++++++++
 .../resources/src/main/res/values/strings.xml      |  1 +
 .../vlc-android/res/menu/activity_option.xml       |  9 ++++++
 .../src/org/videolan/vlc/gui/BaseActivity.kt       | 15 ++++++++--
 4 files changed, 55 insertions(+), 3 deletions(-)

diff --git a/application/resources/src/main/res/drawable/ic_am_pin_unlock.xml b/application/resources/src/main/res/drawable/ic_am_pin_unlock.xml
new file mode 100644
index 0000000000..c7d3877246
--- /dev/null
+++ b/application/resources/src/main/res/drawable/ic_am_pin_unlock.xml
@@ -0,0 +1,33 @@
+<!--
+  ~ *************************************************************************
+  ~  ic_am_pin_unlock.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="48dp"
+        android:height="48dp"
+        android:viewportWidth="24"
+        android:viewportHeight="24">
+    <path
+            android:fillColor="?attr/colorControlNormal"
+            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.83v-4.7l6,-2.25l6,2.25V11.09zM9.91,8.5L8.5,9.91L10.59,12L8.5,14.09l1.41,1.41L12,13.42l2.09,2.08l1.41,-1.41L13.42,12l2.08,-2.09L14.09,8.5L12,10.59L9.91,8.5z" />
+</vector>
diff --git a/application/resources/src/main/res/values/strings.xml b/application/resources/src/main/res/values/strings.xml
index 416399a766..0221c57b55 100644
--- a/application/resources/src/main/res/values/strings.xml
+++ b/application/resources/src/main/res/values/strings.xml
@@ -979,6 +979,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="unlock_with_pin">Unlock safe mode</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>
diff --git a/application/vlc-android/res/menu/activity_option.xml b/application/vlc-android/res/menu/activity_option.xml
index 478f4c9ff3..4c990fd772 100644
--- a/application/vlc-android/res/menu/activity_option.xml
+++ b/application/vlc-android/res/menu/activity_option.xml
@@ -166,6 +166,15 @@
             android:title="@string/add_server_favorite"
             vlc:showAsAction="never"
             android:visible="false"/>
+
+    <item
+            android:orderInCategory="4"
+            android:id="@+id/pin_unlock"
+            android:icon="@drawable/ic_am_pin_unlock"
+            android:title="@string/unlock_with_pin"
+            vlc:showAsAction="ifRoom"
+            android:visible="false"/>
+
     <item
             android:orderInCategory="4"
             android:id="@+id/ml_menu_refresh"
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/BaseActivity.kt b/application/vlc-android/src/org/videolan/vlc/gui/BaseActivity.kt
index c5527728ba..01976c42bd 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/BaseActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/BaseActivity.kt
@@ -36,6 +36,7 @@ import org.videolan.vlc.R
 import org.videolan.vlc.gui.helpers.UiTools
 import org.videolan.vlc.gui.helpers.applyTheme
 import org.videolan.vlc.gui.helpers.hf.PinCodeDelegate
+import org.videolan.vlc.gui.helpers.hf.checkPIN
 import org.videolan.vlc.media.MediaUtils
 import org.videolan.vlc.util.FileUtils
 
@@ -90,9 +91,13 @@ abstract class BaseActivity : AppCompatActivity() {
     }
 
     override fun onPrepareOptionsMenu(menu: Menu?): Boolean {
-        val unlockedItem = menu?.findItem(R.id.pin_relocked)
-        if (unlockedItem != null) {
-            unlockedItem.isVisible = PinCodeDelegate.pinUnlocked.value == true
+        val relockItem = menu?.findItem(R.id.pin_relocked)
+        if (relockItem != null) {
+            relockItem.isVisible = PinCodeDelegate.pinUnlocked.value == true
+        }
+        val unlockItem = menu?.findItem(R.id.pin_unlock)
+        if (unlockItem != null) {
+            unlockItem.isVisible = Settings.safeMode && PinCodeDelegate.pinUnlocked.value == false
         }
         return super.onPrepareOptionsMenu(menu)
     }
@@ -103,6 +108,10 @@ abstract class BaseActivity : AppCompatActivity() {
             UiTools.snacker(this, R.string.safe_mode_enabled)
             return true
         }
+        if (item.itemId == R.id.pin_unlock) {
+            lifecycleScope.launch { checkPIN(true) }
+            return true
+        }
         return super.onOptionsItemSelected(item)
     }
 



More information about the Android mailing list