Auxio/app/src/main/java/org/oxycblt/auxio/AuxioApp.kt
OxygenCobalt 29fe849565
playback: add shuffle shortcut
Add a shortcut to shuffle all songs.

This is likely the only static shortcut Auxio will have. Top tracks
and recently added are completely useless for me, so I will never
add them. I may add more dynamic shortcuts for recently played items,
however.

Note that we use a basic black shuffle icon here. I will not add icon
customization to these shortcuts.
2022-06-18 11:20:22 -06:00

81 lines
3.3 KiB
Kotlin

/*
* Copyright (c) 2021 Auxio Project
*
* This program 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.
*
* This program 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.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.oxycblt.auxio
import android.app.Application
import android.content.Intent
import androidx.core.content.pm.ShortcutInfoCompat
import androidx.core.content.pm.ShortcutManagerCompat
import androidx.core.graphics.drawable.IconCompat
import coil.ImageLoader
import coil.ImageLoaderFactory
import coil.request.CachePolicy
import org.oxycblt.auxio.image.AlbumCoverFetcher
import org.oxycblt.auxio.image.ArtistImageFetcher
import org.oxycblt.auxio.image.CrossfadeTransitionFactory
import org.oxycblt.auxio.image.GenreImageFetcher
import org.oxycblt.auxio.image.MusicKeyer
import org.oxycblt.auxio.settings.SettingsManager
import org.oxycblt.auxio.util.logD
class AuxioApp : Application(), ImageLoaderFactory {
override fun onCreate() {
super.onCreate()
logD(BuildConfig.APPLICATION_ID + ".MainActivity")
// Adding static shortcuts in a dynamic manner is better than declaring them
// manually, as it will properly handle the difference between debug and release
// Auxio instances.
ShortcutManagerCompat.addDynamicShortcuts(
this,
listOf(
ShortcutInfoCompat.Builder(this, SHORTCUT_SHUFFLE_ID)
.setShortLabel(getString(R.string.lbl_shuffle_shortcut_short))
.setLongLabel(getString(R.string.lbl_shuffle_shortcut_long))
.setIcon(IconCompat.createWithResource(this, R.drawable.ic_shuffle_shortcut))
.setIntent(
Intent(this, MainActivity::class.java).apply {
action = INTENT_KEY_SHORTCUT_SHUFFLE
})
.build()))
// Init SettingsManager here so that there aren't any race conditions
// [e.g PlaybackService gets SettingsManager before activity can init SettingsManager]
SettingsManager.init(applicationContext)
}
override fun newImageLoader(): ImageLoader {
return ImageLoader.Builder(applicationContext)
.components {
add(AlbumCoverFetcher.SongFactory())
add(AlbumCoverFetcher.AlbumFactory())
add(ArtistImageFetcher.Factory())
add(GenreImageFetcher.Factory())
add(MusicKeyer())
}
.transitionFactory(CrossfadeTransitionFactory())
.diskCachePolicy(CachePolicy.DISABLED) // Not downloading anything, so no disk-caching
.build()
}
companion object {
const val SHORTCUT_SHUFFLE_ID = "shortcut_shuffle"
const val INTENT_KEY_SHORTCUT_SHUFFLE = BuildConfig.APPLICATION_ID + ".action.SHUFFLE_ALL"
}
}