[Android] Add a parental control setting
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 Jun 26 10:06:08 2023 +0200| [1eb70a36feb8680cf357686c691b5155fefeff85] | committer: Duncan McNamara
Add a parental control setting
> https://code.videolan.org/videolan/vlc-android/commit/1eb70a36feb8680cf357686c691b5155fefeff85
---
.../resources/src/main/res/values/strings.xml | 4 ++
.../res/xml/preferences_parental_control.xml | 34 ++++++++++++++
application/vlc-android/res/xml/preferences_ui.xml | 6 +--
.../src/org/videolan/vlc/gui/PinCodeActivity.kt | 4 ++
.../gui/preferences/PreferencesParentalControl.kt | 52 ++++++++++++++++++++++
.../videolan/vlc/gui/preferences/PreferencesUi.kt | 21 +++++++--
6 files changed, 115 insertions(+), 6 deletions(-)
diff --git a/application/resources/src/main/res/values/strings.xml b/application/resources/src/main/res/values/strings.xml
index e6de56eeb3..de4ecfaaec 100644
--- a/application/resources/src/main/res/values/strings.xml
+++ b/application/resources/src/main/res/values/strings.xml
@@ -961,6 +961,10 @@
<string name="missing_media_snack">Media is missing. Hide all missing media?</string>
<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="audio_limit">Limit audio volume</string>
+ <string name="audio_limit_summary">Prevent audio boost and limit volume to 50%</string>
<string name="safe_mode">Safe mode</string>
<string name="safe_mode_summary">When activated, files cannot be deleted, playlist modified or settings accessed without entering the pin</string>
<string name="safe_mode_pin">Enter your PIN</string>
diff --git a/application/vlc-android/res/xml/preferences_parental_control.xml b/application/vlc-android/res/xml/preferences_parental_control.xml
new file mode 100644
index 0000000000..2ca127ce9c
--- /dev/null
+++ b/application/vlc-android/res/xml/preferences_parental_control.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ android:key="video_category"
+ android:title="@string/video_prefs_category">
+
+ <CheckBoxPreference
+ android:defaultValue="false"
+ android:key="parental_control_enabled"
+ android:summary="@string/parental_control_summary"
+ android:title="@string/parental_control"
+ app:iconSpaceReserved="false"
+ app:singleLineTitle="false" />
+
+ <CheckBoxPreference
+ android:defaultValue="false"
+ android:dependency="parental_control_enabled"
+ android:key="safe_mode"
+ android:summary="@string/safe_mode_summary"
+ android:title="@string/safe_mode"
+ app:iconSpaceReserved="false"
+ app:singleLineTitle="false" />
+ <CheckBoxPreference
+ android:defaultValue="false"
+ android:dependency="parental_control_enabled"
+ android:key="audio_limit"
+ android:summary="@string/audio_limit_summary"
+ android:title="@string/audio_limit"
+ app:iconSpaceReserved="false"
+ app:singleLineTitle="false" />
+
+
+</androidx.preference.PreferenceScreen>
diff --git a/application/vlc-android/res/xml/preferences_ui.xml b/application/vlc-android/res/xml/preferences_ui.xml
index 97f4d98208..bc8f4cfe2c 100644
--- a/application/vlc-android/res/xml/preferences_ui.xml
+++ b/application/vlc-android/res/xml/preferences_ui.xml
@@ -66,10 +66,10 @@
<PreferenceScreen
- android:key="safe_mode"
+ android:key="parental_control"
android:singleLine="false"
- android:summary="@string/safe_mode_summary"
- android:title="@string/safe_mode"/>
+ android:summary="@string/parental_control_summary"
+ android:title="@string/parental_control"/>
<PreferenceCategory
android:title="@string/video"
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/PinCodeActivity.kt b/application/vlc-android/src/org/videolan/vlc/gui/PinCodeActivity.kt
index 9da8df7099..1ec93ad3b1 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/PinCodeActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/PinCodeActivity.kt
@@ -25,6 +25,7 @@
package org.videolan.vlc.gui
import android.app.Application
+import android.content.Context
import android.os.Bundle
import android.view.MenuItem
import android.view.inputmethod.EditorInfo
@@ -110,6 +111,7 @@ class PinCodeActivity : BaseActivity() {
if (model.step.value == PinStep.RE_ENTER || model.step.value == PinStep.NO_MATCH) {
if (model.checkMatch(binding.pinCode.text.toString())) {
model.savePin(binding.pinCode.text.toString())
+ setResult(RESULT_OK)
finish()
} else {
binding.pinCode.text?.clear()
@@ -216,3 +218,5 @@ enum class PinStep {
ENTER_EXISTING, INVALID, ENTER_NEW, RE_ENTER, NO_MATCH;
}
+
+fun Context.isPinCodeSet() = Settings.getInstance(this).getString(KEY_SAFE_MODE_PIN, "")?.isNotBlank() == true
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesParentalControl.kt b/application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesParentalControl.kt
new file mode 100644
index 0000000000..8e11fffbaa
--- /dev/null
+++ b/application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesParentalControl.kt
@@ -0,0 +1,52 @@
+/*
+ * *************************************************************************
+ * 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.vlc.gui.preferences
+
+import android.content.SharedPreferences
+import android.os.Bundle
+import org.videolan.tools.KEY_VIDEO_JUMP_DELAY
+import org.videolan.tools.Settings
+import org.videolan.vlc.R
+import org.videolan.vlc.gui.video.VideoPlayerActivity
+
+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)
+
+ }
+
+
+ override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) {
+ (activity as? VideoPlayerActivity)?.onChangedControlSetting(key)
+ when (key) {
+ KEY_VIDEO_JUMP_DELAY -> {
+ Settings.videoJumpDelay = sharedPreferences.getInt(KEY_VIDEO_JUMP_DELAY, 10)
+ }
+ }
+ }
+}
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 108bef2246..8108b0e38b 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,10 +23,11 @@
package org.videolan.vlc.gui.preferences
-import android.content.Intent
+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
@@ -51,9 +52,17 @@ import org.videolan.vlc.BuildConfig
import org.videolan.vlc.R
import org.videolan.vlc.gui.PinCodeActivity
import org.videolan.vlc.gui.helpers.UiTools
+import org.videolan.vlc.gui.isPinCodeSet
+
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
@@ -126,8 +135,14 @@ class PreferencesUi : BasePreferenceFragment(), SharedPreferences.OnSharedPrefer
return true
}
"media_seen" -> requireActivity().setResult(RESULT_UPDATE_SEEN_MEDIA)
- "safe_mode" -> {
- startActivity(Intent(requireActivity(), PinCodeActivity::class.java))
+ "parental_control" -> {
+ if (requireActivity().isPinCodeSet())
+ loadFragment(PreferencesParentalControl())
+ else {
+ val intent = Intent(requireActivity(), PinCodeActivity::class.java)
+ someActivityResultLauncher.launch(intent)
+ }
+// startActivity(Intent(requireActivity(), PinCodeActivity::class.java))
}
KEY_ARTISTS_SHOW_ALL -> (activity as PreferencesActivity).updateArtists()
}
More information about the Android
mailing list