[Android] Move the parental control preference to the root

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


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Mon Jul  3 13:40:17 2023 +0200| [16e86b1c7b338104e5bd6e92bf4ffc142f2d42a0] | committer: Duncan McNamara

Move the parental control preference to the root

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

 .../resources/src/main/res/values/strings.xml      |  1 -
 application/vlc-android/res/xml/preferences.xml    |  6 ++++
 application/vlc-android/res/xml/preferences_ui.xml |  7 -----
 .../vlc/gui/preferences/PreferencesFragment.kt     | 36 ++++++++++++++++++++--
 .../videolan/vlc/gui/preferences/PreferencesUi.kt  | 19 ------------
 5 files changed, 39 insertions(+), 30 deletions(-)

diff --git a/application/resources/src/main/res/values/strings.xml b/application/resources/src/main/res/values/strings.xml
index bc83dccd1d..6232077570 100644
--- a/application/resources/src/main/res/values/strings.xml
+++ b/application/resources/src/main/res/values/strings.xml
@@ -962,7 +962,6 @@
     <string name="browser_show_missing_media">Show missing media</string>
     <string name="browser_show_missing_media_summary">Show distant media even if they are not present</string>
     <string name="parental_control">Parental control</string>
-    <string name="parental_control_summary">Various parental control settings</string>
     <string name="safe_mode">Safe mode</string>
     <string name="safe_mode_summary">When activated, files cannot be deleted or playlist modified without entering the pin</string>
     <string name="safe_mode_pin">Enter your PIN</string>
diff --git a/application/vlc-android/res/xml/preferences.xml b/application/vlc-android/res/xml/preferences.xml
index f2e9f67c67..7940538543 100644
--- a/application/vlc-android/res/xml/preferences.xml
+++ b/application/vlc-android/res/xml/preferences.xml
@@ -86,6 +86,12 @@
         <Preference
                 android:title="@string/casting_category"
                 android:key="casting_category"/>
+
+        <PreferenceScreen
+                android:key="parental_control"
+                android:singleLine="false"
+                android:fragment="org.videolan.television.ui.preferences.PreferencesParentalControl"
+                android:title="@string/parental_control"/>
         <Preference
                 android:title="@string/advanced_prefs_category"
                 android:key="adv_category"
diff --git a/application/vlc-android/res/xml/preferences_ui.xml b/application/vlc-android/res/xml/preferences_ui.xml
index bc8f4cfe2c..611abbd8c2 100644
--- a/application/vlc-android/res/xml/preferences_ui.xml
+++ b/application/vlc-android/res/xml/preferences_ui.xml
@@ -64,13 +64,6 @@
             android:summary="@string/browser_show_missing_media_summary"
             android:title="@string/browser_show_missing_media"/>
 
-
-    <PreferenceScreen
-            android:key="parental_control"
-            android:singleLine="false"
-            android:summary="@string/parental_control_summary"
-            android:title="@string/parental_control"/>
-
     <PreferenceCategory
             android:title="@string/video"
             android:key="ui_video_category">
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesFragment.kt
index c926158023..fc55933e41 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesFragment.kt
@@ -23,10 +23,12 @@
 
 package org.videolan.vlc.gui.preferences
 
+import android.app.Activity
 import android.content.Intent
 import android.content.SharedPreferences
 import android.os.Bundle
 import android.view.View
+import androidx.activity.result.contract.ActivityResultContracts
 import androidx.core.os.bundleOf
 import androidx.fragment.app.FragmentActivity
 import androidx.preference.CheckBoxPreference
@@ -34,11 +36,25 @@ import androidx.preference.ListPreference
 import androidx.preference.Preference
 import org.videolan.libvlc.util.AndroidUtil
 import org.videolan.medialibrary.interfaces.Medialibrary
-import org.videolan.resources.*
+import org.videolan.resources.KEY_AUDIO_LAST_PLAYLIST
+import org.videolan.resources.KEY_CURRENT_AUDIO
+import org.videolan.resources.KEY_CURRENT_AUDIO_RESUME_ARTIST
+import org.videolan.resources.KEY_CURRENT_AUDIO_RESUME_THUMB
+import org.videolan.resources.KEY_CURRENT_AUDIO_RESUME_TITLE
+import org.videolan.resources.KEY_CURRENT_MEDIA
+import org.videolan.resources.KEY_CURRENT_MEDIA_RESUME
+import org.videolan.resources.KEY_MEDIA_LAST_PLAYLIST
+import org.videolan.resources.KEY_MEDIA_LAST_PLAYLIST_RESUME
 import org.videolan.resources.util.parcelable
-import org.videolan.tools.*
-import org.videolan.vlc.BuildConfig
+import org.videolan.tools.AUDIO_RESUME_PLAYBACK
+import org.videolan.tools.PLAYBACK_HISTORY
+import org.videolan.tools.RESULT_RESTART
+import org.videolan.tools.Settings
+import org.videolan.tools.Settings.isPinCodeSet
+import org.videolan.tools.VIDEO_RESUME_PLAYBACK
 import org.videolan.vlc.R
+import org.videolan.vlc.gui.PinCodeActivity
+import org.videolan.vlc.gui.PinCodeReason
 import org.videolan.vlc.gui.SecondaryActivity
 import org.videolan.vlc.gui.dialogs.ConfirmAudioPlayQueueDialog
 import org.videolan.vlc.gui.helpers.UiTools
@@ -47,6 +63,12 @@ import org.videolan.vlc.util.Permissions
 
 class PreferencesFragment : BasePreferenceFragment(), SharedPreferences.OnSharedPreferenceChangeListener {
 
+    var pinCodeResult = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
+        if (result.resultCode == Activity.RESULT_OK) {
+            loadFragment(PreferencesParentalControl())
+        }
+    }
+
     override fun getXml() = R.xml.preferences
 
     override fun getTitleId() = R.string.preferences
@@ -108,6 +130,14 @@ class PreferencesFragment : BasePreferenceFragment(), SharedPreferences.OnShared
             "audio_category" -> loadFragment(PreferencesAudio())
             "adv_category" -> loadFragment(PreferencesAdvanced())
             "casting_category" -> loadFragment(PreferencesCasting())
+            "parental_control" -> {
+                if (requireActivity().isPinCodeSet())
+                    loadFragment(PreferencesParentalControl())
+                else {
+                    val intent = PinCodeActivity.getIntent(requireActivity(), PinCodeReason.FIRST_CREATION)
+                    pinCodeResult.launch(intent)
+                }
+            }
             PLAYBACK_HISTORY -> {
                 val activity = activity
                 activity?.setResult(RESULT_RESTART)
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesUi.kt b/application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesUi.kt
index 796b4e2565..b30dd452b8 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesUi.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesUi.kt
@@ -23,11 +23,9 @@
 
 package org.videolan.vlc.gui.preferences
 
-import android.app.Activity
 import android.content.SharedPreferences
 import android.os.Bundle
 import android.text.InputType
-import androidx.activity.result.contract.ActivityResultContracts
 import androidx.appcompat.app.AppCompatDelegate
 import androidx.preference.EditTextPreference
 import androidx.preference.ListPreference
@@ -47,23 +45,14 @@ import org.videolan.tools.PREF_TV_UI
 import org.videolan.tools.RESULT_UPDATE_SEEN_MEDIA
 import org.videolan.tools.SHOW_VIDEO_THUMBNAILS
 import org.videolan.tools.Settings
-import org.videolan.tools.Settings.isPinCodeSet
 import org.videolan.tools.putSingle
 import org.videolan.vlc.BuildConfig
 import org.videolan.vlc.R
-import org.videolan.vlc.gui.PinCodeActivity
-import org.videolan.vlc.gui.PinCodeReason
 import org.videolan.vlc.gui.helpers.UiTools
 
 
 class PreferencesUi : BasePreferenceFragment(), SharedPreferences.OnSharedPreferenceChangeListener {
 
-    var pinCodeResult = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
-        if (result.resultCode == Activity.RESULT_OK) {
-            loadFragment(PreferencesParentalControl())
-        }
-    }
-
     override fun getXml() = R.xml.preferences_ui
 
     override fun getTitleId() = R.string.interface_prefs_screen
@@ -136,14 +125,6 @@ class PreferencesUi : BasePreferenceFragment(), SharedPreferences.OnSharedPrefer
                 return true
             }
             "media_seen" -> requireActivity().setResult(RESULT_UPDATE_SEEN_MEDIA)
-            "parental_control" -> {
-                if (requireActivity().isPinCodeSet())
-                    loadFragment(PreferencesParentalControl())
-                else {
-                    val intent = PinCodeActivity.getIntent(requireActivity(), PinCodeReason.FIRST_CREATION)
-                    pinCodeResult.launch(intent)
-                }
-            }
             KEY_ARTISTS_SHOW_ALL -> (activity as PreferencesActivity).updateArtists()
         }
         return super.onPreferenceTreeClick(preference)



More information about the Android mailing list