Use MainThreadExecutor
This commit is contained in:
parent
37e3ce09c1
commit
fefee74a66
|
@ -10,6 +10,7 @@ import android.content.ComponentName
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
|
import android.widget.Toast
|
||||||
import androidx.core.net.toUri
|
import androidx.core.net.toUri
|
||||||
import androidx.media3.common.HeartRating
|
import androidx.media3.common.HeartRating
|
||||||
import androidx.media3.common.MediaItem
|
import androidx.media3.common.MediaItem
|
||||||
|
@ -39,6 +40,7 @@ import org.moire.ultrasonic.provider.UltrasonicAppWidgetProvider4X3
|
||||||
import org.moire.ultrasonic.provider.UltrasonicAppWidgetProvider4X4
|
import org.moire.ultrasonic.provider.UltrasonicAppWidgetProvider4X4
|
||||||
import org.moire.ultrasonic.service.MusicServiceFactory.getMusicService
|
import org.moire.ultrasonic.service.MusicServiceFactory.getMusicService
|
||||||
import org.moire.ultrasonic.util.FileUtil
|
import org.moire.ultrasonic.util.FileUtil
|
||||||
|
import org.moire.ultrasonic.util.MainThreadExecutor
|
||||||
import org.moire.ultrasonic.util.Settings
|
import org.moire.ultrasonic.util.Settings
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
|
@ -584,33 +586,29 @@ class MediaPlayerController(
|
||||||
if (legacyPlaylistManager.currentPlaying == null) return
|
if (legacyPlaylistManager.currentPlaying == null) return
|
||||||
val song = legacyPlaylistManager.currentPlaying!!.track
|
val song = legacyPlaylistManager.currentPlaying!!.track
|
||||||
|
|
||||||
fun updateStarred() {
|
|
||||||
// Trigger an update
|
|
||||||
// TODO Update Metadata of MediaItem...
|
|
||||||
// localMediaPlayer.setCurrentPlaying(localMediaPlayer.currentPlaying)
|
|
||||||
song.starred = !song.starred
|
|
||||||
}
|
|
||||||
|
|
||||||
controller?.setRating(
|
controller?.setRating(
|
||||||
HeartRating(!song.starred)
|
HeartRating(!song.starred)
|
||||||
).let {
|
).let {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && it != null) {
|
Futures.addCallback(
|
||||||
Futures.addCallback(
|
it,
|
||||||
it,
|
object : FutureCallback<SessionResult> {
|
||||||
object : FutureCallback<SessionResult> {
|
override fun onSuccess(result: SessionResult?) {
|
||||||
override fun onSuccess(result: SessionResult?) {
|
// Trigger an update
|
||||||
updateStarred()
|
// TODO Update Metadata of MediaItem...
|
||||||
}
|
// localMediaPlayer.setCurrentPlaying(localMediaPlayer.currentPlaying)
|
||||||
|
song.starred = !song.starred
|
||||||
|
}
|
||||||
|
|
||||||
override fun onFailure(t: Throwable) {
|
override fun onFailure(t: Throwable) {
|
||||||
TODO("Not yet implemented")
|
Toast.makeText(
|
||||||
}
|
context,
|
||||||
},
|
"There was an error updating the rating",
|
||||||
context.mainExecutor
|
Toast.LENGTH_SHORT
|
||||||
)
|
).show()
|
||||||
} else {
|
}
|
||||||
updateStarred()
|
},
|
||||||
}
|
MainThreadExecutor()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue