Fix app shortcuts click crash

This commit is contained in:
Hemanth S 2020-10-12 20:25:31 +05:30
parent 0ce71b19a8
commit 9dc2da66e1
10 changed files with 37 additions and 38 deletions

View file

@ -77,7 +77,6 @@ class MainActivity : AbsSlidingMusicPanelActivity(), OnSharedPreferenceChangeLis
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
setDrawUnderStatusBar() setDrawUnderStatusBar()
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setStatusbarColorAuto() setStatusbarColorAuto()
setNavigationbarColorAuto() setNavigationbarColorAuto()
setLightNavigationBar(true) setLightNavigationBar(true)
@ -91,6 +90,12 @@ class MainActivity : AbsSlidingMusicPanelActivity(), OnSharedPreferenceChangeLis
if (!hasPermissions()) { if (!hasPermissions()) {
findNavController(R.id.fragment_container).navigate(R.id.permissionFragment) findNavController(R.id.fragment_container).navigate(R.id.permissionFragment)
} }
showPromotionalDialog()
}
private fun showPromotionalDialog() {
} }
private fun setupNavigationController() { private fun setupNavigationController() {
@ -104,9 +109,6 @@ class MainActivity : AbsSlidingMusicPanelActivity(), OnSharedPreferenceChangeLis
} }
navController.graph = navGraph navController.graph = navGraph
NavigationUI.setupWithNavController(getBottomNavigationView(), navController) NavigationUI.setupWithNavController(getBottomNavigationView(), navController)
navController.addOnDestinationChangedListener { _, _, _ ->
// appBarLayout.setExpanded(true, true)
}
} }
override fun onSupportNavigateUp(): Boolean = override fun onSupportNavigateUp(): Boolean =

View file

@ -20,6 +20,7 @@ import android.os.Bundle
import code.name.monkey.retromusic.appshortcuts.shortcuttype.LastAddedShortcutType import code.name.monkey.retromusic.appshortcuts.shortcuttype.LastAddedShortcutType
import code.name.monkey.retromusic.appshortcuts.shortcuttype.ShuffleAllShortcutType import code.name.monkey.retromusic.appshortcuts.shortcuttype.ShuffleAllShortcutType
import code.name.monkey.retromusic.appshortcuts.shortcuttype.TopTracksShortcutType import code.name.monkey.retromusic.appshortcuts.shortcuttype.TopTracksShortcutType
import code.name.monkey.retromusic.extensions.extraNotNull
import code.name.monkey.retromusic.model.Playlist import code.name.monkey.retromusic.model.Playlist
import code.name.monkey.retromusic.model.smartplaylist.LastAddedPlaylist import code.name.monkey.retromusic.model.smartplaylist.LastAddedPlaylist
import code.name.monkey.retromusic.model.smartplaylist.ShuffleAllPlaylist import code.name.monkey.retromusic.model.smartplaylist.ShuffleAllPlaylist
@ -31,16 +32,7 @@ class AppShortcutLauncherActivity : Activity() {
public override fun onCreate(savedInstanceState: Bundle?) { public override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
when (extraNotNull(KEY_SHORTCUT_TYPE, SHORTCUT_TYPE_NONE).value) {
var shortcutType = SHORTCUT_TYPE_NONE
// Set shortcutType from the intent extras
val extras = intent.extras
if (extras != null) {
shortcutType = extras.getInt(KEY_SHORTCUT_TYPE, SHORTCUT_TYPE_NONE)
}
when (shortcutType) {
SHORTCUT_TYPE_SHUFFLE_ALL -> { SHORTCUT_TYPE_SHUFFLE_ALL -> {
startServiceWithPlaylist( startServiceWithPlaylist(
SHUFFLE_MODE_SHUFFLE, ShuffleAllPlaylist() SHUFFLE_MODE_SHUFFLE, ShuffleAllPlaylist()
@ -78,9 +70,9 @@ class AppShortcutLauncherActivity : Activity() {
companion object { companion object {
const val KEY_SHORTCUT_TYPE = "code.name.monkey.retromusic.appshortcuts.ShortcutType" const val KEY_SHORTCUT_TYPE = "code.name.monkey.retromusic.appshortcuts.ShortcutType"
const val SHORTCUT_TYPE_SHUFFLE_ALL = 0 const val SHORTCUT_TYPE_SHUFFLE_ALL = 0L
const val SHORTCUT_TYPE_TOP_TRACKS = 1 const val SHORTCUT_TYPE_TOP_TRACKS = 1L
const val SHORTCUT_TYPE_LAST_ADDED = 2 const val SHORTCUT_TYPE_LAST_ADDED = 2L
const val SHORTCUT_TYPE_NONE = 4 const val SHORTCUT_TYPE_NONE = 4L
} }
} }

View file

@ -32,7 +32,7 @@ class DynamicShortcutManager(private val context: Context) {
this.context.getSystemService(ShortcutManager::class.java) this.context.getSystemService(ShortcutManager::class.java)
private val defaultShortcuts: List<ShortcutInfo> private val defaultShortcuts: List<ShortcutInfo>
get() = Arrays.asList( get() = listOf(
ShuffleAllShortcutType(context).shortcutInfo, ShuffleAllShortcutType(context).shortcutInfo,
TopTracksShortcutType(context).shortcutInfo, TopTracksShortcutType(context).shortcutInfo,
LastAddedShortcutType(context).shortcutInfo LastAddedShortcutType(context).shortcutInfo
@ -58,8 +58,12 @@ class DynamicShortcutManager(private val context: Context) {
icon: Icon, icon: Icon,
intent: Intent intent: Intent
): ShortcutInfo { ): ShortcutInfo {
return ShortcutInfo.Builder(context, id).setShortLabel(shortLabel) return ShortcutInfo.Builder(context, id)
.setLongLabel(longLabel).setIcon(icon).setIntent(intent).build() .setShortLabel(shortLabel)
.setLongLabel(longLabel)
.setIcon(icon)
.setIntent(intent)
.build()
} }
fun reportShortcutUsed(context: Context, shortcutId: String) { fun reportShortcutUsed(context: Context, shortcutId: String) {

View file

@ -33,11 +33,11 @@ abstract class BaseShortcutType(internal var context: Context) {
* @param shortcutType Describes the type of shortcut to create (ShuffleAll, TopTracks, custom playlist, etc.) * @param shortcutType Describes the type of shortcut to create (ShuffleAll, TopTracks, custom playlist, etc.)
* @return * @return
*/ */
internal fun getPlaySongsIntent(shortcutType: Int): Intent { internal fun getPlaySongsIntent(shortcutType: Long): Intent {
val intent = Intent(context, AppShortcutLauncherActivity::class.java) val intent = Intent(context, AppShortcutLauncherActivity::class.java)
intent.action = Intent.ACTION_VIEW intent.action = Intent.ACTION_VIEW
val b = Bundle() val b = Bundle()
b.putInt(AppShortcutLauncherActivity.KEY_SHORTCUT_TYPE, shortcutType) b.putLong(AppShortcutLauncherActivity.KEY_SHORTCUT_TYPE, shortcutType)
intent.putExtras(b) intent.putExtras(b)
return intent return intent
} }

View file

@ -26,20 +26,16 @@ import code.name.monkey.retromusic.appshortcuts.AppShortcutLauncherActivity
class ShuffleAllShortcutType(context: Context) : BaseShortcutType(context) { class ShuffleAllShortcutType(context: Context) : BaseShortcutType(context) {
override val shortcutInfo: ShortcutInfo override val shortcutInfo: ShortcutInfo
get() = ShortcutInfo.Builder( get() = ShortcutInfo.Builder(context, id)
context, id .setShortLabel(context.getString(R.string.app_shortcut_shuffle_all_short))
).setShortLabel(context.getString(R.string.app_shortcut_shuffle_all_short)).setLongLabel( .setLongLabel(context.getString(R.string.app_shortcut_shuffle_all_long))
context.getString(R.string.app_shortcut_shuffle_all_long) .setIcon(AppShortcutIconGenerator.generateThemedIcon(context, R.drawable.ic_app_shortcut_shuffle_all))
).setIcon( .setIntent(getPlaySongsIntent(AppShortcutLauncherActivity.SHORTCUT_TYPE_SHUFFLE_ALL))
AppShortcutIconGenerator.generateThemedIcon(
context, R.drawable.ic_app_shortcut_shuffle_all
)
).setIntent(getPlaySongsIntent(AppShortcutLauncherActivity.SHORTCUT_TYPE_SHUFFLE_ALL))
.build() .build()
companion object { companion object {
val id: String val id: String
get() = BaseShortcutType.ID_PREFIX + "shuffle_all" get() = ID_PREFIX + "shuffle_all"
} }
} }

View file

@ -168,8 +168,8 @@ class GradientPlayerFragment : AbsPlayerFragment(R.layout.fragment_gradient_play
} }
override fun onPause() { override fun onPause() {
recyclerViewDragDropManager?.cancelDrag()
super.onPause() super.onPause()
recyclerViewDragDropManager?.cancelDrag()
progressViewUpdateHelper.stop() progressViewUpdateHelper.stop()
} }

View file

@ -6,7 +6,7 @@ import kotlin.math.abs
object PlaylistIdGenerator { object PlaylistIdGenerator {
operator fun invoke(name: String, @DrawableRes iconRes: Int): Long { operator fun invoke(name: String, @DrawableRes iconRes: Int): Long {
return -abs(31L * name.hashCode() + iconRes * name.hashCode() * 31L * 31L) return abs(31L * name.hashCode() + iconRes * name.hashCode() * 31L * 31L)
} }
} }

View file

@ -72,8 +72,10 @@ import code.name.monkey.retromusic.appwidgets.AppWidgetText;
import code.name.monkey.retromusic.glide.BlurTransformation; import code.name.monkey.retromusic.glide.BlurTransformation;
import code.name.monkey.retromusic.glide.SongGlideRequest; import code.name.monkey.retromusic.glide.SongGlideRequest;
import code.name.monkey.retromusic.helper.ShuffleHelper; import code.name.monkey.retromusic.helper.ShuffleHelper;
import code.name.monkey.retromusic.model.AbsCustomPlaylist;
import code.name.monkey.retromusic.model.Playlist; import code.name.monkey.retromusic.model.Playlist;
import code.name.monkey.retromusic.model.Song; import code.name.monkey.retromusic.model.Song;
import code.name.monkey.retromusic.model.smartplaylist.AbsSmartPlaylist;
import code.name.monkey.retromusic.providers.HistoryStore; import code.name.monkey.retromusic.providers.HistoryStore;
import code.name.monkey.retromusic.providers.MusicPlaybackQueueStore; import code.name.monkey.retromusic.providers.MusicPlaybackQueueStore;
import code.name.monkey.retromusic.providers.SongPlayCountStore; import code.name.monkey.retromusic.providers.SongPlayCountStore;
@ -1271,10 +1273,10 @@ public class MusicService extends Service
} }
private void playFromPlaylist(Intent intent) { private void playFromPlaylist(Intent intent) {
Playlist playlist = intent.getParcelableExtra(INTENT_EXTRA_PLAYLIST); AbsSmartPlaylist playlist = intent.getParcelableExtra(INTENT_EXTRA_PLAYLIST);
int shuffleMode = intent.getIntExtra(INTENT_EXTRA_SHUFFLE_MODE, getShuffleMode()); int shuffleMode = intent.getIntExtra(INTENT_EXTRA_SHUFFLE_MODE, getShuffleMode());
if (playlist != null) { if (playlist != null) {
List<Song> playlistSongs = playlist.getSongs(); List<Song> playlistSongs = playlist.songs();
if (!playlistSongs.isEmpty()) { if (!playlistSongs.isEmpty()) {
if (shuffleMode == SHUFFLE_MODE_SHUFFLE) { if (shuffleMode == SHUFFLE_MODE_SHUFFLE) {
int startPosition = new Random().nextInt(playlistSongs.size()); int startPosition = new Random().nextInt(playlistSongs.size());

View file

@ -108,6 +108,8 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="?attr/roundSelector" android:background="?attr/roundSelector"
android:clickable="true"
android:focusable="true"
android:padding="14dp" android:padding="14dp"
android:scaleType="fitCenter" android:scaleType="fitCenter"
app:layout_constraintBottom_toBottomOf="@+id/previousButton" app:layout_constraintBottom_toBottomOf="@+id/previousButton"
@ -124,6 +126,8 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="?attr/roundSelector" android:background="?attr/roundSelector"
android:clickable="true"
android:focusable="true"
android:padding="14dp" android:padding="14dp"
android:scaleType="fitCenter" android:scaleType="fitCenter"
app:layout_constraintBottom_toBottomOf="@+id/nextButton" app:layout_constraintBottom_toBottomOf="@+id/nextButton"

View file

@ -519,7 +519,6 @@
<string name="pref_snow_fall_title">Эффект снегопада</string> <string name="pref_snow_fall_title">Эффект снегопада</string>
<string name="action_album_artists_only">Только альбомы исполнителей</string>
<string name="pref_summary_album_art_on_lockscreen">Использовать обложку альбома текущей песни в качестве обоев на экране блокировки.</string> <string name="pref_summary_album_art_on_lockscreen">Использовать обложку альбома текущей песни в качестве обоев на экране блокировки.</string>
<string name="pref_summary_audio_ducking">Снизить громкость воспроизведения когда приходит звуковое уведомление</string> <string name="pref_summary_audio_ducking">Снизить громкость воспроизведения когда приходит звуковое уведомление</string>
<string name="pref_summary_blacklist">Содержимое черного списка скрыто из вашей библиотеки.</string> <string name="pref_summary_blacklist">Содержимое черного списка скрыто из вашей библиотеки.</string>