Clear queue on logout.

This commit is contained in:
Antoine POPINEAU 2019-10-30 22:06:57 +01:00
parent 5c1498bb95
commit eac875b9cb
No known key found for this signature in database
GPG Key ID: A78AC64694F84063
4 changed files with 13 additions and 0 deletions

View File

@ -12,6 +12,8 @@ import androidx.preference.PreferenceFragmentCompat
import androidx.preference.SeekBarPreference
import com.github.apognu.otter.R
import com.github.apognu.otter.utils.AppContext
import com.github.apognu.otter.utils.Command
import com.github.apognu.otter.utils.CommandBus
import com.preference.PowerPreference
class SettingsActivity : AppCompatActivity() {
@ -69,6 +71,8 @@ class SettingsFragment : PreferenceFragmentCompat(), SharedPreferences.OnSharedP
context.cacheDir.deleteRecursively()
CommandBus.send(Command.ClearQueue)
activity?.setResult(MainActivity.ResultCode.LOGOUT.code)
activity?.finish()
}

View File

@ -172,6 +172,8 @@ class PlayerService : Service() {
is Command.NextTrack -> player.next()
is Command.PreviousTrack -> previousTrack()
is Command.Seek -> progress(message.progress)
is Command.ClearQueue -> queue.clear()
}
if (player.playWhenReady) {

View File

@ -154,4 +154,10 @@ class QueueManager(val context: Context) {
return metadata.getOrNull(current)
}
fun clear() {
metadata = mutableListOf()
datasources.clear()
current = -1
}
}

View File

@ -24,6 +24,7 @@ sealed class Command {
class ReplaceQueue(val queue: List<Track>) : Command()
class RemoveFromQueue(val track: Track) : Command()
class MoveFromQueue(val oldPosition: Int, val newPosition: Int) : Command()
object ClearQueue : Command()
class PlayTrack(val index: Int) : Command()
}