launch restore on Main Thread
This commit is contained in:
parent
81d24f6cbb
commit
647435fe55
|
@ -136,6 +136,7 @@ class NowPlayingFragment : Fragment() {
|
||||||
.navigate(R.id.trackCollectionFragment, bundle)
|
.navigate(R.id.trackCollectionFragment, bundle)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
requireView().setOnTouchListener { _: View?, event: MotionEvent ->
|
requireView().setOnTouchListener { _: View?, event: MotionEvent ->
|
||||||
handleOnTouch(event)
|
handleOnTouch(event)
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,13 +7,10 @@
|
||||||
|
|
||||||
package org.moire.ultrasonic.service
|
package org.moire.ultrasonic.service
|
||||||
|
|
||||||
import android.content.BroadcastReceiver
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.view.KeyEvent
|
import android.view.KeyEvent
|
||||||
import io.reactivex.rxjava3.disposables.Disposable
|
|
||||||
import org.koin.core.component.KoinComponent
|
import org.koin.core.component.KoinComponent
|
||||||
import org.koin.core.component.inject
|
import org.koin.core.component.inject
|
||||||
import org.moire.ultrasonic.app.UApp.Companion.applicationContext
|
|
||||||
import org.moire.ultrasonic.util.CacheCleaner
|
import org.moire.ultrasonic.util.CacheCleaner
|
||||||
import org.moire.ultrasonic.util.Constants
|
import org.moire.ultrasonic.util.Constants
|
||||||
import org.moire.ultrasonic.util.Util.ifNotNull
|
import org.moire.ultrasonic.util.Util.ifNotNull
|
||||||
|
|
|
@ -33,7 +33,8 @@ class PlaybackStateSerializer : KoinComponent {
|
||||||
private val lock: Lock = ReentrantLock()
|
private val lock: Lock = ReentrantLock()
|
||||||
private val setup = AtomicBoolean(false)
|
private val setup = AtomicBoolean(false)
|
||||||
|
|
||||||
private val appScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
|
private val ioScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
|
||||||
|
private val mainScope = CoroutineScope(SupervisorJob() + Dispatchers.Main)
|
||||||
|
|
||||||
fun serialize(
|
fun serialize(
|
||||||
songs: Iterable<DownloadFile>,
|
songs: Iterable<DownloadFile>,
|
||||||
|
@ -42,7 +43,7 @@ class PlaybackStateSerializer : KoinComponent {
|
||||||
) {
|
) {
|
||||||
if (!setup.get()) return
|
if (!setup.get()) return
|
||||||
|
|
||||||
appScope.launch {
|
ioScope.launch {
|
||||||
if (lock.tryLock()) {
|
if (lock.tryLock()) {
|
||||||
try {
|
try {
|
||||||
serializeNow(songs, currentPlayingIndex, currentPlayingPosition)
|
serializeNow(songs, currentPlayingIndex, currentPlayingPosition)
|
||||||
|
@ -78,7 +79,7 @@ class PlaybackStateSerializer : KoinComponent {
|
||||||
|
|
||||||
fun deserialize(afterDeserialized: (State?) -> Unit?) {
|
fun deserialize(afterDeserialized: (State?) -> Unit?) {
|
||||||
|
|
||||||
appScope.launch {
|
ioScope.launch {
|
||||||
try {
|
try {
|
||||||
lock.lock()
|
lock.lock()
|
||||||
deserializeNow(afterDeserialized)
|
deserializeNow(afterDeserialized)
|
||||||
|
@ -103,6 +104,8 @@ class PlaybackStateSerializer : KoinComponent {
|
||||||
state.currentPlayingPosition
|
state.currentPlayingPosition
|
||||||
)
|
)
|
||||||
|
|
||||||
afterDeserialized(state)
|
mainScope.launch {
|
||||||
|
afterDeserialized(state)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue