make the copied playlist name unique

Changelog: changed
This commit is contained in:
Kai 2025-06-06 09:39:09 -05:00
commit dd1c04bea1
No known key found for this signature in database
2 changed files with 10 additions and 3 deletions

View file

@ -170,7 +170,14 @@ class PlaylistFragment : MainFragment() {
}
private fun copyPlaylist(playlist: Playlist) {
StatePlaylists.instance.playlistStore.save(playlist.makeCopy())
var copyNumber = 1
var newName = "${playlist.name} (Copy)"
val playlists = StatePlaylists.instance.playlistStore.getItems()
while (playlists.any { it.name == newName }) {
copyNumber += 1
newName = "${playlist.name} (Copy $copyNumber)"
}
StatePlaylists.instance.playlistStore.save(playlist.makeCopy(newName))
UIDialogs.toast("Playlist copied")
}

View file

@ -35,8 +35,8 @@ class Playlist {
this.videos = ArrayList(list);
}
fun makeCopy(): Playlist {
return Playlist("$name (Copy)", videos)
fun makeCopy(newName: String? = null): Playlist {
return Playlist(newName ?: name, videos)
}
companion object {