launch restore on Main Thread

This commit is contained in:
tzugen 2022-04-20 20:57:51 +02:00
parent 81d24f6cbb
commit 647435fe55
No known key found for this signature in database
GPG Key ID: 61E9C34BC10EC930
3 changed files with 8 additions and 7 deletions

View File

@ -136,6 +136,7 @@ class NowPlayingFragment : Fragment() {
.navigate(R.id.trackCollectionFragment, bundle)
}
}
requireView().setOnTouchListener { _: View?, event: MotionEvent ->
handleOnTouch(event)
}

View File

@ -7,13 +7,10 @@
package org.moire.ultrasonic.service
import android.content.BroadcastReceiver
import android.content.Intent
import android.view.KeyEvent
import io.reactivex.rxjava3.disposables.Disposable
import org.koin.core.component.KoinComponent
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.Constants
import org.moire.ultrasonic.util.Util.ifNotNull

View File

@ -33,7 +33,8 @@ class PlaybackStateSerializer : KoinComponent {
private val lock: Lock = ReentrantLock()
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(
songs: Iterable<DownloadFile>,
@ -42,7 +43,7 @@ class PlaybackStateSerializer : KoinComponent {
) {
if (!setup.get()) return
appScope.launch {
ioScope.launch {
if (lock.tryLock()) {
try {
serializeNow(songs, currentPlayingIndex, currentPlayingPosition)
@ -78,7 +79,7 @@ class PlaybackStateSerializer : KoinComponent {
fun deserialize(afterDeserialized: (State?) -> Unit?) {
appScope.launch {
ioScope.launch {
try {
lock.lock()
deserializeNow(afterDeserialized)
@ -103,6 +104,8 @@ class PlaybackStateSerializer : KoinComponent {
state.currentPlayingPosition
)
afterDeserialized(state)
mainScope.launch {
afterDeserialized(state)
}
}
}