[Android] Trigger a dialog for history deletion
Nicolas Pomepuy
git at videolan.org
Wed May 18 05:36:45 UTC 2022
vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Mon May 16 08:27:28 2022 +0200| [25d2ac496cc50cafb4bb8d1ab484b6bfbc6f7764] | committer: Nicolas Pomepuy
Trigger a dialog for history deletion
Fixes #2520
> https://code.videolan.org/videolan/vlc-android/commit/25d2ac496cc50cafb4bb8d1ab484b6bfbc6f7764
---
.../resources/src/main/res/values/strings.xml | 2 +-
.../ui/preferences/PreferencesAdvanced.kt | 19 +++++++-------
.../src/org/videolan/vlc/gui/HistoryFragment.kt | 15 +++++++++--
.../vlc/gui/preferences/PreferencesAdvanced.kt | 29 +++++++++++-----------
4 files changed, 37 insertions(+), 28 deletions(-)
diff --git a/application/resources/src/main/res/values/strings.xml b/application/resources/src/main/res/values/strings.xml
index 8c770a5f9..4cbd2b3b5 100644
--- a/application/resources/src/main/res/values/strings.xml
+++ b/application/resources/src/main/res/values/strings.xml
@@ -123,7 +123,6 @@
<string name="nosubfolder">No subfolder</string>
<string name="directorynotfound">The directory path \'%1$s\' was not found.</string>
<string name="nohistory">You have no playback history yet.</string>
- <string name="validation">Are you sure?</string>
<string name="cover_art">Cover art</string>
<string name="shuffle_all_title">Shuffle all</string>
@@ -449,6 +448,7 @@
<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="clear_history_message">You will lose your history, your current playlists and your progresses</string>
<string name="set_locale">Set locale</string>
<string name="network_caching">Network caching value</string>
<string name="network_caching_summary">The amount of time to buffer network media (in ms) for software decoding\nSet to 0 to disable</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 8a19a2f9d..0418b036a 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
@@ -25,7 +25,6 @@ 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
import android.content.SharedPreferences
@@ -43,8 +42,11 @@ 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.tools.BitmapCache
+import org.videolan.tools.Settings
import org.videolan.tools.putSingle
import org.videolan.vlc.BuildConfig
import org.videolan.vlc.MediaParsingService
@@ -111,15 +113,12 @@ class PreferencesAdvanced : BasePreferenceFragment(), SharedPreferences.OnShared
return true
}
"clear_history" -> {
- AlertDialog.Builder(ctx)
- .setTitle(R.string.clear_playback_history)
- .setMessage(R.string.validation)
- .setIcon(R.drawable.ic_warning)
- .setPositiveButton(R.string.yes) { _, _ -> launch(Dispatchers.IO) {
- Medialibrary.getInstance().clearHistory()
- }}
- .setNegativeButton(R.string.cancel, null)
- .show()
+ val dialog = ConfirmDeleteDialog.newInstance(title = getString(R.string.clear_playback_history), description = getString(R.string.clear_history_message), buttonText = getString(R.string.clear_history))
+ dialog.show((activity as FragmentActivity).supportFragmentManager, RenameDialog::class.simpleName)
+ dialog.setListener {
+ Medialibrary.getInstance().clearHistory()
+ Settings.getInstance(activity).edit().remove(KEY_AUDIO_LAST_PLAYLIST).remove(KEY_MEDIA_LAST_PLAYLIST).apply()
+ }
return true
}
"clear_app_data" -> {
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/HistoryFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/HistoryFragment.kt
index a1b624caa..68675d4b3 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/HistoryFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/HistoryFragment.kt
@@ -23,6 +23,7 @@ import android.os.Bundle
import android.view.*
import android.widget.TextView
import androidx.appcompat.view.ActionMode
+import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.ItemTouchHelper
@@ -33,9 +34,13 @@ import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
import org.videolan.medialibrary.interfaces.media.MediaWrapper
import org.videolan.medialibrary.media.MediaLibraryItem
+import org.videolan.resources.KEY_AUDIO_LAST_PLAYLIST
+import org.videolan.resources.KEY_MEDIA_LAST_PLAYLIST
import org.videolan.tools.*
import org.videolan.vlc.R
import org.videolan.vlc.gui.browser.MediaBrowserFragment
+import org.videolan.vlc.gui.dialogs.ConfirmDeleteDialog
+import org.videolan.vlc.gui.dialogs.RenameDialog
import org.videolan.vlc.gui.helpers.*
import org.videolan.vlc.interfaces.IHistory
import org.videolan.vlc.interfaces.IListEventsHandler
@@ -123,8 +128,13 @@ class HistoryFragment : MediaBrowserFragment<HistoryModel>(), IRefreshable, IHis
override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
R.id.ml_menu_clean -> {
- clearHistory()
- requireActivity().finish()
+
+ val dialog = ConfirmDeleteDialog.newInstance(title = getString(R.string.clear_playback_history), description = getString(R.string.clear_history_message), buttonText = getString(R.string.clear_history))
+ dialog.show((activity as FragmentActivity).supportFragmentManager, RenameDialog::class.simpleName)
+ dialog.setListener {
+ clearHistory()
+ requireActivity().finish()
+ }
true
}
else -> super.onOptionsItemSelected(item)
@@ -166,6 +176,7 @@ class HistoryFragment : MediaBrowserFragment<HistoryModel>(), IRefreshable, IHis
override fun clearHistory() {
mediaLibrary.clearHistory()
viewModel.clearHistory()
+ Settings.getInstance(requireActivity()).edit().remove(KEY_AUDIO_LAST_PLAYLIST).remove(KEY_MEDIA_LAST_PLAYLIST).apply()
}
override fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean {
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 d16ccd50d..44f3372fb 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
@@ -35,14 +35,19 @@ import android.text.InputFilter
import android.text.InputType
import android.util.Log
import android.widget.Toast
-import androidx.appcompat.app.AlertDialog
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.*
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.launch
+import kotlinx.coroutines.withContext
import org.videolan.medialibrary.interfaces.Medialibrary
-import org.videolan.resources.*
+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.BitmapCache
import org.videolan.tools.Settings
import org.videolan.tools.putSingle
@@ -100,18 +105,12 @@ class PreferencesAdvanced : BasePreferenceFragment(), SharedPreferences.OnShared
return true
}
"clear_history" -> {
- AlertDialog.Builder(requireContext())
- .setTitle(R.string.clear_playback_history)
- .setMessage(R.string.validation)
- .setIcon(R.drawable.ic_warning)
- .setPositiveButton(R.string.yes) { _, _ ->
- lifecycleScope.launch(Dispatchers.IO) {
- Medialibrary.getInstance().clearHistory()
- Settings.getInstance(requireActivity()).edit().remove(KEY_AUDIO_LAST_PLAYLIST).remove(KEY_MEDIA_LAST_PLAYLIST).apply()
- }
- }
-
- .setNegativeButton(R.string.cancel, null).show()
+ val dialog = ConfirmDeleteDialog.newInstance(title = getString(R.string.clear_playback_history), description = getString(R.string.clear_history_message), buttonText = getString(R.string.clear_history))
+ dialog.show((activity as FragmentActivity).supportFragmentManager, RenameDialog::class.simpleName)
+ dialog.setListener {
+ Medialibrary.getInstance().clearHistory()
+ Settings.getInstance(requireActivity()).edit().remove(KEY_AUDIO_LAST_PLAYLIST).remove(KEY_MEDIA_LAST_PLAYLIST).apply()
+ }
return true
}
"clear_media_db" -> {
More information about the Android
mailing list