Skip to content

Commit

Permalink
Previous track button should replay last one chapter before position …
Browse files Browse the repository at this point in the history
…threshold
  • Loading branch information
GrakovNe authored Nov 6, 2024
1 parent de1ecf5 commit f8702d1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ android {
applicationId = "org.grakovne.lissen"
minSdk = 28
targetSdk = 35
versionCode = 22
versionName = "1.0.21"
versionCode = 23
versionName = "1.0.22"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand All @@ -42,7 +42,7 @@ android {
release {}
debug {
matchingFallbacks.add("release")
isDebuggable = false
isDebuggable = true
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,14 @@ fun TrackControlComposable(
) {
IconButton(
onClick = {
if (currentTrackIndex > 0) {
viewModel.previousTrack()
}
viewModel.previousTrack()
},
enabled = currentTrackIndex > 0
enabled = true
) {
Icon(
imageVector = Icons.Rounded.SkipPrevious,
contentDescription = "Previous Track",
tint = when (currentTrackIndex > 0) {
true -> colorScheme.onBackground
else -> colorScheme.onBackground.copy(alpha = 0.3f)
},
tint = colorScheme.onBackground,
modifier = Modifier.size(36.dp)
)
}
Expand Down
16 changes: 14 additions & 2 deletions app/src/main/java/org/grakovne/lissen/viewmodel/PlayerViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,15 @@ class PlayerViewModel @Inject constructor(
}

fun previousTrack() {
val previousChapterIndex = currentChapterIndex.value?.let { it - 1 } ?: return
setChapter(previousChapterIndex)
val position = currentChapterPosition.value ?: return
val index = currentChapterIndex.value ?: return

val currentIndexReplay = (position > CURRENT_TRACK_REPLAY_THRESHOLD || index == 0)

when {
currentIndexReplay -> setChapter(index)
index > 0 -> setChapter(index - 1)
}
}

fun togglePlayPause() {
Expand Down Expand Up @@ -182,4 +189,9 @@ class PlayerViewModel @Inject constructor(

return 0.0
}

companion object {

private const val CURRENT_TRACK_REPLAY_THRESHOLD = 5
}
}

0 comments on commit f8702d1

Please sign in to comment.