Skip to content

Commit

Permalink
More tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
theothernt committed Jul 16, 2024
1 parent e1a3bd5 commit 1be9620
Showing 1 changed file with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,8 @@ class TextNowPlaying : AppCompatTextView {

override fun onAttachedToWindow() {
super.onAttachedToWindow()

coroutineScope.launch {
receiver.subscribe<MusicEvent> {
animate().alpha(0f).setDuration(300)
delay(300)
text = formatNowPlaying(it)
animate().alpha(1f).setDuration(300)
}
receiver.subscribe<MusicEvent> {
updateNowPlaying(it)
}
}

Expand All @@ -54,6 +48,13 @@ class TextNowPlaying : AppCompatTextView {
coroutineScope.cancel()
}

private fun updateNowPlaying(trackInfo: MusicEvent) = coroutineScope.launch {
animate().alpha(0f).setDuration(300)
delay(300)
text = formatNowPlaying(trackInfo)
animate().alpha(1f).setDuration(300)
}

private fun formatNowPlaying(trackInfo: MusicEvent): String {
val (artist, song) = trackInfo
return when (format) {
Expand Down

0 comments on commit 1be9620

Please sign in to comment.