diff --git a/Armadillo/src/main/java/com/scribd/armadillo/Reducer.kt b/Armadillo/src/main/java/com/scribd/armadillo/Reducer.kt index 5f60b77..2cac038 100644 --- a/Armadillo/src/main/java/com/scribd/armadillo/Reducer.kt +++ b/Armadillo/src/main/java/com/scribd/armadillo/Reducer.kt @@ -175,14 +175,24 @@ internal object Reducer { isSeeking = action.isSeeking, seekTarget = action.seekPositionTarget) } else MediaControlState() - + val progress = if (action.seekPositionTarget != null) { + playbackInfo.progress.copy( + positionInDuration = action.seekPositionTarget, + currentChapterIndex = playbackInfo.audioPlayable.getChapterIndexAtOffset(action.seekPositionTarget)) + } else { + playbackInfo.progress + } oldState.copy(playbackInfo = playbackInfo.copy( + progress = progress, controlState = controlState)) .apply { debugState = newDebug } } is FastForwardAction -> { val playbackInfo = oldState.playbackInfo ?: throw ActionBeforeSetup(action) oldState.copy(playbackInfo = playbackInfo.copy( + progress = playbackInfo.progress.copy( + positionInDuration = action.seekPositionTarget, + currentChapterIndex = playbackInfo.audioPlayable.getChapterIndexAtOffset(action.seekPositionTarget)), controlState = MediaControlState( isSeeking = true, isFastForwarding = true, @@ -192,6 +202,9 @@ internal object Reducer { is RewindAction -> { val playbackInfo = oldState.playbackInfo ?: throw ActionBeforeSetup(action) oldState.copy(playbackInfo = playbackInfo.copy( + progress = playbackInfo.progress.copy( + positionInDuration = action.seekPositionTarget, + currentChapterIndex = playbackInfo.audioPlayable.getChapterIndexAtOffset(action.seekPositionTarget)), controlState = MediaControlState( isSeeking = true, isRewinding = true, @@ -201,6 +214,9 @@ internal object Reducer { is SkipNextAction -> { val playbackInfo = oldState.playbackInfo ?: throw ActionBeforeSetup(action) oldState.copy(playbackInfo = playbackInfo.copy( + progress = playbackInfo.progress.copy( + positionInDuration = action.seekPositionTarget, + currentChapterIndex = playbackInfo.audioPlayable.getChapterIndexAtOffset(action.seekPositionTarget)), controlState = MediaControlState( isSeeking = true, isNextChapter = true, @@ -210,6 +226,9 @@ internal object Reducer { is SkipPrevAction -> { val playbackInfo = oldState.playbackInfo ?: throw ActionBeforeSetup(action) oldState.copy(playbackInfo = playbackInfo.copy( + progress = playbackInfo.progress.copy( + positionInDuration = action.seekPositionTarget, + currentChapterIndex = playbackInfo.audioPlayable.getChapterIndexAtOffset(action.seekPositionTarget)), controlState = MediaControlState( isSeeking = true, isPrevChapter = true, diff --git a/Armadillo/src/main/java/com/scribd/armadillo/actions/Action.kt b/Armadillo/src/main/java/com/scribd/armadillo/actions/Action.kt index 59788c0..fc505b4 100644 --- a/Armadillo/src/main/java/com/scribd/armadillo/actions/Action.kt +++ b/Armadillo/src/main/java/com/scribd/armadillo/actions/Action.kt @@ -61,19 +61,19 @@ internal data class SeekAction(val isSeeking: Boolean, val seekPositionTarget: M override val name = "Seeking: $isSeeking" } -internal data class FastForwardAction(val seekPositionTarget: Milliseconds?) : Action { +internal data class FastForwardAction(val seekPositionTarget: Milliseconds) : Action { override val name = "FastForwardAction: $seekPositionTarget" } -internal data class RewindAction(val seekPositionTarget: Milliseconds?) : Action { +internal data class RewindAction(val seekPositionTarget: Milliseconds) : Action { override val name = "RewindAction: $seekPositionTarget" } -internal data class SkipNextAction(val seekPositionTarget: Milliseconds?) : Action { +internal data class SkipNextAction(val seekPositionTarget: Milliseconds) : Action { override val name = "SkipNextAction: $seekPositionTarget" } -internal data class SkipPrevAction(val seekPositionTarget: Milliseconds?) : Action { +internal data class SkipPrevAction(val seekPositionTarget: Milliseconds) : Action { override val name = "SkipNextAction: $seekPositionTarget" } diff --git a/Armadillo/src/test/java/com/scribd/armadillo/ReducerTest.kt b/Armadillo/src/test/java/com/scribd/armadillo/ReducerTest.kt index 87c37d1..2899d10 100644 --- a/Armadillo/src/test/java/com/scribd/armadillo/ReducerTest.kt +++ b/Armadillo/src/test/java/com/scribd/armadillo/ReducerTest.kt @@ -61,6 +61,70 @@ class ReducerTest { assertThat(newState.playbackInfo!!.playbackSpeed).isEqualTo(PLAYBACK_SPEED) } + @Test + fun reduce_seek_updatesPlaybackAndControlState() { + val targetDistance = 10.milliseconds + val newState = Reducer.reduce(MockModels.appState(), SeekAction(true, targetDistance)) + assertThat(newState.playbackInfo!!.progress.positionInDuration).isEqualTo(targetDistance) + assertThat(newState.playbackInfo!!.progress.currentChapterIndex).isEqualTo(0) + + val controlState = newState.playbackInfo!!.controlState + assertThat(controlState.isSeeking).isTrue + assertThat(controlState.seekTarget).isEqualTo(targetDistance) + } + + @Test + fun reduce_fastForward_updatesPlaybackAndControlState() { + val targetDistance = 10.milliseconds + val newState = Reducer.reduce(MockModels.appState(), FastForwardAction(targetDistance)) + assertThat(newState.playbackInfo!!.progress.positionInDuration).isEqualTo(targetDistance) + assertThat(newState.playbackInfo!!.progress.currentChapterIndex).isEqualTo(0) + + val controlState = newState.playbackInfo!!.controlState + assertThat(controlState.isSeeking).isTrue + assertThat(controlState.seekTarget).isEqualTo(targetDistance) + assertThat(controlState.isFastForwarding).isTrue + } + + @Test + fun reduce_rewind_updatesPlaybackAndControlState() { + val targetDistance = 10.milliseconds + val newState = Reducer.reduce(MockModels.appState(), RewindAction(targetDistance)) + assertThat(newState.playbackInfo!!.progress.positionInDuration).isEqualTo(targetDistance) + assertThat(newState.playbackInfo!!.progress.currentChapterIndex).isEqualTo(0) + + val controlState = newState.playbackInfo!!.controlState + assertThat(controlState.isSeeking).isTrue + assertThat(controlState.seekTarget).isEqualTo(targetDistance) + assertThat(controlState.isRewinding).isTrue + } + + @Test + fun reduce_skipNext_updatesPlaybackAndControlState() { + val targetDistance = 10.milliseconds + val newState = Reducer.reduce(MockModels.appState(), SkipNextAction(targetDistance)) + assertThat(newState.playbackInfo!!.progress.positionInDuration).isEqualTo(targetDistance) + assertThat(newState.playbackInfo!!.progress.currentChapterIndex).isEqualTo(0) + + val controlState = newState.playbackInfo!!.controlState + assertThat(controlState.isSeeking).isTrue + assertThat(controlState.seekTarget).isEqualTo(targetDistance) + assertThat(controlState.isNextChapter).isTrue + } + + @Test + fun reduce_skipPrev_updatesPlaybackAndControlState() { + val targetDistance = 10.milliseconds + val newState = Reducer.reduce(MockModels.appState(), SkipPrevAction(targetDistance)) + assertThat(newState.playbackInfo!!.progress.positionInDuration).isEqualTo(targetDistance) + assertThat(newState.playbackInfo!!.progress.currentChapterIndex).isEqualTo(0) + + val controlState = newState.playbackInfo!!.controlState + assertThat(controlState.isSeeking).isTrue + assertThat(controlState.seekTarget).isEqualTo(targetDistance) + assertThat(controlState.isPrevChapter).isTrue + } + @Test fun reduce_NewAudiobookAction() { val newState = Reducer.reduce(MockModels.appState(), diff --git a/RELEASE.md b/RELEASE.md index feee41f..22d22c6 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -1,5 +1,8 @@ # Project Armadillo Release Notes +## 1.3.2 +- Added a fix for updating the playback info progress in the reducer for seek related controls + ## 1.3.1 - Adds support for offline DRM for downloaded MPEG-DASH audio diff --git a/gradle.properties b/gradle.properties index 280d925..1fb9cb9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,7 +12,7 @@ org.gradle.jvmargs=-Xmx1536m # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true PACKAGE_NAME=com.scribd.armadillo -LIBRARY_VERSION=1.3.1 +LIBRARY_VERSION=1.3.2 EXOPLAYER_VERSION=2.17.1 RXJAVA_VERSION=2.2.4 RXANDROID_VERSION=2.0.1