playback: fix delayed actions not working
Fix an issue on some devices where the delayed actions system would not work on startup. Apparently onStart can be called several times with the same intent. No, I am not joking. What the actual hell. This would cause any delayed action other than Restore to be overwritten. The only hard rule about android is that there are no rules. I hate this platform so much.
This commit is contained in:
parent
9ca4f70315
commit
7f07764b68
1 changed files with 26 additions and 12 deletions
|
@ -67,28 +67,42 @@ class MainActivity : AppCompatActivity() {
|
|||
startService(Intent(this, IndexerService::class.java))
|
||||
startService(Intent(this, PlaybackService::class.java))
|
||||
|
||||
// If we have a valid intent, use that. Otherwise, restore the playback state.
|
||||
playbackModel.startDelayedAction(
|
||||
intentToDelayedAction(intent) ?: PlaybackViewModel.DelayedAction.RestoreState)
|
||||
logD("YOU FUCKING RETARD DO BASCIS ${intent?.action}")
|
||||
|
||||
if (!intentToDelayedAction(intent)) {
|
||||
playbackModel.startDelayedAction(PlaybackViewModel.DelayedAction.RestoreState)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onNewIntent(intent: Intent?) {
|
||||
super.onNewIntent(intent)
|
||||
intentToDelayedAction(intent)?.let(playbackModel::startDelayedAction)
|
||||
intentToDelayedAction(intent)
|
||||
}
|
||||
|
||||
private fun intentToDelayedAction(intent: Intent?): PlaybackViewModel.DelayedAction? {
|
||||
if (intent == null || intent.getBooleanExtra(KEY_INTENT_USED, false)) {
|
||||
return null
|
||||
private fun intentToDelayedAction(intent: Intent?): Boolean {
|
||||
if (intent == null) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (intent.getBooleanExtra(KEY_INTENT_USED, false)) {
|
||||
return true
|
||||
}
|
||||
|
||||
intent.putExtra(KEY_INTENT_USED, true)
|
||||
|
||||
return when (intent.action) {
|
||||
Intent.ACTION_VIEW -> intent.data?.let { PlaybackViewModel.DelayedAction.Open(it) }
|
||||
AuxioApp.INTENT_KEY_SHORTCUT_SHUFFLE -> PlaybackViewModel.DelayedAction.ShuffleAll
|
||||
else -> null
|
||||
}
|
||||
val action =
|
||||
when (intent.action) {
|
||||
Intent.ACTION_VIEW ->
|
||||
PlaybackViewModel.DelayedAction.Open(intent.data ?: return false)
|
||||
AuxioApp.INTENT_KEY_SHORTCUT_SHUFFLE -> {
|
||||
PlaybackViewModel.DelayedAction.ShuffleAll
|
||||
}
|
||||
else -> return false
|
||||
}
|
||||
|
||||
playbackModel.startDelayedAction(action)
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
private fun setupTheme() {
|
||||
|
|
Loading…
Reference in a new issue