Browse Source

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

housekeeping/remove-warnings
Antoine POPINEAU 5 years ago
parent
commit
9e7d1cfe29
No known key found for this signature in database
GPG Key ID: A78AC64694F84063
  1. 19
      app/src/main/java/com/github/apognu/otter/Otter.kt
  2. 2
      app/src/main/java/com/github/apognu/otter/playback/PlayerService.kt
  3. 25
      app/src/main/java/com/github/apognu/otter/utils/EventBus.kt
  4. 8
      app/src/main/res/layout/row_album.xml
  5. 8
      app/src/main/res/layout/row_artist.xml
  6. 8
      app/src/main/res/layout/row_playlist.xml
  7. 8
      app/src/main/res/layout/row_track.xml
  8. 1
      app/src/main/res/values/styles.xml

19
app/src/main/java/com/github/apognu/otter/Otter.kt

@ -2,12 +2,31 @@ package com.github.apognu.otter @@ -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)

2
app/src/main/java/com/github/apognu/otter/playback/PlayerService.kt

@ -113,7 +113,7 @@ class PlayerService : Service() { @@ -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)

25
app/src/main/java/com/github/apognu/otter/utils/EventBus.kt

@ -1,5 +1,6 @@ @@ -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 { @@ -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 { @@ -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 { @@ -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()
}
}

8
app/src/main/res/layout/row_album.xml

@ -3,13 +3,13 @@ @@ -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">

8
app/src/main/res/layout/row_artist.xml

@ -3,13 +3,13 @@ @@ -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">

8
app/src/main/res/layout/row_playlist.xml

@ -4,12 +4,12 @@ @@ -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">

8
app/src/main/res/layout/row_track.xml

@ -6,10 +6,10 @@ @@ -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">

1
app/src/main/res/values/styles.xml

@ -37,6 +37,7 @@ @@ -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>

Loading…
Cancel
Save