widgets: respond to settings changes

Make it so that widgets respond to settings changes, such as
cover configuration.
This commit is contained in:
OxygenCobalt 2021-08-03 12:22:46 -06:00
parent 2abc91674b
commit 5d7d86b17e
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
3 changed files with 37 additions and 3 deletions

View file

@ -110,7 +110,7 @@ dependencies {
task ktlint(type: JavaExec, group: "verification") {
description = "Check Kotlin code style."
mainClass = "com.pinterest.ktlint.Main"
mainClass.set("com.pinterest.ktlint.Main")
classpath = configurations.ktlint
args "src/**/*.kt"
@ -119,7 +119,7 @@ check.dependsOn ktlint
task ktlintFormat(type: JavaExec, group: "formatting") {
description = "Fix Kotlin code style deviations."
mainClass = "com.pinterest.ktlint.Main"
mainClass.set("com.pinterest.ktlint.Main")
classpath = configurations.ktlint
args "-F", "src/**/*.kt"

View file

@ -16,6 +16,9 @@ import java.lang.reflect.Field
* views when animated with a stock LayoutTransition. If something breaks on the playback controls
* or nav bar, this is probably the culprit.
*
* "But oxygencobalt, couldn't you just write your own animation code and run that instea-"
* **NO.**
*
* Adapted from this StackOverflow answer:
* https://stackoverflow.com/a/35087229
* @author OxygenCobalt

View file

@ -4,15 +4,27 @@ import android.content.Context
import org.oxycblt.auxio.logD
import org.oxycblt.auxio.music.Song
import org.oxycblt.auxio.playback.state.PlaybackStateManager
import org.oxycblt.auxio.settings.SettingsManager
class WidgetController(private val context: Context) : PlaybackStateManager.Callback {
/**
* A wrapper around each widget subclass that manages which updates to deliver from the
* main process's [PlaybackStateManager] and [SettingsManager] instances to the widgets themselves.
*/
class WidgetController(private val context: Context) :
PlaybackStateManager.Callback,
SettingsManager.Callback {
private val playbackManager = PlaybackStateManager.getInstance()
private val settingsManager = SettingsManager.getInstance()
private val minimal = MinimalWidgetProvider()
init {
playbackManager.addCallback(this)
settingsManager.addCallback(this)
}
/*
* Initialize a newly added widget. This usually comes from the WIDGET_UPDATE intent.
*/
fun initWidget(type: Int) {
logD("Updating new widget $type")
@ -21,19 +33,28 @@ class WidgetController(private val context: Context) : PlaybackStateManager.Call
}
}
/*
* Update every widget, regardless of whether it needs to or not.
*/
fun update() {
logD("Updating all widgets")
minimal.update(context, playbackManager)
}
/*
* Release this instance, removing the callbacks and resetting all widgets
*/
fun release() {
logD("Resetting widgets")
minimal.reset(context)
playbackManager.removeCallback(this)
settingsManager.removeCallback(this)
}
// --- PLAYBACKSTATEMANAGER CALLBACKS ---
override fun onSongUpdate(song: Song?) {
minimal.update(context, playbackManager)
}
@ -41,4 +62,14 @@ class WidgetController(private val context: Context) : PlaybackStateManager.Call
override fun onPlayingUpdate(isPlaying: Boolean) {
minimal.update(context, playbackManager)
}
// --- SETTINGSMANAGER CALLBACKS ---
override fun onShowCoverUpdate(showCovers: Boolean) {
minimal.update(context, playbackManager)
}
override fun onQualityCoverUpdate(doQualityCovers: Boolean) {
minimal.update(context, playbackManager)
}
}