[Android] Settings: clear medialia library

Geoffrey Métais git at videolan.org
Fri Nov 15 15:27:52 CET 2019


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Nov 15 15:26:50 2019 +0100| [698def5a60fc180dcb511b19a8d42811e1c4ce8a] | committer: Geoffrey Métais

Settings: clear medialia library

> https://code.videolan.org/videolan/vlc-android/commit/698def5a60fc180dcb511b19a8d42811e1c4ce8a
---

 .../vlc/gui/preferences/PreferencesAdvanced.kt     | 22 +++++++++++++---------
 .../vlc/gui/tv/preferences/PreferencesAdvanced.kt  | 21 ++++++++++++++-------
 2 files changed, 27 insertions(+), 16 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesAdvanced.kt b/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesAdvanced.kt
index 665d32cfc..a4ee03630 100644
--- a/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesAdvanced.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesAdvanced.kt
@@ -47,10 +47,8 @@ import java.io.File
 @ExperimentalCoroutinesApi
 @ObsoleteCoroutinesApi
 class PreferencesAdvanced : BasePreferenceFragment(), SharedPreferences.OnSharedPreferenceChangeListener, CoroutineScope by MainScope() {
-    override fun getXml(): Int {
-        return R.xml.preferences_adv
-    }
 
+    override fun getXml() =  R.xml.preferences_adv
 
     override fun getTitleId(): Int {
         return R.string.advanced_prefs_category
@@ -86,16 +84,22 @@ class PreferencesAdvanced : BasePreferenceFragment(), SharedPreferences.OnShared
                         .setTitle(R.string.clear_playback_history)
                         .setMessage(R.string.validation)
                         .setIcon(android.R.drawable.ic_dialog_alert)
-                        .setPositiveButton(R.string.yes) { dialog, _ -> AbstractMedialibrary.getInstance().clearHistory() }
+                        .setPositiveButton(R.string.yes) { _, _ ->
+                            launch(Dispatchers.IO) { AbstractMedialibrary.getInstance().clearHistory() }
+                        }
 
                         .setNegativeButton(R.string.cancel, null).show()
                 return true
             }
             "clear_media_db" -> {
-                val i = Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
-                i.addCategory(Intent.CATEGORY_DEFAULT)
-                i.data = Uri.parse("package:" + requireContext().packageName)
-                startActivity(i)
+                AlertDialog.Builder(requireContext())
+                        .setTitle(R.string.clear_media_db)
+                        .setMessage(R.string.validation)
+                        .setIcon(android.R.drawable.ic_dialog_alert)
+                        .setPositiveButton(R.string.yes) { _, _ -> launch(Dispatchers.IO) {
+                            AbstractMedialibrary.getInstance().clearDatabase(true)
+                        }}
+                        .setNegativeButton(R.string.cancel, null).show()
                 return true
             }
             "quit_app" -> {
@@ -104,7 +108,7 @@ class PreferencesAdvanced : BasePreferenceFragment(), SharedPreferences.OnShared
             }
             "dump_media_db" -> {
                 if (AbstractMedialibrary.getInstance().isWorking)
-                    UiTools.snacker(view!!, getString(R.string.settings_ml_block_scan))
+                    view?.let { UiTools.snacker(it, getString(R.string.settings_ml_block_scan)) }
                 else {
                     val dst = File(AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY + AbstractMedialibrary.VLC_MEDIA_DB_NAME)
                     launch {
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/preferences/PreferencesAdvanced.kt b/vlc-android/src/org/videolan/vlc/gui/tv/preferences/PreferencesAdvanced.kt
index ac789e8f5..3d5e1a9f5 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/preferences/PreferencesAdvanced.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/preferences/PreferencesAdvanced.kt
@@ -86,19 +86,26 @@ class PreferencesAdvanced : BasePreferenceFragment(), SharedPreferences.OnShared
                 return true
             }
             "clear_history" -> {
-                AlertDialog.Builder(activity)
+                AlertDialog.Builder(ctx)
                         .setTitle(R.string.clear_playback_history)
                         .setMessage(R.string.validation)
                         .setIcon(android.R.drawable.ic_dialog_alert)
-                        .setPositiveButton(R.string.yes) { _, _ -> AbstractMedialibrary.getInstance().clearHistory() }
-                        .setNegativeButton(R.string.cancel, null).show()
+                        .setPositiveButton(R.string.yes) { _, _ -> launch(Dispatchers.IO) {
+                            AbstractMedialibrary.getInstance().clearHistory()
+                        }}
+                        .setNegativeButton(R.string.cancel, null)
+                        .show()
                 return true
             }
             "clear_media_db" -> {
-                val i = Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
-                i.addCategory(Intent.CATEGORY_DEFAULT)
-                i.data = Uri.parse("package:" + ctx.packageName)
-                startActivity(i)
+                AlertDialog.Builder(ctx)
+                        .setTitle(R.string.clear_media_db)
+                        .setMessage(R.string.validation)
+                        .setIcon(android.R.drawable.ic_dialog_alert)
+                        .setPositiveButton(R.string.yes) { _, _ -> launch(Dispatchers.IO) { AbstractMedialibrary.getInstance().clearDatabase(true)
+                        }}
+                        .setNegativeButton(R.string.cancel, null)
+                        .show()
                 return true
             }
             "quit_app" -> {



More information about the Android mailing list