widgets: respond to settings changes
Make it so that widgets respond to settings changes, such as cover configuration.
This commit is contained in:
parent
2abc91674b
commit
5d7d86b17e
3 changed files with 37 additions and 3 deletions
|
@ -110,7 +110,7 @@ dependencies {
|
||||||
|
|
||||||
task ktlint(type: JavaExec, group: "verification") {
|
task ktlint(type: JavaExec, group: "verification") {
|
||||||
description = "Check Kotlin code style."
|
description = "Check Kotlin code style."
|
||||||
mainClass = "com.pinterest.ktlint.Main"
|
mainClass.set("com.pinterest.ktlint.Main")
|
||||||
classpath = configurations.ktlint
|
classpath = configurations.ktlint
|
||||||
|
|
||||||
args "src/**/*.kt"
|
args "src/**/*.kt"
|
||||||
|
@ -119,7 +119,7 @@ check.dependsOn ktlint
|
||||||
|
|
||||||
task ktlintFormat(type: JavaExec, group: "formatting") {
|
task ktlintFormat(type: JavaExec, group: "formatting") {
|
||||||
description = "Fix Kotlin code style deviations."
|
description = "Fix Kotlin code style deviations."
|
||||||
mainClass = "com.pinterest.ktlint.Main"
|
mainClass.set("com.pinterest.ktlint.Main")
|
||||||
classpath = configurations.ktlint
|
classpath = configurations.ktlint
|
||||||
|
|
||||||
args "-F", "src/**/*.kt"
|
args "-F", "src/**/*.kt"
|
||||||
|
|
|
@ -16,6 +16,9 @@ import java.lang.reflect.Field
|
||||||
* views when animated with a stock LayoutTransition. If something breaks on the playback controls
|
* views when animated with a stock LayoutTransition. If something breaks on the playback controls
|
||||||
* or nav bar, this is probably the culprit.
|
* 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:
|
* Adapted from this StackOverflow answer:
|
||||||
* https://stackoverflow.com/a/35087229
|
* https://stackoverflow.com/a/35087229
|
||||||
* @author OxygenCobalt
|
* @author OxygenCobalt
|
||||||
|
|
|
@ -4,15 +4,27 @@ import android.content.Context
|
||||||
import org.oxycblt.auxio.logD
|
import org.oxycblt.auxio.logD
|
||||||
import org.oxycblt.auxio.music.Song
|
import org.oxycblt.auxio.music.Song
|
||||||
import org.oxycblt.auxio.playback.state.PlaybackStateManager
|
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 playbackManager = PlaybackStateManager.getInstance()
|
||||||
|
private val settingsManager = SettingsManager.getInstance()
|
||||||
private val minimal = MinimalWidgetProvider()
|
private val minimal = MinimalWidgetProvider()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
playbackManager.addCallback(this)
|
playbackManager.addCallback(this)
|
||||||
|
settingsManager.addCallback(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Initialize a newly added widget. This usually comes from the WIDGET_UPDATE intent.
|
||||||
|
*/
|
||||||
fun initWidget(type: Int) {
|
fun initWidget(type: Int) {
|
||||||
logD("Updating new widget $type")
|
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() {
|
fun update() {
|
||||||
logD("Updating all widgets")
|
logD("Updating all widgets")
|
||||||
|
|
||||||
minimal.update(context, playbackManager)
|
minimal.update(context, playbackManager)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Release this instance, removing the callbacks and resetting all widgets
|
||||||
|
*/
|
||||||
fun release() {
|
fun release() {
|
||||||
logD("Resetting widgets")
|
logD("Resetting widgets")
|
||||||
|
|
||||||
minimal.reset(context)
|
minimal.reset(context)
|
||||||
playbackManager.removeCallback(this)
|
playbackManager.removeCallback(this)
|
||||||
|
settingsManager.removeCallback(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --- PLAYBACKSTATEMANAGER CALLBACKS ---
|
||||||
|
|
||||||
override fun onSongUpdate(song: Song?) {
|
override fun onSongUpdate(song: Song?) {
|
||||||
minimal.update(context, playbackManager)
|
minimal.update(context, playbackManager)
|
||||||
}
|
}
|
||||||
|
@ -41,4 +62,14 @@ class WidgetController(private val context: Context) : PlaybackStateManager.Call
|
||||||
override fun onPlayingUpdate(isPlaying: Boolean) {
|
override fun onPlayingUpdate(isPlaying: Boolean) {
|
||||||
minimal.update(context, playbackManager)
|
minimal.update(context, playbackManager)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --- SETTINGSMANAGER CALLBACKS ---
|
||||||
|
|
||||||
|
override fun onShowCoverUpdate(showCovers: Boolean) {
|
||||||
|
minimal.update(context, playbackManager)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onQualityCoverUpdate(doQualityCovers: Boolean) {
|
||||||
|
minimal.update(context, playbackManager)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue