mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 14:20:30 +05:30
Remove playlists at library on deletion
This commit is contained in:
parent
73a7e62e57
commit
295caa3093
@ -51,11 +51,7 @@ class PlaylistsAdapter(
|
||||
|
||||
deletePlaylist.setOnClickListener {
|
||||
DeletePlaylistDialog(playlist.id!!, playlistType) {
|
||||
playlists.removeAt(position)
|
||||
(root.context as BaseActivity).runOnUiThread {
|
||||
notifyItemRemoved(position)
|
||||
notifyItemRangeChanged(position, itemCount)
|
||||
}
|
||||
onDelete(position, root.context as BaseActivity)
|
||||
}.show(
|
||||
(root.context as BaseActivity).supportFragmentManager,
|
||||
null
|
||||
@ -69,7 +65,10 @@ class PlaylistsAdapter(
|
||||
val playlistOptionsDialog = PlaylistOptionsBottomSheet(
|
||||
playlistId = playlist.id!!,
|
||||
playlistName = playlist.name!!,
|
||||
playlistType = playlistType
|
||||
playlistType = playlistType,
|
||||
onDelete = {
|
||||
onDelete(position, root.context as BaseActivity)
|
||||
}
|
||||
)
|
||||
playlistOptionsDialog.show(
|
||||
(root.context as BaseActivity).supportFragmentManager,
|
||||
@ -79,4 +78,12 @@ class PlaylistsAdapter(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun onDelete(position: Int, activity: BaseActivity) {
|
||||
playlists.removeAt(position)
|
||||
activity.runOnUiThread {
|
||||
notifyItemRemoved(position)
|
||||
notifyItemRangeChanged(position, itemCount)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,11 +16,12 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
class DeletePlaylistDialog(
|
||||
private val playlistId: String,
|
||||
private val playlistType: PlaylistType,
|
||||
private val onSuccess: () -> Unit = {}
|
||||
private val onSuccess: () -> Unit
|
||||
) : DialogFragment() {
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
return MaterialAlertDialogBuilder(requireContext())
|
||||
@ -58,7 +59,9 @@ class DeletePlaylistDialog(
|
||||
}
|
||||
try {
|
||||
if (response.message == "ok") {
|
||||
onSuccess.invoke()
|
||||
withContext(Dispatchers.Main) {
|
||||
onSuccess.invoke()
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG(), e.toString())
|
||||
|
@ -17,7 +17,8 @@ import kotlinx.coroutines.runBlocking
|
||||
class PlaylistOptionsBottomSheet(
|
||||
private val playlistId: String,
|
||||
private val playlistName: String,
|
||||
private val playlistType: PlaylistType
|
||||
private val playlistType: PlaylistType,
|
||||
private val onDelete: () -> Unit = {}
|
||||
) : BaseBottomSheet() {
|
||||
private val shareData = ShareData(currentPlaylist = playlistName)
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
@ -63,8 +64,10 @@ class PlaylistOptionsBottomSheet(
|
||||
shareDialog.show(parentFragmentManager, ShareDialog::class.java.name)
|
||||
}
|
||||
context?.getString(R.string.deletePlaylist) -> {
|
||||
DeletePlaylistDialog(playlistId, playlistType)
|
||||
.show(parentFragmentManager, null)
|
||||
DeletePlaylistDialog(playlistId, playlistType) {
|
||||
// try to refresh the playlists in the library on deletion success
|
||||
onDelete.invoke()
|
||||
}.show(parentFragmentManager, null)
|
||||
}
|
||||
context?.getString(R.string.renamePlaylist) -> {
|
||||
RenamePlaylistDialog(playlistId, playlistName)
|
||||
|
Loading…
Reference in New Issue
Block a user