Merge pull request #4752 from Bnyro/master

fix: crash when deleting playlist, playlist description not shown
This commit is contained in:
Bnyro 2023-09-10 20:02:17 +02:00 committed by GitHub
commit 34261bfe4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 13 deletions

View File

@ -45,6 +45,7 @@ class PlaylistsAdapter(
ImageHelper.loadImage(playlist.thumbnail, playlistThumbnail)
}
playlistTitle.text = playlist.name
playlistDescription.text = playlist.shortDescription
videoCount.text = playlist.videos.toString()

View File

@ -1,10 +1,12 @@
package com.github.libretube.ui.dialogs
import android.app.AlertDialog
import android.app.Dialog
import android.os.Bundle
import androidx.core.os.bundleOf
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.setFragmentResult
import androidx.lifecycle.lifecycleScope
import com.github.libretube.R
import com.github.libretube.api.PlaylistsHelper
import com.github.libretube.constants.IntentData
@ -16,6 +18,7 @@ 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 : DialogFragment() {
private lateinit var playlistId: String
@ -31,20 +34,23 @@ class DeletePlaylistDialog : DialogFragment() {
return MaterialAlertDialogBuilder(requireContext())
.setTitle(R.string.deletePlaylist)
.setMessage(R.string.areYouSure)
.setPositiveButton(R.string.yes) { _, _ ->
val appContext = context?.applicationContext
CoroutineScope(Dispatchers.IO).launch {
val success = PlaylistsHelper.deletePlaylist(playlistId, playlistType)
appContext?.toastFromMainDispatcher(
if (success) R.string.success else R.string.fail
)
setFragmentResult(
PlaylistOptionsBottomSheet.PLAYLIST_OPTIONS_REQUEST_KEY,
bundleOf(IntentData.playlistTask to true)
)
}
}
.setPositiveButton(R.string.yes, null)
.setNegativeButton(R.string.cancel, null)
.show()
.apply {
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
lifecycleScope.launch(Dispatchers.IO) {
val success = PlaylistsHelper.deletePlaylist(playlistId, playlistType)
context.toastFromMainDispatcher(
if (success) R.string.success else R.string.fail
)
setFragmentResult(
PlaylistOptionsBottomSheet.PLAYLIST_OPTIONS_REQUEST_KEY,
bundleOf(IntentData.playlistTask to true)
)
withContext(Dispatchers.Main) { dismiss() }
}
}
}
}
}