From 3fadb792bce0bf8a3011d8e20389845fc8f08ad7 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 13 Aug 2023 20:07:29 +0200 Subject: [PATCH] fix: crash when removing video from playlist --- .../libretube/ui/adapters/PlaylistAdapter.kt | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/github/libretube/ui/adapters/PlaylistAdapter.kt b/app/src/main/java/com/github/libretube/ui/adapters/PlaylistAdapter.kt index aa57a6eb5..f948f46a4 100644 --- a/app/src/main/java/com/github/libretube/ui/adapters/PlaylistAdapter.kt +++ b/app/src/main/java/com/github/libretube/ui/adapters/PlaylistAdapter.kt @@ -7,12 +7,14 @@ import android.view.LayoutInflater import android.view.ViewGroup import androidx.core.view.isGone import androidx.recyclerview.widget.RecyclerView +import com.github.libretube.R import com.github.libretube.api.PlaylistsHelper import com.github.libretube.api.obj.StreamItem import com.github.libretube.databinding.VideoRowBinding import com.github.libretube.enums.PlaylistType import com.github.libretube.extensions.TAG import com.github.libretube.extensions.toID +import com.github.libretube.extensions.toastFromMainDispatcher import com.github.libretube.helpers.ImageHelper import com.github.libretube.helpers.NavigationHelper import com.github.libretube.ui.base.BaseActivity @@ -20,14 +22,15 @@ import com.github.libretube.ui.extensions.setFormattedDuration import com.github.libretube.ui.extensions.setWatchProgressLength import com.github.libretube.ui.sheets.VideoOptionsBottomSheet import com.github.libretube.ui.viewholders.PlaylistViewHolder -import java.io.IOException import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch +/** + * @param originalFeed original, unsorted feed, needed in order to delete the proper video from + * playlists + */ class PlaylistAdapter( - // original, unsorted feed - // needed in order to delete the proper video from playlists private val originalFeed: MutableList, private val sortedFeed: MutableList, private val playlistId: String, @@ -109,12 +112,14 @@ class PlaylistAdapter( notifyItemRemoved(position) notifyItemRangeChanged(position, itemCount) } + val appContext = context.applicationContext + CoroutineScope(Dispatchers.IO).launch { try { PlaylistsHelper.removeFromPlaylist(playlistId, playlistIndex) - } catch (e: IOException) { + } catch (e: Exception) { Log.e(TAG(), e.toString()) - return@launch + appContext.toastFromMainDispatcher(R.string.unknown_error) } } }