[Android] Add the parental control settings on TV
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 09:20:40 2023 +0200| [bbb6264de922eab003eebd432ef122c1e6a8e77b] | committer: Duncan McNamara
Add the parental control settings on TV
> https://code.videolan.org/videolan/vlc-android/commit/bbb6264de922eab003eebd432ef122c1e6a8e77b
---
.../ui/preferences/PreferencesFragment.kt | 25 ++++++
.../ui/preferences/PreferencesParentalControl.kt | 94 ++++++++++++++++++++++
2 files changed, 119 insertions(+)
diff --git a/application/television/src/main/java/org/videolan/television/ui/preferences/PreferencesFragment.kt b/application/television/src/main/java/org/videolan/television/ui/preferences/PreferencesFragment.kt
index 4415f33234..9dbe37d0fa 100644
--- a/application/television/src/main/java/org/videolan/television/ui/preferences/PreferencesFragment.kt
+++ b/application/television/src/main/java/org/videolan/television/ui/preferences/PreferencesFragment.kt
@@ -24,6 +24,7 @@
package org.videolan.television.ui.preferences
import android.annotation.TargetApi
+import android.app.Activity
import android.content.Intent
import android.content.SharedPreferences
import android.os.Build
@@ -32,10 +33,14 @@ import android.widget.Toast
import androidx.fragment.app.FragmentActivity
import androidx.preference.CheckBoxPreference
import androidx.preference.Preference
+import androidx.preference.PreferenceScreen
import org.videolan.medialibrary.interfaces.Medialibrary
import org.videolan.resources.*
import org.videolan.tools.*
+import org.videolan.tools.Settings.isPinCodeSet
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
@@ -58,6 +63,19 @@ class PreferencesFragment : BasePreferenceFragment(), SharedPreferences.OnShared
preferenceScreen.sharedPreferences.registerOnSharedPreferenceChangeListener(this)
}
+ @Deprecated("Deprecated in Java")
+ override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
+ super.onActivityResult(requestCode, resultCode, data)
+ if (resultCode == Activity.RESULT_OK) {
+ when (requestCode) {
+ 0 -> {
+ val preferenceScreen: PreferenceScreen? = findPreference("parental_control") as PreferenceScreen?
+ onPreferenceTreeClick(preferenceScreen!!)
+ }
+ }
+ }
+ }
+
override fun onPreferenceTreeClick(preference: Preference): Boolean {
val context = activity ?: return false
return when (preference.key) {
@@ -76,6 +94,13 @@ class PreferencesFragment : BasePreferenceFragment(), SharedPreferences.OnShared
}
true
}
+ "parental_control" -> {
+ if (!activity.isPinCodeSet()) {
+ val intent = PinCodeActivity.getIntent(activity, PinCodeReason.FIRST_CREATION)
+ startActivityForResult(intent, 0)
+ true
+ } else super.onPreferenceTreeClick(preference)
+ }
AUDIO_RESUME_PLAYBACK -> {
val audioResumePref = findPreference<CheckBoxPreference>(AUDIO_RESUME_PLAYBACK)
diff --git a/application/television/src/main/java/org/videolan/television/ui/preferences/PreferencesParentalControl.kt b/application/television/src/main/java/org/videolan/television/ui/preferences/PreferencesParentalControl.kt
new file mode 100644
index 0000000000..f9f0e1beef
--- /dev/null
+++ b/application/television/src/main/java/org/videolan/television/ui/preferences/PreferencesParentalControl.kt
@@ -0,0 +1,94 @@
+/*
+ * *************************************************************************
+ * PreferencesParentalControl.java
+ * **************************************************************************
+ * Copyright © 2023 VLC authors and VideoLAN
+ *
+ * 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.
+ * ***************************************************************************
+ */
+
+package org.videolan.television.ui.preferences
+
+import android.app.Activity
+import android.content.Intent
+import android.content.SharedPreferences
+import android.os.Bundle
+import android.widget.Toast
+import androidx.preference.Preference
+import org.videolan.tools.KEY_SAFE_MODE
+import org.videolan.tools.Settings
+import org.videolan.tools.Settings.isPinCodeSet
+import org.videolan.vlc.R
+import org.videolan.vlc.gui.PinCodeActivity
+import org.videolan.vlc.gui.PinCodeReason
+
+class PreferencesParentalControl : BasePreferenceFragment(), SharedPreferences.OnSharedPreferenceChangeListener {
+
+
+ override fun getXml() = R.xml.preferences_parental_control
+
+ override fun getTitleId() = R.string.parental_control
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ if (!activity.isPinCodeSet()) {
+ val intent = PinCodeActivity.getIntent(activity, PinCodeReason.FIRST_CREATION)
+ startActivityForResult(intent, 1)
+ }
+ }
+
+ override fun onStart() {
+ super.onStart()
+ preferenceScreen.sharedPreferences.registerOnSharedPreferenceChangeListener(this)
+ }
+
+ override fun onStop() {
+ super.onStop()
+ preferenceScreen.sharedPreferences
+ .unregisterOnSharedPreferenceChangeListener(this)
+ }
+
+ override fun onPreferenceTreeClick(preference: Preference): Boolean {
+ if (preference.key == null) return false
+ when (preference.key) {
+ "modify_pin_code" -> {
+ val intent = PinCodeActivity.getIntent(activity, PinCodeReason.MODIFY)
+ startActivityForResult(intent, 0)
+ }
+ }
+ return super.onPreferenceTreeClick(preference)
+ }
+
+ @Deprecated("Deprecated in Java")
+ override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
+ super.onActivityResult(requestCode, resultCode, data)
+ if (resultCode == Activity.RESULT_OK) {
+ when (requestCode) {
+ 0 -> {
+ Toast.makeText(activity, R.string.pin_code_modified, Toast.LENGTH_LONG).show()
+ }
+ }
+ }
+ }
+
+ override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) {
+ when (key) {
+ KEY_SAFE_MODE -> {
+ Settings.safeMode = sharedPreferences.getBoolean(key, false) && activity.isPinCodeSet()
+ }
+ }
+ }
+}
More information about the Android
mailing list