Added missing ripple effects. Fixed padding around list items. Moved event buses into Application object.

This commit is contained in:
Antoine POPINEAU 2019-10-22 20:03:52 +02:00
parent 68e5f7e1d1
commit 9e7d1cfe29
No known key found for this signature in database
GPG Key ID: A78AC64694F84063
8 changed files with 46 additions and 33 deletions

View File

@ -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<Event> = BroadcastChannel(10)
val commandBus: Channel<Command> = Channel(10)
val requestBus: BroadcastChannel<Request> = BroadcastChannel(10)
val progressBus: BroadcastChannel<Triple<Int, Int, Int>> = 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)

View File

@ -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)

View File

@ -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<Event> = BroadcastChannel(10)
fun send(event: Event) {
GlobalScope.launch {
bus.offer(event)
get().offer(event)
}
}
fun get() = bus
fun get() = Otter.get().eventBus
inline fun <reified T : Event> asChannel(): ReceiveChannel<T> {
return get().openSubscription().filter { it is T }.map { it as T }
@ -64,31 +63,27 @@ object EventBus {
}
object CommandBus {
private var bus: Channel<Command> = 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<Request> = BroadcastChannel(10)
fun send(request: Request): Channel<Response> {
return Channel<Response>().also {
GlobalScope.launch(Main) {
request.channel = it
bus.offer(request)
get().offer(request)
}
}
}
fun get() = bus
fun get() = Otter.get().requestBus
inline fun <reified T> asChannel(): ReceiveChannel<T> {
return get().openSubscription().filter { it is T }.map { it as T }
@ -96,16 +91,14 @@ object RequestBus {
}
object ProgressBus {
private val bus: BroadcastChannel<Triple<Int, Int, Int>> = 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<Triple<Int, Int, Int>> {
return bus.openSubscription()
return Otter.get().progressBus.openSubscription()
}
}

View File

@ -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">

View File

@ -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">

View File

@ -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">

View File

@ -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">

View File

@ -37,6 +37,7 @@
</style>
<style name="AppTheme.OutlinedButton" parent="Widget.MaterialComponents.Button.OutlinedButton">
<item name="rippleColor">@android:color/darker_gray</item>
<item name="android:textColor">@color/controlForeground</item>
<item name="iconTint">@color/controlForeground</item>
</style>