[Android] Add a clear data setting
Nicolas Pomepuy
git at videolan.org
Thu Jun 10 11:24:07 UTC 2021
vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Tue Jun 1 08:35:52 2021 +0200| [9eb0961c07684cd49ee98436d1c268be830cdf25] | committer: Nicolas Pomepuy
Add a clear data setting
> https://code.videolan.org/videolan/vlc-android/commit/9eb0961c07684cd49ee98436d1c268be830cdf25
---
.../resources/src/main/res/values/strings.xml | 3 +++
.../ui/preferences/PreferencesAdvanced.kt | 15 ++++++++++-
.../vlc-android/res/xml/preferences_adv.xml | 6 +++++
.../vlc/gui/preferences/PreferencesAdvanced.kt | 29 +++++++++++++++-------
4 files changed, 43 insertions(+), 10 deletions(-)
diff --git a/application/resources/src/main/res/values/strings.xml b/application/resources/src/main/res/values/strings.xml
index 8d3222c5a..db6475cda 100644
--- a/application/resources/src/main/res/values/strings.xml
+++ b/application/resources/src/main/res/values/strings.xml
@@ -398,6 +398,8 @@
<string name="dump_media_db_summary">Copy database to internal storage root</string>
<string name="clear_media_db">Clear media database</string>
<string name="clear_media_database_summary">Clears the database to start over</string>
+ <string name="clear_app_data">Clear app data</string>
+ <string name="clear_app_data_summary">Clears VLC for Android data</string>
<string name="clear_history">Clear history</string>
<string name="set_locale">Set locale</string>
<string name="network_caching">Network caching value</string>
@@ -702,6 +704,7 @@
<string name="recently_added">Recently added</string>
<string name="playback_multiple_errors">Multiple media cannot be played</string>
<string name="clear_media_db_message">You will lose your progresses, bookmarks and the playlists you created but you will keep your VLC for Android settings</string>
+ <string name="clear_app_data_message">You will lose your progresses, bookmarks, playlists and all VLC settings</string>
<string name="clear">Clear</string>
<string name="abrepeat_add_first_marker">Set start point</string>
<string name="abrepeat_add_second_marker">Set end point</string>
diff --git a/application/television/src/main/java/org/videolan/television/ui/preferences/PreferencesAdvanced.kt b/application/television/src/main/java/org/videolan/television/ui/preferences/PreferencesAdvanced.kt
index 3306a62ae..ef153a537 100644
--- a/application/television/src/main/java/org/videolan/television/ui/preferences/PreferencesAdvanced.kt
+++ b/application/television/src/main/java/org/videolan/television/ui/preferences/PreferencesAdvanced.kt
@@ -24,6 +24,7 @@
package org.videolan.television.ui.preferences
import android.annotation.TargetApi
+import android.app.ActivityManager
import android.app.AlertDialog
import android.content.Context
import android.content.Intent
@@ -34,7 +35,6 @@ import android.os.Bundle
import android.widget.Toast
import androidx.core.content.edit
import androidx.fragment.app.FragmentActivity
-import androidx.lifecycle.lifecycleScope
import androidx.preference.EditTextPreference
import androidx.preference.Preference
import kotlinx.coroutines.*
@@ -104,6 +104,19 @@ class PreferencesAdvanced : BasePreferenceFragment(), SharedPreferences.OnShared
.show()
return true
}
+ "clear_app_data" -> {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+ val dialog = ConfirmDeleteDialog.newInstance(title = getString(R.string.clear_app_data), description = getString(R.string.clear_app_data_message), buttonText = getString(R.string.clear))
+ dialog.show((activity as FragmentActivity).supportFragmentManager, RenameDialog::class.simpleName)
+ dialog.setListener { (activity.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager).clearApplicationUserData() }
+ } else {
+ val i = Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
+ i.addCategory(Intent.CATEGORY_DEFAULT)
+ i.data = Uri.parse("package:" + activity.applicationContext.packageName)
+ startActivity(i)
+ }
+ return true
+ }
"clear_media_db" -> {
val dialog = ConfirmDeleteDialog.newInstance(title = getString(R.string.clear_media_db), description = getString(R.string.clear_media_db_message), buttonText = getString(R.string.clear))
dialog.show((activity as FragmentActivity).supportFragmentManager, RenameDialog::class.simpleName)
diff --git a/application/vlc-android/res/xml/preferences_adv.xml b/application/vlc-android/res/xml/preferences_adv.xml
index 835b01541..646a57118 100644
--- a/application/vlc-android/res/xml/preferences_adv.xml
+++ b/application/vlc-android/res/xml/preferences_adv.xml
@@ -37,6 +37,12 @@
android:summary="@string/clear_media_database_summary"
android:title="@string/clear_media_db"/>
+ <Preference
+ android:enabled="true"
+ android:key="clear_app_data"
+ android:summary="@string/clear_app_data_summary"
+ android:title="@string/clear_app_data"/>
+
<PreferenceScreen
android:key="clear_history"
android:title="@string/clear_playback_history"/>
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesAdvanced.kt b/application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesAdvanced.kt
index 492961a08..df1e7ddb6 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesAdvanced.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesAdvanced.kt
@@ -23,12 +23,13 @@
package org.videolan.vlc.gui.preferences
-import android.app.AlarmManager
-import android.app.PendingIntent
+import android.app.ActivityManager
import android.content.Context
+import android.content.Context.ACTIVITY_SERVICE
import android.content.Intent
import android.content.SharedPreferences
import android.net.Uri
+import android.os.Build
import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
@@ -38,24 +39,21 @@ import androidx.preference.EditTextPreference
import androidx.preference.Preference
import kotlinx.coroutines.*
import org.videolan.medialibrary.interfaces.Medialibrary
-import org.videolan.resources.*
-import org.videolan.tools.RESULT_RESTART
+import org.videolan.resources.AndroidDevices
+import org.videolan.resources.KEY_AUDIO_LAST_PLAYLIST
+import org.videolan.resources.KEY_MEDIA_LAST_PLAYLIST
+import org.videolan.resources.VLCInstance
import org.videolan.tools.Settings
-import org.videolan.tools.isStarted
import org.videolan.tools.putSingle
import org.videolan.vlc.BuildConfig
import org.videolan.vlc.MediaParsingService
import org.videolan.vlc.R
-import org.videolan.vlc.StartActivity
import org.videolan.vlc.gui.DebugLogActivity
-import org.videolan.vlc.gui.MainActivity
-import org.videolan.vlc.gui.SecondaryActivity
import org.videolan.vlc.gui.dialogs.ConfirmDeleteDialog
import org.videolan.vlc.gui.dialogs.RenameDialog
import org.videolan.vlc.gui.helpers.UiTools
import org.videolan.vlc.gui.helpers.hf.StoragePermissionsDelegate.Companion.getWritePermission
import org.videolan.vlc.util.FeatureFlag
-import org.videolan.vlc.gui.onboarding.ONBOARDING_DONE_KEY
import org.videolan.vlc.util.FileUtils
import java.io.File
@@ -125,6 +123,19 @@ class PreferencesAdvanced : BasePreferenceFragment(), SharedPreferences.OnShared
}
return true
}
+ "clear_app_data" -> {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+ val dialog = ConfirmDeleteDialog.newInstance(title = getString(R.string.clear_app_data), description = getString(R.string.clear_app_data_message), buttonText = getString(R.string.clear))
+ dialog.show(requireActivity().supportFragmentManager, RenameDialog::class.simpleName)
+ dialog.setListener { (requireActivity().getSystemService(ACTIVITY_SERVICE) as ActivityManager).clearApplicationUserData() }
+ } else {
+ val i = Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
+ i.addCategory(Intent.CATEGORY_DEFAULT)
+ i.data = Uri.parse("package:" + requireActivity().applicationContext.packageName)
+ startActivity(i)
+ }
+ return true
+ }
"quit_app" -> {
android.os.Process.killProcess(android.os.Process.myPid())
return true
More information about the Android
mailing list