From 9a64eeabe66d03e859656758d9824805758ef525 Mon Sep 17 00:00:00 2001 From: eddyizm Date: Sun, 5 Oct 2025 12:59:24 -0700 Subject: [PATCH] feat: added preference to disable heart and show shuffle instead --- .../tempo/ui/fragment/SettingsFragment.java | 16 ++++++++ .../tempo/util/Preferences.kt | 11 +++++ app/src/main/res/values/strings.xml | 2 + app/src/main/res/xml/global_preferences.xml | 7 ++++ .../service/MediaLibraryServiceCallback.kt | 41 ++++++++----------- 5 files changed, 53 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/com/cappielloantonio/tempo/ui/fragment/SettingsFragment.java b/app/src/main/java/com/cappielloantonio/tempo/ui/fragment/SettingsFragment.java index ef4f2134..0ee8d86f 100644 --- a/app/src/main/java/com/cappielloantonio/tempo/ui/fragment/SettingsFragment.java +++ b/app/src/main/java/com/cappielloantonio/tempo/ui/fragment/SettingsFragment.java @@ -117,6 +117,7 @@ public class SettingsFragment extends PreferenceFragmentCompat { actionDeleteDownloadStorage(); actionKeepScreenOn(); actionAutoDownloadLyrics(); + actionMiniPlayerHeart(); bindMediaService(); actionAppEqualizer(); @@ -358,6 +359,21 @@ public class SettingsFragment extends PreferenceFragmentCompat { }); } + private void actionMiniPlayerHeart() { + SwitchPreference preference = findPreference("mini_shuffle_button_visibility"); + if (preference == null) { + return; + } + + preference.setChecked(Preferences.showShuffleInsteadOfHeart()); + preference.setOnPreferenceChangeListener((pref, newValue) -> { + if (newValue instanceof Boolean) { + Preferences.setShuffleInsteadOfHeart((Boolean) newValue); + } + return true; + }); + } + private void actionAutoDownloadLyrics() { SwitchPreference preference = findPreference("auto_download_lyrics"); if (preference == null) { diff --git a/app/src/main/java/com/cappielloantonio/tempo/util/Preferences.kt b/app/src/main/java/com/cappielloantonio/tempo/util/Preferences.kt index 80276319..d3d81ee2 100644 --- a/app/src/main/java/com/cappielloantonio/tempo/util/Preferences.kt +++ b/app/src/main/java/com/cappielloantonio/tempo/util/Preferences.kt @@ -73,6 +73,7 @@ object Preferences { private const val LAST_INSTANT_MIX = "last_instant_mix" private const val EQUALIZER_ENABLED = "equalizer_enabled" private const val EQUALIZER_BAND_LEVELS = "equalizer_band_levels" + private const val MINI_SHUFFLE_BUTTON_VISIBILITY = "mini_shuffle_button_visibility" @JvmStatic fun getServer(): String? { @@ -359,6 +360,16 @@ object Preferences { ).apply() } + @JvmStatic + fun showShuffleInsteadOfHeart(): Boolean { + return App.getInstance().preferences.getBoolean(MINI_SHUFFLE_BUTTON_VISIBILITY, false) + } + + @JvmStatic + fun setShuffleInsteadOfHeart(enabled: Boolean) { + App.getInstance().preferences.edit().putBoolean(MINI_SHUFFLE_BUTTON_VISIBILITY, enabled).apply() + } + @JvmStatic fun showServerUnreachableDialog(): Boolean { return App.getInstance().preferences.getLong( diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 70aa972f..2b7a4148 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -335,6 +335,8 @@ Sync timer If enabled, the user will have the ability to save their play queue and will have the ability to load state when opening the application. Sync play queue for this user [Not Fully Baked] + Show Shuffle button + If enabled, show the shuffle button, remove the heart in the mini player Show radio If enabled, show the radio section. Restart the app for it to take full effect. Auto download lyrics diff --git a/app/src/main/res/xml/global_preferences.xml b/app/src/main/res/xml/global_preferences.xml index f240a304..e8b5faeb 100644 --- a/app/src/main/res/xml/global_preferences.xml +++ b/app/src/main/res/xml/global_preferences.xml @@ -97,6 +97,13 @@ android:defaultValue="true" android:summary="@string/settings_music_directory_summary" android:key="music_directory_section_visibility" /> + + + diff --git a/app/src/tempo/java/com/cappielloantonio/tempo/service/MediaLibraryServiceCallback.kt b/app/src/tempo/java/com/cappielloantonio/tempo/service/MediaLibraryServiceCallback.kt index f9254974..1815a815 100644 --- a/app/src/tempo/java/com/cappielloantonio/tempo/service/MediaLibraryServiceCallback.kt +++ b/app/src/tempo/java/com/cappielloantonio/tempo/service/MediaLibraryServiceCallback.kt @@ -32,6 +32,7 @@ import com.cappielloantonio.tempo.util.Constants.CUSTOM_COMMAND_TOGGLE_REPEAT_MO import com.cappielloantonio.tempo.util.Constants.CUSTOM_COMMAND_TOGGLE_SHUFFLE_MODE_OFF import com.cappielloantonio.tempo.util.Constants.CUSTOM_COMMAND_TOGGLE_SHUFFLE_MODE_ON import com.google.common.collect.ImmutableList +import com.cappielloantonio.tempo.util.Preferences import com.google.common.util.concurrent.Futures import com.google.common.util.concurrent.ListenableFuture import retrofit2.Call @@ -180,11 +181,22 @@ open class MediaLibrarySessionCallback( private fun buildCustomLayout(player: Player, isRatingPending: Boolean = false): ImmutableList { val customLayout = mutableListOf() - //TODO: create a user setting to decide which of the buttons to show on the mini player -// // Add shuffle button -// customLayout.add( -// if (player.shuffleModeEnabled) customCommandToggleShuffleModeOff else customCommandToggleShuffleModeOn -// ) + val showShuffle = Preferences.showShuffleInsteadOfHeart() + + if (!showShuffle) { + if (player.currentMediaItem != null && !isRatingPending) { + // Heart button + if ((player.mediaMetadata.userRating as HeartRating?)?.isHeart == true) { + customLayout.add(customCommandToggleHeartOff) + } else { + customLayout.add(customCommandToggleHeartOn) + } + } + } else { + customLayout.add( + if (player.shuffleModeEnabled) customCommandToggleShuffleModeOff else customCommandToggleShuffleModeOn + ) + } // Add repeat button val repeatButton = when (player.repeatMode) { @@ -194,25 +206,6 @@ open class MediaLibrarySessionCallback( } customLayout.add(repeatButton) - - // HEART_DEBUG logging - Log.d("HEART_DEBUG:", "Current media item: ${player.currentMediaItem}") - Log.d("HEART_DEBUG:", "User rating: ${player.mediaMetadata.userRating}") - Log.d("HEART_DEBUG:", "Is rating pending: $isRatingPending") - - // Add heart button if there's a current media item - if (player.currentMediaItem != null) { - if (isRatingPending) { - customLayout.add(customCommandToggleHeartLoading) - } else if ((player.mediaMetadata.userRating as HeartRating?)?.isHeart == true) { - customLayout.add(customCommandToggleHeartOff) - } else { - customLayout.add(customCommandToggleHeartOn) - } - } else { - Log.d("HEART_DEBUG:", "No current media item - skipping heart button") - } - return ImmutableList.copyOf(customLayout) }