PlayerAndroid/app/src/main/java/code/name/monkey/retromusic/appshortcuts/AppShortcutLauncherActivity.kt

87 lines
3.3 KiB
Kotlin
Raw Normal View History

2019-03-03 09:20:15 +00:00
/*
2020-10-06 08:46:04 +00:00
* Copyright (c) 2020 Hemanth Savarla.
2019-03-03 09:20:15 +00:00
*
* Licensed under the GNU General Public License v3
*
2020-10-06 08:46:04 +00:00
* This is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
2019-03-03 09:20:15 +00:00
*
* This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
2020-10-06 08:46:04 +00:00
*
2019-03-03 09:20:15 +00:00
*/
2018-12-25 14:58:47 +00:00
package code.name.monkey.retromusic.appshortcuts
import android.app.Activity
import android.content.Intent
import android.os.Bundle
import code.name.monkey.retromusic.appshortcuts.shortcuttype.LastAddedShortcutType
import code.name.monkey.retromusic.appshortcuts.shortcuttype.ShuffleAllShortcutType
import code.name.monkey.retromusic.appshortcuts.shortcuttype.TopTracksShortcutType
2018-12-25 14:58:47 +00:00
import code.name.monkey.retromusic.model.Playlist
import code.name.monkey.retromusic.model.smartplaylist.LastAddedPlaylist
import code.name.monkey.retromusic.model.smartplaylist.ShuffleAllPlaylist
import code.name.monkey.retromusic.model.smartplaylist.TopTracksPlaylist
2018-12-25 14:58:47 +00:00
import code.name.monkey.retromusic.service.MusicService
import code.name.monkey.retromusic.service.MusicService.*
2018-12-25 14:58:47 +00:00
class AppShortcutLauncherActivity : Activity() {
public override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
2018-12-25 14:58:47 +00:00
var shortcutType = SHORTCUT_TYPE_NONE
2018-12-25 14:58:47 +00:00
// Set shortcutType from the intent extras
val extras = intent.extras
if (extras != null) {
shortcutType = extras.getInt(KEY_SHORTCUT_TYPE, SHORTCUT_TYPE_NONE)
}
2018-12-25 14:58:47 +00:00
when (shortcutType) {
SHORTCUT_TYPE_SHUFFLE_ALL -> {
startServiceWithPlaylist(
2020-08-14 08:34:03 +00:00
SHUFFLE_MODE_SHUFFLE, ShuffleAllPlaylist()
)
DynamicShortcutManager.reportShortcutUsed(this, ShuffleAllShortcutType.id)
}
SHORTCUT_TYPE_TOP_TRACKS -> {
startServiceWithPlaylist(
2020-08-14 08:34:03 +00:00
SHUFFLE_MODE_NONE, TopTracksPlaylist()
)
DynamicShortcutManager.reportShortcutUsed(this, TopTracksShortcutType.id)
}
SHORTCUT_TYPE_LAST_ADDED -> {
startServiceWithPlaylist(
2020-08-14 08:34:03 +00:00
SHUFFLE_MODE_NONE, LastAddedPlaylist()
)
DynamicShortcutManager.reportShortcutUsed(this, LastAddedShortcutType.id)
}
}
finish()
}
2018-12-25 14:58:47 +00:00
private fun startServiceWithPlaylist(shuffleMode: Int, playlist: Playlist) {
val intent = Intent(this, MusicService::class.java)
intent.action = ACTION_PLAY_PLAYLIST
2018-12-25 14:58:47 +00:00
val bundle = Bundle()
bundle.putParcelable(INTENT_EXTRA_PLAYLIST, playlist)
bundle.putInt(INTENT_EXTRA_SHUFFLE_MODE, shuffleMode)
2018-12-25 14:58:47 +00:00
intent.putExtras(bundle)
2018-12-25 14:58:47 +00:00
startService(intent)
}
2018-12-25 14:58:47 +00:00
companion object {
const val KEY_SHORTCUT_TYPE = "code.name.monkey.retromusic.appshortcuts.ShortcutType"
const val SHORTCUT_TYPE_SHUFFLE_ALL = 0
const val SHORTCUT_TYPE_TOP_TRACKS = 1
const val SHORTCUT_TYPE_LAST_ADDED = 2
const val SHORTCUT_TYPE_NONE = 4
}
2018-12-25 14:58:47 +00:00
}