Skip to content

Instantly share code, notes, and snippets.

...
private val prefsListener = SharedPreferences.OnSharedPreferenceChangeListener { _, key ->
when (key) {
PrefsRepo.KEY_SKIP_SILENCE, PrefsRepo.KEY_PLAYBACK_SPEED -> {
invalidatePlaybackParams()
}
PrefsRepo.KEY_PAUSE_ON_FOCUS_LOST -> {
updateAudioAttrs(exoPlayer)
}
// \/ \/ Add below \/ \/
@mattttvaughn
mattttvaughn / CurrentlyPlayingViewModel.kt
Created March 23, 2022 00:03
Updating skip forwards/backwards icons in currently playing
private var _jumpForwardsIcon = MutableLiveData(makeJumpForwardsIcon())
val jumpForwardsIcon: LiveData<Int>
get() = _jumpForwardsIcon
private var _jumpBackwardsIcon = MutableLiveData(makeJumpBackwardsIcon())
val jumpBackwardsIcon: LiveData<Int>
get() = _jumpBackwardsIcon
// this listener already exists, just add the KEY_JUMP lines
private val prefsChangeListener = SharedPreferences.OnSharedPreferenceChangeListener { _, key ->
@mattttvaughn
mattttvaughn / TitleSortComparator.kt
Created February 23, 2022 01:43
Sample tests for TitleSortComparator
package io.github.mattpvaughn.chronicle.features.library
// src/main/java/io/github/mattpvaughn/chronicle/features/library/TitleSortComparator.kt
/** Compares Book titles using numerical ordering */
class TitleSortComparator {
fun compare(bookTitle1: String, bookTitle2: String): Int {
fun titleToArray(bookTitle: String): List<String> {
return bookTitle.split(Regex("(?<=\\D)(?=\\d)|(?<=\\d)(?=\\D)"))