Added missing ripple effects. Fixed padding around list items. Moved event buses into Application object.
This commit is contained in:
parent
68e5f7e1d1
commit
9e7d1cfe29
|
@ -2,12 +2,31 @@ package com.github.apognu.otter
|
||||||
|
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
import androidx.appcompat.app.AppCompatDelegate
|
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 com.preference.PowerPreference
|
||||||
|
import kotlinx.coroutines.channels.BroadcastChannel
|
||||||
|
import kotlinx.coroutines.channels.Channel
|
||||||
|
import kotlinx.coroutines.channels.ConflatedBroadcastChannel
|
||||||
|
|
||||||
class Otter : Application() {
|
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() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
|
|
||||||
|
instance = this
|
||||||
|
|
||||||
when (PowerPreference.getDefaultFile().getString("night_mode")) {
|
when (PowerPreference.getDefaultFile().getString("night_mode")) {
|
||||||
"on" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
|
"on" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
|
||||||
"off" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
|
"off" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
|
||||||
|
|
|
@ -113,7 +113,7 @@ class PlayerService : Service() {
|
||||||
|
|
||||||
private fun watchEventBus() {
|
private fun watchEventBus() {
|
||||||
jobs.add(GlobalScope.launch(Main) {
|
jobs.add(GlobalScope.launch(Main) {
|
||||||
for (message in CommandBus.asChannel()) {
|
for (message in CommandBus.get()) {
|
||||||
when (message) {
|
when (message) {
|
||||||
is Command.RefreshService -> {
|
is Command.RefreshService -> {
|
||||||
EventBus.send(Event.QueueChanged)
|
EventBus.send(Event.QueueChanged)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.github.apognu.otter.utils
|
package com.github.apognu.otter.utils
|
||||||
|
|
||||||
|
import com.github.apognu.otter.Otter
|
||||||
import kotlinx.coroutines.Dispatchers.Main
|
import kotlinx.coroutines.Dispatchers.Main
|
||||||
import kotlinx.coroutines.GlobalScope
|
import kotlinx.coroutines.GlobalScope
|
||||||
import kotlinx.coroutines.channels.*
|
import kotlinx.coroutines.channels.*
|
||||||
|
@ -48,15 +49,13 @@ sealed class Response {
|
||||||
}
|
}
|
||||||
|
|
||||||
object EventBus {
|
object EventBus {
|
||||||
private var bus: BroadcastChannel<Event> = BroadcastChannel(10)
|
|
||||||
|
|
||||||
fun send(event: Event) {
|
fun send(event: Event) {
|
||||||
GlobalScope.launch {
|
GlobalScope.launch {
|
||||||
bus.offer(event)
|
get().offer(event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun get() = bus
|
fun get() = Otter.get().eventBus
|
||||||
|
|
||||||
inline fun <reified T : Event> asChannel(): ReceiveChannel<T> {
|
inline fun <reified T : Event> asChannel(): ReceiveChannel<T> {
|
||||||
return get().openSubscription().filter { it is T }.map { it as T }
|
return get().openSubscription().filter { it is T }.map { it as T }
|
||||||
|
@ -64,31 +63,27 @@ object EventBus {
|
||||||
}
|
}
|
||||||
|
|
||||||
object CommandBus {
|
object CommandBus {
|
||||||
private var bus: Channel<Command> = Channel(10)
|
|
||||||
|
|
||||||
fun send(command: Command) {
|
fun send(command: Command) {
|
||||||
GlobalScope.launch {
|
GlobalScope.launch {
|
||||||
bus.offer(command)
|
get().offer(command)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun asChannel() = bus
|
fun get() = Otter.get().commandBus
|
||||||
}
|
}
|
||||||
|
|
||||||
object RequestBus {
|
object RequestBus {
|
||||||
private var bus: BroadcastChannel<Request> = BroadcastChannel(10)
|
|
||||||
|
|
||||||
fun send(request: Request): Channel<Response> {
|
fun send(request: Request): Channel<Response> {
|
||||||
return Channel<Response>().also {
|
return Channel<Response>().also {
|
||||||
GlobalScope.launch(Main) {
|
GlobalScope.launch(Main) {
|
||||||
request.channel = it
|
request.channel = it
|
||||||
|
|
||||||
bus.offer(request)
|
get().offer(request)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun get() = bus
|
fun get() = Otter.get().requestBus
|
||||||
|
|
||||||
inline fun <reified T> asChannel(): ReceiveChannel<T> {
|
inline fun <reified T> asChannel(): ReceiveChannel<T> {
|
||||||
return get().openSubscription().filter { it is T }.map { it as T }
|
return get().openSubscription().filter { it is T }.map { it as T }
|
||||||
|
@ -96,16 +91,14 @@ object RequestBus {
|
||||||
}
|
}
|
||||||
|
|
||||||
object ProgressBus {
|
object ProgressBus {
|
||||||
private val bus: BroadcastChannel<Triple<Int, Int, Int>> = ConflatedBroadcastChannel()
|
|
||||||
|
|
||||||
fun send(current: Int, duration: Int, percent: Int) {
|
fun send(current: Int, duration: Int, percent: Int) {
|
||||||
GlobalScope.launch {
|
GlobalScope.launch {
|
||||||
bus.send(Triple(current, duration, percent))
|
Otter.get().progressBus.send(Triple(current, duration, percent))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun asChannel(): ReceiveChannel<Triple<Int, Int, Int>> {
|
fun asChannel(): ReceiveChannel<Triple<Int, Int, Int>> {
|
||||||
return bus.openSubscription()
|
return Otter.get().progressBus.openSubscription()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,13 +3,13 @@
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
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:background="?android:attr/selectableItemBackground"
|
||||||
android:gravity="center_vertical"
|
android:gravity="center_vertical"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
|
android:paddingStart="16dp"
|
||||||
|
android:paddingTop="12dp"
|
||||||
|
android:paddingEnd="16dp"
|
||||||
|
android:paddingBottom="12dp"
|
||||||
android:transitionGroup="true"
|
android:transitionGroup="true"
|
||||||
tools:showIn="@layout/fragment_albums">
|
tools:showIn="@layout/fragment_albums">
|
||||||
|
|
||||||
|
|
|
@ -3,13 +3,13 @@
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
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:background="?android:attr/selectableItemBackground"
|
||||||
android:gravity="center_vertical"
|
android:gravity="center_vertical"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
|
android:paddingStart="16dp"
|
||||||
|
android:paddingTop="12dp"
|
||||||
|
android:paddingEnd="16dp"
|
||||||
|
android:paddingBottom="12dp"
|
||||||
android:transitionGroup="true"
|
android:transitionGroup="true"
|
||||||
tools:showIn="@layout/fragment_artists">
|
tools:showIn="@layout/fragment_artists">
|
||||||
|
|
||||||
|
|
|
@ -4,12 +4,12 @@
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
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:background="?android:attr/selectableItemBackground"
|
||||||
android:gravity="center_vertical"
|
android:gravity="center_vertical"
|
||||||
|
android:paddingStart="16dp"
|
||||||
|
android:paddingTop="12dp"
|
||||||
|
android:paddingEnd="16dp"
|
||||||
|
android:paddingBottom="12dp"
|
||||||
android:transitionGroup="true"
|
android:transitionGroup="true"
|
||||||
tools:showIn="@layout/fragment_playlists">
|
tools:showIn="@layout/fragment_playlists">
|
||||||
|
|
||||||
|
|
|
@ -6,10 +6,10 @@
|
||||||
android:background="?android:attr/selectableItemBackground"
|
android:background="?android:attr/selectableItemBackground"
|
||||||
android:gravity="center_vertical"
|
android:gravity="center_vertical"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:layout_marginStart="16dp"
|
android:paddingStart="16dp"
|
||||||
android:layout_marginTop="12dp"
|
android:paddingTop="12dp"
|
||||||
android:layout_marginEnd="16dp"
|
android:paddingEnd="16dp"
|
||||||
android:layout_marginBottom="12dp"
|
android:paddingBottom="12dp"
|
||||||
android:transitionGroup="true"
|
android:transitionGroup="true"
|
||||||
tools:showIn="@layout/fragment_tracks">
|
tools:showIn="@layout/fragment_tracks">
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="AppTheme.OutlinedButton" parent="Widget.MaterialComponents.Button.OutlinedButton">
|
<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="android:textColor">@color/controlForeground</item>
|
||||||
<item name="iconTint">@color/controlForeground</item>
|
<item name="iconTint">@color/controlForeground</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
Loading…
Reference in New Issue