[Android] Improve the clear media database 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:02:17 2021 +0200| [73d398a1163e26e9273b9bd1bc0a69689fff91bf] | committer: Nicolas Pomepuy
Improve the clear media database setting
Use the deletion confirmation dialog
Re-discover the internal storage
Fixes #2038
> https://code.videolan.org/videolan/vlc-android/commit/73d398a1163e26e9273b9bd1bc0a69689fff91bf
---
.../resources/src/main/res/values/strings.xml | 3 +-
.../ui/preferences/PreferencesAdvanced.kt | 24 ++++++++++-----
.../vlc/gui/preferences/PreferencesAdvanced.kt | 36 ++++++++++++++--------
3 files changed, 42 insertions(+), 21 deletions(-)
diff --git a/application/resources/src/main/res/values/strings.xml b/application/resources/src/main/res/values/strings.xml
index fc3911e86..8d3222c5a 100644
--- a/application/resources/src/main/res/values/strings.xml
+++ b/application/resources/src/main/res/values/strings.xml
@@ -701,7 +701,8 @@
<string name="recently_played">Recently played</string>
<string name="recently_added">Recently added</string>
<string name="playback_multiple_errors">Multiple media cannot be played</string>
- <string name="clear_media_db_warning">You will lose your progresses and the playlists you created.\n%s</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">Clear</string>
<string name="abrepeat_add_first_marker">Set start point</string>
<string name="abrepeat_add_second_marker">Set end point</string>
<string name="demux_bitrate">Demux bitrate</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 73db98ec3..3306a62ae 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
@@ -34,6 +34,7 @@ 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.*
@@ -42,8 +43,11 @@ import org.videolan.resources.AndroidDevices
import org.videolan.resources.VLCInstance
import org.videolan.tools.putSingle
import org.videolan.vlc.BuildConfig
+import org.videolan.vlc.MediaParsingService
import org.videolan.vlc.R
import org.videolan.vlc.gui.DebugLogActivity
+import org.videolan.vlc.gui.dialogs.ConfirmDeleteDialog
+import org.videolan.vlc.gui.dialogs.RenameDialog
import org.videolan.vlc.gui.helpers.hf.StoragePermissionsDelegate.Companion.getWritePermission
import org.videolan.vlc.util.FeatureFlag
import org.videolan.vlc.util.FileUtils
@@ -101,14 +105,18 @@ class PreferencesAdvanced : BasePreferenceFragment(), SharedPreferences.OnShared
return true
}
"clear_media_db" -> {
- AlertDialog.Builder(ctx)
- .setTitle(R.string.clear_media_db)
- .setMessage(R.string.validation)
- .setIcon(R.drawable.ic_warning)
- .setPositiveButton(R.string.yes) { _, _ -> launch(Dispatchers.IO) { Medialibrary.getInstance().clearDatabase(true)
- }}
- .setNegativeButton(R.string.cancel, null)
- .show()
+ 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)
+ dialog.setListener {
+ launch {
+ val medialibrary = Medialibrary.getInstance()
+ activity.stopService(Intent(activity, MediaParsingService::class.java))
+ withContext((Dispatchers.IO)) {
+ medialibrary.clearDatabase(true)
+ }
+ medialibrary.discover(AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY)
+ }
+ }
return true
}
"quit_app" -> {
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 543f1c8a6..492961a08 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,6 +23,8 @@
package org.videolan.vlc.gui.preferences
+import android.app.AlarmManager
+import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
@@ -36,18 +38,24 @@ import androidx.preference.EditTextPreference
import androidx.preference.Preference
import kotlinx.coroutines.*
import org.videolan.medialibrary.interfaces.Medialibrary
-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.resources.*
+import org.videolan.tools.RESULT_RESTART
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
@@ -103,14 +111,18 @@ class PreferencesAdvanced : BasePreferenceFragment(), SharedPreferences.OnShared
return true
}
"clear_media_db" -> {
- AlertDialog.Builder(requireContext())
- .setTitle(R.string.clear_media_db)
- .setMessage(getString(R.string.clear_media_db_warning, getString(R.string.validation)))
- .setIcon(R.drawable.ic_warning)
- .setPositiveButton(R.string.yes) { _, _ -> lifecycleScope.launch(Dispatchers.IO) {
- Medialibrary.getInstance().clearDatabase(true)
- }}
- .setNegativeButton(R.string.cancel, null).show()
+ 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(requireActivity().supportFragmentManager, RenameDialog::class.simpleName)
+ dialog.setListener {
+ lifecycleScope.launch {
+ val medialibrary = Medialibrary.getInstance()
+ requireActivity().stopService(Intent(requireActivity(), MediaParsingService::class.java))
+ withContext((Dispatchers.IO)) {
+ medialibrary.clearDatabase(true)
+ }
+ medialibrary.discover(AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY)
+ }
+ }
return true
}
"quit_app" -> {
More information about the Android
mailing list