From 9dc2da66e1f3bbbd39a35780516024746adccf4c Mon Sep 17 00:00:00 2001 From: Hemanth S Date: Mon, 12 Oct 2020 20:25:31 +0530 Subject: [PATCH] Fix app shortcuts click crash --- .../retromusic/activities/MainActivity.kt | 10 ++++++---- .../AppShortcutLauncherActivity.kt | 20 ++++++------------- .../appshortcuts/DynamicShortcutManager.kt | 10 +++++++--- .../shortcuttype/BaseShortcutType.kt | 4 ++-- .../shortcuttype/ShuffleAllShortcutType.kt | 16 ++++++--------- .../player/gradient/GradientPlayerFragment.kt | 2 +- .../smartplaylist/PlaylistIdGenerator.kt | 2 +- .../retromusic/service/MusicService.java | 6 ++++-- .../res/layout/fragment_gradient_player.xml | 4 ++++ app/src/main/res/values-ru-rRU/strings.xml | 1 - 10 files changed, 37 insertions(+), 38 deletions(-) diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/MainActivity.kt b/app/src/main/java/code/name/monkey/retromusic/activities/MainActivity.kt index 1b147ef5..e02d925b 100644 --- a/app/src/main/java/code/name/monkey/retromusic/activities/MainActivity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/activities/MainActivity.kt @@ -77,7 +77,6 @@ class MainActivity : AbsSlidingMusicPanelActivity(), OnSharedPreferenceChangeLis override fun onCreate(savedInstanceState: Bundle?) { setDrawUnderStatusBar() super.onCreate(savedInstanceState) - setStatusbarColorAuto() setNavigationbarColorAuto() setLightNavigationBar(true) @@ -91,6 +90,12 @@ class MainActivity : AbsSlidingMusicPanelActivity(), OnSharedPreferenceChangeLis if (!hasPermissions()) { findNavController(R.id.fragment_container).navigate(R.id.permissionFragment) } + + showPromotionalDialog() + } + + private fun showPromotionalDialog() { + } private fun setupNavigationController() { @@ -104,9 +109,6 @@ class MainActivity : AbsSlidingMusicPanelActivity(), OnSharedPreferenceChangeLis } navController.graph = navGraph NavigationUI.setupWithNavController(getBottomNavigationView(), navController) - navController.addOnDestinationChangedListener { _, _, _ -> - // appBarLayout.setExpanded(true, true) - } } override fun onSupportNavigateUp(): Boolean = diff --git a/app/src/main/java/code/name/monkey/retromusic/appshortcuts/AppShortcutLauncherActivity.kt b/app/src/main/java/code/name/monkey/retromusic/appshortcuts/AppShortcutLauncherActivity.kt index 68d04c47..6ecd760d 100644 --- a/app/src/main/java/code/name/monkey/retromusic/appshortcuts/AppShortcutLauncherActivity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/appshortcuts/AppShortcutLauncherActivity.kt @@ -20,6 +20,7 @@ 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 +import code.name.monkey.retromusic.extensions.extraNotNull import code.name.monkey.retromusic.model.Playlist import code.name.monkey.retromusic.model.smartplaylist.LastAddedPlaylist import code.name.monkey.retromusic.model.smartplaylist.ShuffleAllPlaylist @@ -31,16 +32,7 @@ class AppShortcutLauncherActivity : Activity() { public override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - - 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) { + when (extraNotNull(KEY_SHORTCUT_TYPE, SHORTCUT_TYPE_NONE).value) { SHORTCUT_TYPE_SHUFFLE_ALL -> { startServiceWithPlaylist( SHUFFLE_MODE_SHUFFLE, ShuffleAllPlaylist() @@ -78,9 +70,9 @@ class AppShortcutLauncherActivity : Activity() { 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 + const val SHORTCUT_TYPE_SHUFFLE_ALL = 0L + const val SHORTCUT_TYPE_TOP_TRACKS = 1L + const val SHORTCUT_TYPE_LAST_ADDED = 2L + const val SHORTCUT_TYPE_NONE = 4L } } diff --git a/app/src/main/java/code/name/monkey/retromusic/appshortcuts/DynamicShortcutManager.kt b/app/src/main/java/code/name/monkey/retromusic/appshortcuts/DynamicShortcutManager.kt index 7de8c8ef..2b74eab3 100644 --- a/app/src/main/java/code/name/monkey/retromusic/appshortcuts/DynamicShortcutManager.kt +++ b/app/src/main/java/code/name/monkey/retromusic/appshortcuts/DynamicShortcutManager.kt @@ -32,7 +32,7 @@ class DynamicShortcutManager(private val context: Context) { this.context.getSystemService(ShortcutManager::class.java) private val defaultShortcuts: List - get() = Arrays.asList( + get() = listOf( ShuffleAllShortcutType(context).shortcutInfo, TopTracksShortcutType(context).shortcutInfo, LastAddedShortcutType(context).shortcutInfo @@ -58,8 +58,12 @@ class DynamicShortcutManager(private val context: Context) { icon: Icon, intent: Intent ): ShortcutInfo { - return ShortcutInfo.Builder(context, id).setShortLabel(shortLabel) - .setLongLabel(longLabel).setIcon(icon).setIntent(intent).build() + return ShortcutInfo.Builder(context, id) + .setShortLabel(shortLabel) + .setLongLabel(longLabel) + .setIcon(icon) + .setIntent(intent) + .build() } fun reportShortcutUsed(context: Context, shortcutId: String) { diff --git a/app/src/main/java/code/name/monkey/retromusic/appshortcuts/shortcuttype/BaseShortcutType.kt b/app/src/main/java/code/name/monkey/retromusic/appshortcuts/shortcuttype/BaseShortcutType.kt index 1be5edcb..91fc8f41 100644 --- a/app/src/main/java/code/name/monkey/retromusic/appshortcuts/shortcuttype/BaseShortcutType.kt +++ b/app/src/main/java/code/name/monkey/retromusic/appshortcuts/shortcuttype/BaseShortcutType.kt @@ -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.) * @return */ - internal fun getPlaySongsIntent(shortcutType: Int): Intent { + internal fun getPlaySongsIntent(shortcutType: Long): Intent { val intent = Intent(context, AppShortcutLauncherActivity::class.java) intent.action = Intent.ACTION_VIEW val b = Bundle() - b.putInt(AppShortcutLauncherActivity.KEY_SHORTCUT_TYPE, shortcutType) + b.putLong(AppShortcutLauncherActivity.KEY_SHORTCUT_TYPE, shortcutType) intent.putExtras(b) return intent } diff --git a/app/src/main/java/code/name/monkey/retromusic/appshortcuts/shortcuttype/ShuffleAllShortcutType.kt b/app/src/main/java/code/name/monkey/retromusic/appshortcuts/shortcuttype/ShuffleAllShortcutType.kt index 4d13055e..21855cac 100644 --- a/app/src/main/java/code/name/monkey/retromusic/appshortcuts/shortcuttype/ShuffleAllShortcutType.kt +++ b/app/src/main/java/code/name/monkey/retromusic/appshortcuts/shortcuttype/ShuffleAllShortcutType.kt @@ -26,20 +26,16 @@ import code.name.monkey.retromusic.appshortcuts.AppShortcutLauncherActivity class ShuffleAllShortcutType(context: Context) : BaseShortcutType(context) { override val shortcutInfo: ShortcutInfo - get() = ShortcutInfo.Builder( - context, id - ).setShortLabel(context.getString(R.string.app_shortcut_shuffle_all_short)).setLongLabel( - context.getString(R.string.app_shortcut_shuffle_all_long) - ).setIcon( - AppShortcutIconGenerator.generateThemedIcon( - context, R.drawable.ic_app_shortcut_shuffle_all - ) - ).setIntent(getPlaySongsIntent(AppShortcutLauncherActivity.SHORTCUT_TYPE_SHUFFLE_ALL)) + get() = ShortcutInfo.Builder(context, id) + .setShortLabel(context.getString(R.string.app_shortcut_shuffle_all_short)) + .setLongLabel(context.getString(R.string.app_shortcut_shuffle_all_long)) + .setIcon(AppShortcutIconGenerator.generateThemedIcon(context, R.drawable.ic_app_shortcut_shuffle_all)) + .setIntent(getPlaySongsIntent(AppShortcutLauncherActivity.SHORTCUT_TYPE_SHUFFLE_ALL)) .build() companion object { val id: String - get() = BaseShortcutType.ID_PREFIX + "shuffle_all" + get() = ID_PREFIX + "shuffle_all" } } diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/player/gradient/GradientPlayerFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/player/gradient/GradientPlayerFragment.kt index 81683283..cf11bd78 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/player/gradient/GradientPlayerFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/player/gradient/GradientPlayerFragment.kt @@ -168,8 +168,8 @@ class GradientPlayerFragment : AbsPlayerFragment(R.layout.fragment_gradient_play } override fun onPause() { - recyclerViewDragDropManager?.cancelDrag() super.onPause() + recyclerViewDragDropManager?.cancelDrag() progressViewUpdateHelper.stop() } diff --git a/app/src/main/java/code/name/monkey/retromusic/model/smartplaylist/PlaylistIdGenerator.kt b/app/src/main/java/code/name/monkey/retromusic/model/smartplaylist/PlaylistIdGenerator.kt index f81ceb6c..baefff7b 100644 --- a/app/src/main/java/code/name/monkey/retromusic/model/smartplaylist/PlaylistIdGenerator.kt +++ b/app/src/main/java/code/name/monkey/retromusic/model/smartplaylist/PlaylistIdGenerator.kt @@ -6,7 +6,7 @@ import kotlin.math.abs object PlaylistIdGenerator { 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) } } \ No newline at end of file diff --git a/app/src/main/java/code/name/monkey/retromusic/service/MusicService.java b/app/src/main/java/code/name/monkey/retromusic/service/MusicService.java index b7d39972..f0b8b110 100644 --- a/app/src/main/java/code/name/monkey/retromusic/service/MusicService.java +++ b/app/src/main/java/code/name/monkey/retromusic/service/MusicService.java @@ -72,8 +72,10 @@ import code.name.monkey.retromusic.appwidgets.AppWidgetText; import code.name.monkey.retromusic.glide.BlurTransformation; import code.name.monkey.retromusic.glide.SongGlideRequest; 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.Song; +import code.name.monkey.retromusic.model.smartplaylist.AbsSmartPlaylist; import code.name.monkey.retromusic.providers.HistoryStore; import code.name.monkey.retromusic.providers.MusicPlaybackQueueStore; import code.name.monkey.retromusic.providers.SongPlayCountStore; @@ -1271,10 +1273,10 @@ public class MusicService extends Service } 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()); if (playlist != null) { - List playlistSongs = playlist.getSongs(); + List playlistSongs = playlist.songs(); if (!playlistSongs.isEmpty()) { if (shuffleMode == SHUFFLE_MODE_SHUFFLE) { int startPosition = new Random().nextInt(playlistSongs.size()); diff --git a/app/src/main/res/layout/fragment_gradient_player.xml b/app/src/main/res/layout/fragment_gradient_player.xml index 6c6a3bfc..f83beb93 100644 --- a/app/src/main/res/layout/fragment_gradient_player.xml +++ b/app/src/main/res/layout/fragment_gradient_player.xml @@ -108,6 +108,8 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="?attr/roundSelector" + android:clickable="true" + android:focusable="true" android:padding="14dp" android:scaleType="fitCenter" app:layout_constraintBottom_toBottomOf="@+id/previousButton" @@ -124,6 +126,8 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="?attr/roundSelector" + android:clickable="true" + android:focusable="true" android:padding="14dp" android:scaleType="fitCenter" app:layout_constraintBottom_toBottomOf="@+id/nextButton" diff --git a/app/src/main/res/values-ru-rRU/strings.xml b/app/src/main/res/values-ru-rRU/strings.xml index 2bfa8287..8f08c590 100644 --- a/app/src/main/res/values-ru-rRU/strings.xml +++ b/app/src/main/res/values-ru-rRU/strings.xml @@ -519,7 +519,6 @@ Эффект снегопада - Только альбомы исполнителей Использовать обложку альбома текущей песни в качестве обоев на экране блокировки. Снизить громкость воспроизведения когда приходит звуковое уведомление Содержимое черного списка скрыто из вашей библиотеки.