[Android] Add a way to overwrite a playlist in the SavePlaylistDialog
Nicolas Pomepuy
git at videolan.org
Thu May 11 07:59:33 UTC 2023
vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Mon Mar 20 12:02:49 2023 +0100| [bb08c12d0a5e613db86eca6890b687bed15db6a8] | committer: Duncan McNamara
Add a way to overwrite a playlist in the SavePlaylistDialog
Fixes #2697
> https://code.videolan.org/videolan/vlc-android/commit/bb08c12d0a5e613db86eca6890b687bed15db6a8
---
application/resources/src/main/res/values/strings.xml | 1 +
application/vlc-android/res/layout/dialog_playlist.xml | 15 +++++++++++++--
.../org/videolan/vlc/gui/dialogs/SavePlaylistDialog.kt | 9 +++++++--
3 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/application/resources/src/main/res/values/strings.xml b/application/resources/src/main/res/values/strings.xml
index ab12f1c303..226d8fe67f 100644
--- a/application/resources/src/main/res/values/strings.xml
+++ b/application/resources/src/main/res/values/strings.xml
@@ -1110,6 +1110,7 @@
<string name="show_only_favs">Show only favorites</string>
<string name="ignore_headset_media_button_presses">Ignore headset media button presses</string>
<string name="ignore_headset_media_button_presses_summary">Useful, for instance, if you are using a headset with broken physical buttons</string>
+ <string name="replace_playlist">Replace playlist</string>
</resources>
diff --git a/application/vlc-android/res/layout/dialog_playlist.xml b/application/vlc-android/res/layout/dialog_playlist.xml
index 92ab69b2da..e2840edc9b 100644
--- a/application/vlc-android/res/layout/dialog_playlist.xml
+++ b/application/vlc-android/res/layout/dialog_playlist.xml
@@ -107,15 +107,26 @@
app:layout_constraintStart_toEndOf="@+id/textView8"
app:layout_constraintTop_toTopOf="@+id/textView8" />
+ <androidx.appcompat.widget.SwitchCompat
+ android:id="@+id/replaceSwitch"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_marginStart="8dp"
+ android:layout_marginEnd="8dp"
+ android:text="@string/replace_playlist"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toBottomOf="@+id/medias" />
+
<FrameLayout
android:id="@+id/dialog_list_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:layout_marginTop="8dp"
+ android:layout_marginTop="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toBottomOf="@+id/medias">
+ app:layout_constraintTop_toBottomOf="@+id/replaceSwitch">
<androidx.recyclerview.widget.RecyclerView
android:id="@android:id/list"
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/dialogs/SavePlaylistDialog.kt b/application/vlc-android/src/org/videolan/vlc/gui/dialogs/SavePlaylistDialog.kt
index d4474c9ffa..2cd110e494 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/dialogs/SavePlaylistDialog.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/dialogs/SavePlaylistDialog.kt
@@ -225,7 +225,12 @@ class SavePlaylistDialog : VLCBottomSheetDialogFragment(), View.OnClickListener,
} else
ids.add(id)
}
- playlist.append(ids)
+ if (binding.replaceSwitch.isChecked) {
+ val name = playlist.title
+ playlist.delete()
+ val newPlaylist = medialibrary.createPlaylist(name, Settings.includeMissing, false)
+ newPlaylist.append(ids)
+ } else playlist.append(ids)
}
dismiss()
}
@@ -234,7 +239,7 @@ class SavePlaylistDialog : VLCBottomSheetDialogFragment(), View.OnClickListener,
selectedPlaylist = item as Playlist
nonDuplicateTracks = getNonDuplicateTracks(selectedPlaylist!!.tracks, newTracks)
val duplicateItemsCount = newTracks.size - nonDuplicateTracks!!.size
- if (duplicateItemsCount == 0) {
+ if (duplicateItemsCount == 0 || binding.replaceSwitch.isChecked) {
savePlaylist(selectedPlaylist!!, newTracks)
} else {
val highlightedItemsCount = newTracks.size
More information about the Android
mailing list