Skip to content

Commit

Permalink
Fix pause behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
ashiagr committed Nov 15, 2022
1 parent 9c140aa commit 68e8851
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
1 change: 1 addition & 0 deletions base.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ dependencies {
implementation androidLibs.composeUi
implementation androidLibs.composeUiToolingPreview
implementation androidLibs.composeViewModel
implementation androidLibs.composeUiUtil

implementation libs.kotlinCoroutines
implementation libs.kotlinCoroutinesAndroid
Expand Down
1 change: 1 addition & 0 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ project.ext {
composeUiToolingPreview: "androidx.compose.ui:ui-tooling-preview:$versionCompose",
composeRx: "androidx.compose.runtime:runtime-rxjava2:$versionCompose",
composeViewModel: "androidx.lifecycle:lifecycle-viewmodel-compose:$versionLifecycle",
composeUiUtil: "androidx.compose.ui:ui-util:$versionCompose",
guava: 'com.google.guava:guava:27.1-android' // Required to fix conflict between versions in exoplayer and workmanager
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp
import androidx.core.app.ShareCompat
import androidx.lifecycle.viewmodel.compose.viewModel
import au.com.shiftyjelly.pocketcasts.compose.AppTheme
import au.com.shiftyjelly.pocketcasts.compose.bars.NavigationButton
import au.com.shiftyjelly.pocketcasts.compose.buttons.RowOutlinedButton
import au.com.shiftyjelly.pocketcasts.compose.components.TextP50
import au.com.shiftyjelly.pocketcasts.compose.preview.ThemePreviewParameterProvider
import au.com.shiftyjelly.pocketcasts.endofyear.ShareableTextProvider.ShareTextData
import au.com.shiftyjelly.pocketcasts.endofyear.StoriesViewModel.State
import au.com.shiftyjelly.pocketcasts.endofyear.utils.waitForUpInitial
import au.com.shiftyjelly.pocketcasts.endofyear.views.SegmentedProgressIndicator
import au.com.shiftyjelly.pocketcasts.endofyear.views.convertibleToBitmap
import au.com.shiftyjelly.pocketcasts.endofyear.views.stories.StoryEpilogueView
Expand Down Expand Up @@ -343,10 +343,10 @@ private fun StorySwitcher(
.pointerInput(Unit) {
detectTapGestures(
onPress = {
val pressStartTime = System.currentTimeMillis()
onPause()
val isReleased = tryAwaitRelease()
if (isReleased) {
awaitPointerEventScope {
val pressStartTime = System.currentTimeMillis()
onPause()
waitForUpInitial()
val pressEndTime = System.currentTimeMillis()
val diffPressTime = pressEndTime - pressStartTime
if (diffPressTime < LongPressThresholdTimeInMs) {
Expand All @@ -358,8 +358,6 @@ private fun StorySwitcher(
} else {
onStart()
}
} else {
onStart()
}
}
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package au.com.shiftyjelly.pocketcasts.endofyear.utils

import androidx.compose.ui.input.pointer.AwaitPointerEventScope
import androidx.compose.ui.input.pointer.PointerEventPass
import androidx.compose.ui.input.pointer.PointerInputChange
import androidx.compose.ui.input.pointer.changedToUp
import androidx.compose.ui.util.fastAll

suspend fun AwaitPointerEventScope.waitForUpInitial(): PointerInputChange {
while (true) {
/* PointerEventPass.Initial: Allows parent to consume aspects of PointerInputChange before children. */
val event = awaitPointerEvent(PointerEventPass.Initial)
if (event.changes.fastAll { it.changedToUp() }) {
return event.changes[0]
}
}
}

0 comments on commit 68e8851

Please sign in to comment.