Skip to content

Commit 59a08c4

Browse files
committed
Fix LongPressMenu crashing if dismissed while loading
1 parent 423c427 commit 59a08c4

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

app/src/main/java/org/schabi/newpipe/ui/components/menu/LongPressAction.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,9 @@ data class LongPressAction(
158158
private fun buildPlayerShuffledActionList(queue: suspend (Context) -> PlayQueue): List<LongPressAction> {
159159
val shuffledQueue: suspend (Context) -> PlayQueue = { context ->
160160
val q = queue(context)
161-
q.fetchAllAndShuffle()
161+
withContext(Dispatchers.IO) {
162+
q.fetchAllAndShuffle()
163+
}
162164
q
163165
}
164166
return listOf(

app/src/main/java/org/schabi/newpipe/ui/components/menu/LongPressMenu.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,14 @@ import androidx.compose.ui.window.DialogProperties
8080
import androidx.lifecycle.viewmodel.compose.viewModel
8181
import coil3.compose.AsyncImage
8282
import java.time.OffsetDateTime
83+
import kotlinx.coroutines.CancellationException
8384
import kotlinx.coroutines.Dispatchers
8485
import kotlinx.coroutines.launch
85-
import kotlinx.coroutines.withContext
8686
import org.schabi.newpipe.R
8787
import org.schabi.newpipe.error.ErrorInfo
8888
import org.schabi.newpipe.error.ErrorUtil
8989
import org.schabi.newpipe.error.UserAction.LONG_PRESS_MENU_ACTION
9090
import org.schabi.newpipe.extractor.stream.StreamType
91-
import org.schabi.newpipe.player.helper.PlayerHolder
92-
import org.schabi.newpipe.ui.components.common.ScaffoldWithToolbar
9391
import org.schabi.newpipe.ui.components.menu.LongPressAction.Type.EnqueueNext
9492
import org.schabi.newpipe.ui.components.menu.LongPressAction.Type.ShowChannelDetails
9593
import org.schabi.newpipe.ui.discardAllTouchesIf
@@ -122,7 +120,7 @@ fun getLongPressMenuView(
122120
LongPressMenu(
123121
longPressable = longPressable,
124122
longPressActions = longPressActions,
125-
onDismissRequest = { (this.parent as ViewGroup).removeView(this) }
123+
onDismissRequest = { (this.parent as? ViewGroup)?.removeView(this) }
126124
)
127125
}
128126
}
@@ -173,6 +171,8 @@ fun LongPressMenu(
173171
coroutineScope.launch {
174172
try {
175173
action.action(ctx)
174+
} catch (_: CancellationException) {
175+
// the user canceled the action, e.g. by dismissing the dialog while loading
176176
} catch (t: Throwable) {
177177
ErrorUtil.showSnackbar(
178178
ctx,

0 commit comments

Comments
 (0)