[Android] Improve the changed settings formatting and add the display actions
Nicolas Pomepuy
git at videolan.org
Tue Apr 8 11:46:30 UTC 2025
vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Tue Apr 8 12:14:41 2025 +0200| [a038e7003110d00d8dbd44a7e94dbd4a8b4ced98] | committer: Nicolas Pomepuy
Improve the changed settings formatting and add the display actions
> https://code.videolan.org/videolan/vlc-android/commit/a038e7003110d00d8dbd44a7e94dbd4a8b4ced98
---
.../vlc/gui/preferences/search/PreferenceParser.kt | 82 +++++++++++++++++++++-
1 file changed, 79 insertions(+), 3 deletions(-)
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/preferences/search/PreferenceParser.kt b/application/vlc-android/src/org/videolan/vlc/gui/preferences/search/PreferenceParser.kt
index 90157698ed..7af30194a1 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/preferences/search/PreferenceParser.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/preferences/search/PreferenceParser.kt
@@ -44,6 +44,8 @@ import org.videolan.tools.Settings
import org.videolan.tools.putSingle
import org.videolan.tools.wrap
import org.videolan.vlc.R
+import org.videolan.vlc.gui.helpers.DefaultPlaybackAction
+import org.videolan.vlc.gui.helpers.DefaultPlaybackActionMediaType
import org.videolan.vlc.util.FileUtils
import java.io.BufferedWriter
import java.io.File
@@ -76,14 +78,59 @@ object PreferenceParser {
return result
}
+ /**
+ * Parses all the preferences available in the app.
+ * @param context the context to be used to retrieve the preferences
+ * @param forVideo if true, parses the video controls else the audio controls
+ *
+ * @return a list of [PreferenceItem]
+ */
+ fun parseControlPreferences(context: Context, forVideo: Boolean): ArrayList<PreferenceItem> {
+ val result = ArrayList<PreferenceItem>()
+ arrayListOf<Int>()
+ .apply {
+ if (forVideo)
+ this.add(R.xml.preferences_video_controls)
+ else
+ this.add(R.xml.preferences_audio_controls)
+ }
+ .forEach {
+ result.addAll(parsePreferences(context, it))
+ }
+ return result
+ }
+
/**
* Compares the preference list with the set settings to get the list of the changed settings by the user
* @param context the context to be used to retrieve the preferences
*
* @return a list of changed settings in the form a of pair of the key and the value
*/
- private fun getAllChangedPrefs(context: Context): ArrayList<Pair<String, Any>> {
- val allPrefs = parsePreferences(context, parseUIPrefs = true)
+ private fun getAllChangedPrefs(context: Context, parseUIPrefs: Boolean = true): ArrayList<Pair<String, Any>> {
+ val allPrefs = parsePreferences(context, parseUIPrefs = parseUIPrefs)
+ val allSettings = Settings.getInstance(context).all
+ val changedSettings = ArrayList<Pair<String, Any>>()
+ allPrefs.forEach { pref ->
+ allSettings.forEach { setting ->
+ if (pref.key == setting.key && pref.key != "custom_libvlc_options") {
+ setting.value?.let {
+ if (!isSame(it, pref.defaultValue)) changedSettings.add(Pair(pref.key, it))
+ }
+ }
+ }
+ }
+ return changedSettings
+ }
+
+ /**
+ * Get all changed control prefs
+ *
+ * @param context the context to be used to retrieve the preferences
+ * @param forVideo if true, returns the video controls else the audio controls
+ * @return a list of changed settings in the form a of pair of the key and the value
+ */
+ private fun getAllChangedControlPrefs(context: Context, forVideo: Boolean = false): ArrayList<Pair<String, Any>> {
+ val allPrefs = parseControlPreferences(context, forVideo = forVideo)
val allSettings = Settings.getInstance(context).all
val changedSettings = ArrayList<Pair<String, Any>>()
allPrefs.forEach { pref ->
@@ -118,7 +165,36 @@ object PreferenceParser {
* @return a string of all the changed preferences
*/
fun getChangedPrefsString(context: Context) = buildString {
- getAllChangedPrefs(context).forEach { append("\t* ${it.first} -> ${it.second}\r\n") }
+ append("\r\nMain settings:\r\n")
+ getAllChangedPrefs(context, parseUIPrefs = false).forEach { append("\t* ${it.first} -> ${it.second}\r\n") }
+ val videoControls = buildString {
+ getAllChangedControlPrefs(context, forVideo = true).forEach { append("\t* ${it.first} -> ${it.second}\r\n") }
+ }
+ if (videoControls.isNotBlank()) {
+ append("\r\nVideo controls:\r\n")
+ append(videoControls)
+ }
+ val audioControls = buildString {
+ getAllChangedControlPrefs(context, forVideo = false).forEach { append("\t* ${it.first} -> ${it.second}\r\n") }
+ }
+ if (audioControls.isNotBlank()) {
+ append("\r\nAudio controls:\r\n")
+ append(audioControls)
+ }
+ //default actions
+ val settings = Settings.getInstance(context)
+ val defaultActions = buildString {
+ DefaultPlaybackActionMediaType.entries.forEach {
+ val currentPlaybackAction = it.getCurrentPlaybackAction(settings)
+ if (currentPlaybackAction != DefaultPlaybackAction.PLAY) {
+ append("\t* ${it.defaultActionKey} -> $currentPlaybackAction\r\n")
+ }
+ }
+ }
+ if (defaultActions.isNotBlank()) {
+ append("\r\nDefault actions:\r\n")
+ append(defaultActions)
+ }
}
/**
More information about the Android
mailing list