Skip to content

Commit

Permalink
Restore saving of book playback rates (PP-1950).
Browse files Browse the repository at this point in the history
  • Loading branch information
io7m committed Nov 21, 2024
1 parent fd278ba commit 39ef59e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
9 changes: 7 additions & 2 deletions README-CHANGES.xml
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@
</c:change>
</c:changes>
</c:release>
<c:release date="2024-11-20T14:16:55+00:00" is-open="true" ticket-system="org.lyrasis.jira" version="1.15.0">
<c:release date="2024-11-21T15:21:12+00:00" is-open="true" ticket-system="org.lyrasis.jira" version="1.15.0">
<c:changes>
<c:change date="2024-10-25T00:00:00+00:00" summary="Support streaming for LCP audiobooks.">
<c:tickets>
Expand All @@ -598,11 +598,16 @@
<c:ticket id="PP-1913"/>
</c:tickets>
</c:change>
<c:change date="2024-11-20T14:16:55+00:00" summary="Strip HTML tags from book summaries.">
<c:change date="2024-11-20T00:00:00+00:00" summary="Strip HTML tags from book summaries.">
<c:tickets>
<c:ticket id="PP-1901"/>
</c:tickets>
</c:change>
<c:change date="2024-11-21T15:21:12+00:00" summary="Restore saving of book playback rates.">
<c:tickets>
<c:ticket id="PP-1950"/>
</c:tickets>
</c:change>
</c:changes>
</c:release>
</c:releases>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import org.nypl.simplified.books.covers.BookCoverProviderType
import org.nypl.simplified.books.time.tracking.TimeTrackingServiceType
import org.nypl.simplified.buildconfig.api.BuildConfigurationServiceType
import org.nypl.simplified.opds.core.getOrNull
import org.nypl.simplified.profiles.controller.api.ProfilesControllerType
import org.nypl.simplified.taskrecorder.api.TaskRecorder
import org.nypl.simplified.taskrecorder.api.TaskResult
import org.nypl.simplified.ui.errorpage.ErrorPageFragment
Expand All @@ -69,6 +70,7 @@ class AudioBookPlayerActivity2 : AppCompatActivity(R.layout.audio_book_player_ba
private lateinit var bookmarkService: BookmarkServiceType
private lateinit var buildConfig: BuildConfigurationServiceType
private lateinit var coverService: BookCoverProviderType
private lateinit var profiles: ProfilesControllerType
private lateinit var timeTrackingService: TimeTrackingServiceType

private var fragmentNow: Fragment = AudioBookLoadingFragment2()
Expand Down Expand Up @@ -98,6 +100,8 @@ class AudioBookPlayerActivity2 : AppCompatActivity(R.layout.audio_book_player_ba
services.requireService(BookCoverProviderType::class.java)
this.timeTrackingService =
services.requireService(TimeTrackingServiceType::class.java)
this.profiles =
services.requireService(ProfilesControllerType::class.java)
}

override fun onStart() {
Expand Down Expand Up @@ -174,7 +178,6 @@ class AudioBookPlayerActivity2 : AppCompatActivity(R.layout.audio_book_player_ba
is PlayerAccessibilityIsWaitingForChapter,
is PlayerAccessibilityPlaybackRateChanged,
is PlayerAccessibilitySleepTimerSettingChanged,
is PlayerEventPlaybackRateChanged,
is PlayerEventChapterCompleted,
is PlayerEventChapterWaiting,
is PlayerEventPlaybackBuffering,
Expand Down Expand Up @@ -274,6 +277,21 @@ class AudioBookPlayerActivity2 : AppCompatActivity(R.layout.audio_book_player_ba
is PlayerEventManifestUpdated -> {
// Nothing yet...
}

is PlayerEventPlaybackRateChanged -> {
val parameters =
AudioBookViewerModel.parameters ?: return

this.profiles.profileUpdate { description ->
description.copy(
preferences = description.preferences.copy(
playbackRates = description.preferences.playbackRates.plus(
Pair(parameters.bookID.value(), event.rate)
)
)
)
}
}
}
}

Expand Down Expand Up @@ -374,6 +392,7 @@ class AudioBookPlayerActivity2 : AppCompatActivity(R.layout.audio_book_player_ba

is PlayerModelState.PlayerOpen -> {
this.loadCoverImage()
this.setPlaybackRateFromPreferencesIfRequired()
this.switchFragment(PlayerFragment())
}

Expand All @@ -383,6 +402,24 @@ class AudioBookPlayerActivity2 : AppCompatActivity(R.layout.audio_book_player_ba
}
}

private fun setPlaybackRateFromPreferencesIfRequired() {
val bookParameters =
AudioBookViewerModel.parameters ?: return
val preferencesRate =
this.profiles.profileCurrent()
.preferences()
.playbackRates
.get(bookParameters.bookID.value())

if (preferencesRate == null) {
return
}

if (preferencesRate != PlayerModel.playbackRate) {
PlayerModel.setPlaybackRate(preferencesRate)
}
}

private fun assignBookmarks(
bookmarks: BookmarksForBook
): PlayerBookmark? {
Expand Down

0 comments on commit 39ef59e

Please sign in to comment.