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