From 9e7d1cfe2967d4cde7a4152c96a8068ff586d1f0 Mon Sep 17 00:00:00 2001 From: Antoine POPINEAU Date: Tue, 22 Oct 2019 20:03:52 +0200 Subject: [PATCH] Added missing ripple effects. Fixed padding around list items. Moved event buses into Application object. --- .../java/com/github/apognu/otter/Otter.kt | 19 ++++++++++++++ .../apognu/otter/playback/PlayerService.kt | 2 +- .../com/github/apognu/otter/utils/EventBus.kt | 25 +++++++------------ app/src/main/res/layout/row_album.xml | 8 +++--- app/src/main/res/layout/row_artist.xml | 8 +++--- app/src/main/res/layout/row_playlist.xml | 8 +++--- app/src/main/res/layout/row_track.xml | 8 +++--- app/src/main/res/values/styles.xml | 1 + 8 files changed, 46 insertions(+), 33 deletions(-) diff --git a/app/src/main/java/com/github/apognu/otter/Otter.kt b/app/src/main/java/com/github/apognu/otter/Otter.kt index 4632159..b0317d3 100644 --- a/app/src/main/java/com/github/apognu/otter/Otter.kt +++ b/app/src/main/java/com/github/apognu/otter/Otter.kt @@ -2,12 +2,31 @@ package com.github.apognu.otter import android.app.Application import androidx.appcompat.app.AppCompatDelegate +import com.github.apognu.otter.utils.Command +import com.github.apognu.otter.utils.Event +import com.github.apognu.otter.utils.Request import com.preference.PowerPreference +import kotlinx.coroutines.channels.BroadcastChannel +import kotlinx.coroutines.channels.Channel +import kotlinx.coroutines.channels.ConflatedBroadcastChannel class Otter : Application() { + companion object { + private var instance: Otter = Otter() + + fun get(): Otter = instance + } + + var eventBus: BroadcastChannel = BroadcastChannel(10) + val commandBus: Channel = Channel(10) + val requestBus: BroadcastChannel = BroadcastChannel(10) + val progressBus: BroadcastChannel> = ConflatedBroadcastChannel() + override fun onCreate() { super.onCreate() + instance = this + when (PowerPreference.getDefaultFile().getString("night_mode")) { "on" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES) "off" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO) diff --git a/app/src/main/java/com/github/apognu/otter/playback/PlayerService.kt b/app/src/main/java/com/github/apognu/otter/playback/PlayerService.kt index 2a47582..bd8b60e 100644 --- a/app/src/main/java/com/github/apognu/otter/playback/PlayerService.kt +++ b/app/src/main/java/com/github/apognu/otter/playback/PlayerService.kt @@ -113,7 +113,7 @@ class PlayerService : Service() { private fun watchEventBus() { jobs.add(GlobalScope.launch(Main) { - for (message in CommandBus.asChannel()) { + for (message in CommandBus.get()) { when (message) { is Command.RefreshService -> { EventBus.send(Event.QueueChanged) diff --git a/app/src/main/java/com/github/apognu/otter/utils/EventBus.kt b/app/src/main/java/com/github/apognu/otter/utils/EventBus.kt index 19201cc..87695d0 100644 --- a/app/src/main/java/com/github/apognu/otter/utils/EventBus.kt +++ b/app/src/main/java/com/github/apognu/otter/utils/EventBus.kt @@ -1,5 +1,6 @@ package com.github.apognu.otter.utils +import com.github.apognu.otter.Otter import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.channels.* @@ -48,15 +49,13 @@ sealed class Response { } object EventBus { - private var bus: BroadcastChannel = BroadcastChannel(10) - fun send(event: Event) { GlobalScope.launch { - bus.offer(event) + get().offer(event) } } - fun get() = bus + fun get() = Otter.get().eventBus inline fun asChannel(): ReceiveChannel { return get().openSubscription().filter { it is T }.map { it as T } @@ -64,31 +63,27 @@ object EventBus { } object CommandBus { - private var bus: Channel = Channel(10) - fun send(command: Command) { GlobalScope.launch { - bus.offer(command) + get().offer(command) } } - fun asChannel() = bus + fun get() = Otter.get().commandBus } object RequestBus { - private var bus: BroadcastChannel = BroadcastChannel(10) - fun send(request: Request): Channel { return Channel().also { GlobalScope.launch(Main) { request.channel = it - bus.offer(request) + get().offer(request) } } } - fun get() = bus + fun get() = Otter.get().requestBus inline fun asChannel(): ReceiveChannel { return get().openSubscription().filter { it is T }.map { it as T } @@ -96,16 +91,14 @@ object RequestBus { } object ProgressBus { - private val bus: BroadcastChannel> = ConflatedBroadcastChannel() - fun send(current: Int, duration: Int, percent: Int) { GlobalScope.launch { - bus.send(Triple(current, duration, percent)) + Otter.get().progressBus.send(Triple(current, duration, percent)) } } fun asChannel(): ReceiveChannel> { - return bus.openSubscription() + return Otter.get().progressBus.openSubscription() } } diff --git a/app/src/main/res/layout/row_album.xml b/app/src/main/res/layout/row_album.xml index 01ca7c1..9443687 100644 --- a/app/src/main/res/layout/row_album.xml +++ b/app/src/main/res/layout/row_album.xml @@ -3,13 +3,13 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginStart="16dp" - android:layout_marginTop="12dp" - android:layout_marginEnd="16dp" - android:layout_marginBottom="12dp" android:background="?android:attr/selectableItemBackground" android:gravity="center_vertical" android:orientation="horizontal" + android:paddingStart="16dp" + android:paddingTop="12dp" + android:paddingEnd="16dp" + android:paddingBottom="12dp" android:transitionGroup="true" tools:showIn="@layout/fragment_albums"> diff --git a/app/src/main/res/layout/row_artist.xml b/app/src/main/res/layout/row_artist.xml index 16cf2f1..3a66147 100644 --- a/app/src/main/res/layout/row_artist.xml +++ b/app/src/main/res/layout/row_artist.xml @@ -3,13 +3,13 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginStart="16dp" - android:layout_marginTop="12dp" - android:layout_marginEnd="16dp" - android:layout_marginBottom="12dp" android:background="?android:attr/selectableItemBackground" android:gravity="center_vertical" android:orientation="horizontal" + android:paddingStart="16dp" + android:paddingTop="12dp" + android:paddingEnd="16dp" + android:paddingBottom="12dp" android:transitionGroup="true" tools:showIn="@layout/fragment_artists"> diff --git a/app/src/main/res/layout/row_playlist.xml b/app/src/main/res/layout/row_playlist.xml index 70fd08c..f73a0fc 100644 --- a/app/src/main/res/layout/row_playlist.xml +++ b/app/src/main/res/layout/row_playlist.xml @@ -4,12 +4,12 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginStart="16dp" - android:layout_marginTop="12dp" - android:layout_marginEnd="16dp" - android:layout_marginBottom="12dp" android:background="?android:attr/selectableItemBackground" android:gravity="center_vertical" + android:paddingStart="16dp" + android:paddingTop="12dp" + android:paddingEnd="16dp" + android:paddingBottom="12dp" android:transitionGroup="true" tools:showIn="@layout/fragment_playlists"> diff --git a/app/src/main/res/layout/row_track.xml b/app/src/main/res/layout/row_track.xml index 7bb6177..c2045a9 100644 --- a/app/src/main/res/layout/row_track.xml +++ b/app/src/main/res/layout/row_track.xml @@ -6,10 +6,10 @@ android:background="?android:attr/selectableItemBackground" android:gravity="center_vertical" android:orientation="horizontal" - android:layout_marginStart="16dp" - android:layout_marginTop="12dp" - android:layout_marginEnd="16dp" - android:layout_marginBottom="12dp" + android:paddingStart="16dp" + android:paddingTop="12dp" + android:paddingEnd="16dp" + android:paddingBottom="12dp" android:transitionGroup="true" tools:showIn="@layout/fragment_tracks"> diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index d4c1a75..fa2b4c7 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -37,6 +37,7 @@