mirror of
https://github.com/cmclark00/RetroMusicPlayer.git
synced 2025-05-19 16:45:20 +01:00
Added favorite icon to notifications
This commit is contained in:
parent
e8cb0f5274
commit
6fde42ba11
16 changed files with 216 additions and 24 deletions
|
@ -211,6 +211,12 @@ public class MusicService extends MediaBrowserServiceCompat implements SharedPre
|
|||
}
|
||||
};
|
||||
private PlayingNotification playingNotification;
|
||||
private final BroadcastReceiver updateFavoriteReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(final Context context, final Intent intent) {
|
||||
updateNotification();
|
||||
}
|
||||
};
|
||||
private AudioManager audioManager;
|
||||
private MediaSessionCompat mediaSession;
|
||||
private PowerManager.WakeLock wakeLock;
|
||||
|
@ -324,6 +330,7 @@ public class MusicService extends MediaBrowserServiceCompat implements SharedPre
|
|||
uiThreadHandler = new Handler();
|
||||
|
||||
registerReceiver(widgetIntentReceiver, new IntentFilter(APP_WIDGET_UPDATE));
|
||||
registerReceiver(updateFavoriteReceiver, new IntentFilter(FAVORITE_STATE_CHANGED));
|
||||
|
||||
initNotification();
|
||||
|
||||
|
@ -698,13 +705,13 @@ public class MusicService extends MediaBrowserServiceCompat implements SharedPre
|
|||
if (getRepeatMode() == REPEAT_MODE_THIS) {
|
||||
repeatIcon = R.drawable.ic_repeat_one_white_24dp;
|
||||
} else if (getRepeatMode() == REPEAT_MODE_ALL) {
|
||||
repeatIcon = R.drawable.ic_repeat_white_24dp;
|
||||
repeatIcon = R.drawable.ic_repeat_white_circle_24dp;
|
||||
}
|
||||
stateBuilder.addCustomAction(new PlaybackStateCompat.CustomAction.Builder(
|
||||
CYCLE_REPEAT, getString(R.string.action_cycle_repeat), repeatIcon)
|
||||
.build());
|
||||
|
||||
final int shuffleIcon = getShuffleMode() == SHUFFLE_MODE_NONE ? R.drawable.ic_shuffle_white_24dp : R.drawable.ic_shuffle_white_24dp;
|
||||
final int shuffleIcon = getShuffleMode() == SHUFFLE_MODE_NONE ? R.drawable.ic_shuffle_off_circled : R.drawable.ic_shuffle_on_circled;
|
||||
stateBuilder.addCustomAction(new PlaybackStateCompat.CustomAction.Builder(
|
||||
TOGGLE_SHUFFLE, getString(R.string.action_toggle_shuffle), shuffleIcon)
|
||||
.build());
|
||||
|
@ -1189,6 +1196,7 @@ public class MusicService extends MediaBrowserServiceCompat implements SharedPre
|
|||
}
|
||||
songPlayCountHelper.notifyPlayStateChanged(isPlaying);
|
||||
break;
|
||||
case FAVORITE_STATE_CHANGED:
|
||||
case META_CHANGED:
|
||||
updateNotification();
|
||||
updateMediaSessionMetaData();
|
||||
|
|
|
@ -24,6 +24,7 @@ import android.graphics.drawable.Drawable
|
|||
import android.os.Build
|
||||
import android.text.Html
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.media.app.NotificationCompat.*
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.activities.MainActivity
|
||||
import code.name.monkey.retromusic.glide.GlideApp
|
||||
|
@ -48,9 +49,9 @@ class PlayingNotificationImpl24 : PlayingNotification() {
|
|||
val isPlaying = service.isPlaying
|
||||
val isFavorite = MusicUtil.isFavorite(service, song)
|
||||
val playButtonResId = if (isPlaying)
|
||||
R.drawable.ic_pause_white_24dp
|
||||
R.drawable.ic_pause_white_48dp
|
||||
else
|
||||
R.drawable.ic_play_arrow_white_32dp
|
||||
R.drawable.ic_play_arrow_white_48dp
|
||||
|
||||
val favoriteResId = if (isFavorite)
|
||||
R.drawable.ic_favorite_white_24dp
|
||||
|
@ -114,12 +115,12 @@ class PlayingNotificationImpl24 : PlayingNotification() {
|
|||
retrievePlaybackAction(ACTION_QUIT))
|
||||
|
||||
val previousAction = NotificationCompat.Action(
|
||||
R.drawable.ic_skip_previous_white_24dp,
|
||||
R.drawable.ic_skip_previous_round_white_32dp,
|
||||
service.getString(R.string.action_previous),
|
||||
retrievePlaybackAction(ACTION_REWIND))
|
||||
|
||||
val nextAction = NotificationCompat.Action(
|
||||
R.drawable.ic_skip_next_white_24dp,
|
||||
R.drawable.ic_skip_next_round_white_32dp,
|
||||
service.getString(R.string.action_next),
|
||||
retrievePlaybackAction(ACTION_SKIP))
|
||||
|
||||
|
@ -134,15 +135,16 @@ class PlayingNotificationImpl24 : PlayingNotification() {
|
|||
.setSubText(Html.fromHtml("<b>" + song.albumName + "</b>"))
|
||||
.setOngoing(isPlaying)
|
||||
.setShowWhen(false)
|
||||
.addAction(toggleFavorite)
|
||||
.addAction(previousAction)
|
||||
.addAction(playPauseAction)
|
||||
.addAction(nextAction)
|
||||
.addAction(closeAction)
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
builder.setStyle(androidx.media.app.NotificationCompat.MediaStyle()
|
||||
builder.setStyle(MediaStyle()
|
||||
.setMediaSession(service.mediaSession.sessionToken)
|
||||
.setShowActionsInCompactView(0, 1, 2, 3, 4))
|
||||
.setShowActionsInCompactView( 1, 2, 3))
|
||||
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
||||
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.O && PreferenceUtil.getInstance().coloredNotification()) {
|
||||
builder.color = color
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue