Added favorite icon to notifications
This commit is contained in:
parent
e8cb0f5274
commit
6fde42ba11
16 changed files with 216 additions and 24 deletions
|
@ -67,6 +67,7 @@ abstract class AbsMusicServiceActivity : AbsBaseActivity(), MusicServiceEventLis
|
|||
filter.addAction(META_CHANGED)
|
||||
filter.addAction(QUEUE_CHANGED)
|
||||
filter.addAction(MEDIA_STORE_CHANGED)
|
||||
filter.addAction(FAVORITE_STATE_CHANGED)
|
||||
|
||||
registerReceiver(musicStateReceiver, filter)
|
||||
|
||||
|
@ -146,6 +147,7 @@ abstract class AbsMusicServiceActivity : AbsBaseActivity(), MusicServiceEventLis
|
|||
val activity = reference.get()
|
||||
if (activity != null && action != null) {
|
||||
when (action) {
|
||||
FAVORITE_STATE_CHANGED,
|
||||
META_CHANGED -> activity.onPlayingMetaChanged()
|
||||
QUEUE_CHANGED -> activity.onQueueChanged()
|
||||
PLAY_STATE_CHANGED -> activity.onPlayStateChanged()
|
||||
|
|
|
@ -22,6 +22,7 @@ import android.os.AsyncTask;
|
|||
import android.support.v4.media.MediaBrowserCompat;
|
||||
import android.support.v4.media.MediaDescriptionCompat;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
@ -314,7 +315,9 @@ public class AutoMusicProvider {
|
|||
}
|
||||
}
|
||||
|
||||
public List<MediaBrowserCompat.MediaItem> getChildren(String mediaId, Resources resources) {
|
||||
@Nullable
|
||||
public List<MediaBrowserCompat.MediaItem> getChildren(@NonNull String mediaId,
|
||||
@NonNull Resources resources) {
|
||||
List<MediaBrowserCompat.MediaItem> mediaItems = new ArrayList<>();
|
||||
|
||||
if (!AutoMediaIDHelper.isBrowseable(mediaId)) {
|
||||
|
@ -325,28 +328,33 @@ public class AutoMusicProvider {
|
|||
case AutoMediaIDHelper.MEDIA_ID_ROOT:
|
||||
//mediaItems.add(createBrowsableMediaItem(AutoMediaIDHelper.MEDIA_ID_MUSICS_BY_HISTORY, resources.getString(R.string.history_label), R.drawable.ic_access_time_white_24dp));
|
||||
//mediaItems.add(createBrowsableMediaItem(AutoMediaIDHelper.MEDIA_ID_MUSICS_BY_TOP_TRACKS, resources.getString(R.string.top_tracks_label), R.drawable.ic_trending_up_white_24dp));
|
||||
//mediaItems.add(createBrowsableMediaItem(AutoMediaIDHelper.MEDIA_ID_MUSICS_BY_PLAYLIST, resources.getString(R.string.playlists_label), R.drawable.ic_queue_music_white_24dp));
|
||||
|
||||
mediaItems.add(
|
||||
createBrowsableMediaItem(
|
||||
AutoMediaIDHelper.MEDIA_ID_MUSICS_BY_ALBUM,
|
||||
resources.getString(R.string.albums_label),
|
||||
R.drawable.ic_album_white_24dp));
|
||||
resources.getString(R.string.albums_label)
|
||||
));
|
||||
mediaItems.add(
|
||||
createBrowsableMediaItem(
|
||||
AutoMediaIDHelper.MEDIA_ID_MUSICS_BY_ARTIST,
|
||||
resources.getString(R.string.artists_label),
|
||||
R.drawable.ic_artist_white_24dp));
|
||||
resources.getString(R.string.artists_label)
|
||||
));
|
||||
mediaItems.add(
|
||||
createBrowsableMediaItem(
|
||||
AutoMediaIDHelper.MEDIA_ID_MUSICS_BY_PLAYLIST,
|
||||
resources.getString(R.string.playlists_label)
|
||||
));
|
||||
mediaItems.add(
|
||||
createBrowsableMediaItem(
|
||||
AutoMediaIDHelper.MEDIA_ID_MUSICS_BY_GENRE,
|
||||
resources.getString(R.string.genres_label),
|
||||
R.drawable.ic_guitar_acoustic_white_24dp));
|
||||
mediaItems.add(
|
||||
resources.getString(R.string.genres_label)
|
||||
));
|
||||
/* mediaItems.add(
|
||||
createPlayableMediaItem(
|
||||
AutoMediaIDHelper.MEDIA_ID_MUSICS_BY_SHUFFLE,
|
||||
resources.getString(R.string.action_shuffle_all),
|
||||
R.drawable.ic_shuffle_white_24dp,
|
||||
""));
|
||||
""));*/
|
||||
//mediaItems.add(createBrowsableMediaItem(AutoMediaIDHelper.MEDIA_ID_MUSICS_BY_QUEUE, resources.getString(R.string.queue_label), R.drawable.ic_playlist_play_white_24dp));
|
||||
break;
|
||||
|
||||
|
@ -386,7 +394,6 @@ public class AutoMusicProvider {
|
|||
break;
|
||||
|
||||
case AutoMediaIDHelper.MEDIA_ID_MUSICS_BY_QUEUE:
|
||||
// TODO: auto scroll to current track, indicate that it's playing
|
||||
for (final Uri uri : getQueue()) {
|
||||
mediaItems.add(createPlayableMediaItem(mediaId, uri, uri.getPathSegments().get(PATH_SEGMENT_TITLE), uri.getPathSegments().get(PATH_SEGMENT_ARTIST)));
|
||||
}
|
||||
|
@ -396,7 +403,7 @@ public class AutoMusicProvider {
|
|||
return mediaItems;
|
||||
}
|
||||
|
||||
private MediaBrowserCompat.MediaItem createBrowsableMediaItem(String mediaId, String title, int iconDrawableId) {
|
||||
private MediaBrowserCompat.MediaItem createBrowsableMediaItem(String mediaId, String title) {
|
||||
MediaDescriptionCompat.Builder builder = new MediaDescriptionCompat.Builder();
|
||||
builder.setMediaId(mediaId)
|
||||
.setTitle(title);
|
||||
|
|
|
@ -23,7 +23,6 @@ import code.name.monkey.retromusic.service.MusicService
|
|||
import code.name.monkey.retromusic.util.MusicUtil
|
||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||
import code.name.monkey.retromusic.util.ViewUtil
|
||||
import kotlinx.android.synthetic.main.fragment_material_playback_controls.*
|
||||
import kotlinx.android.synthetic.main.fragment_material_playback_controls.nextButton
|
||||
import kotlinx.android.synthetic.main.fragment_material_playback_controls.playPauseButton
|
||||
import kotlinx.android.synthetic.main.fragment_material_playback_controls.previousButton
|
||||
|
@ -34,7 +33,6 @@ import kotlinx.android.synthetic.main.fragment_material_playback_controls.songCu
|
|||
import kotlinx.android.synthetic.main.fragment_material_playback_controls.songTotalTime
|
||||
import kotlinx.android.synthetic.main.fragment_material_playback_controls.text
|
||||
import kotlinx.android.synthetic.main.fragment_material_playback_controls.title
|
||||
import kotlinx.android.synthetic.main.fragment_player_playback_controls.*
|
||||
|
||||
/**
|
||||
* @author Hemanth S (h4h13).
|
||||
|
@ -140,7 +138,7 @@ class MaterialControlsFragment : AbsPlayerControlsFragment() {
|
|||
|
||||
private fun updatePlayPauseDrawableState() {
|
||||
if (MusicPlayerRemote.isPlaying) {
|
||||
playPauseButton.setImageResource(R.drawable.ic_pause_white_big);
|
||||
playPauseButton.setImageResource(R.drawable.ic_pause_white_64dp);
|
||||
} else {
|
||||
playPauseButton.setImageResource(R.drawable.ic_play_arrow_white_64dp);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -51,6 +51,7 @@ import code.name.monkey.retromusic.model.Genre;
|
|||
import code.name.monkey.retromusic.model.Playlist;
|
||||
import code.name.monkey.retromusic.model.Song;
|
||||
import code.name.monkey.retromusic.model.lyrics.AbsSynchronizedLyrics;
|
||||
import code.name.monkey.retromusic.service.MusicService;
|
||||
|
||||
|
||||
public class MusicUtil {
|
||||
|
@ -408,6 +409,7 @@ public class MusicUtil {
|
|||
PlaylistsUtil.addToPlaylist(context, song, getOrCreateFavoritesPlaylist(context).id,
|
||||
false);
|
||||
}
|
||||
context.sendBroadcast(new Intent(MusicService.FAVORITE_STATE_CHANGED));
|
||||
}
|
||||
|
||||
public static boolean isFavoritePlaylist(@NonNull final Context context,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue