Added favorite icon to notifications

This commit is contained in:
h4h13 2019-08-04 21:26:32 +05:30
parent e8cb0f5274
commit 6fde42ba11
16 changed files with 216 additions and 24 deletions

View file

@ -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()

View file

@ -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);

View file

@ -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);
}

View file

@ -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();

View file

@ -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

View file

@ -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,

View file

@ -1,4 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (c) 2019 Hemanth Savarala.
~
~ Licensed under the GNU General Public License v3
~
~ This is free software: you can redistribute it and/or modify it under
~ the terms of the GNU General Public License as published by
~ the Free Software Foundation either version 3 of the License, or (at your option) any later version.
~
~ This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
~ without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
~ See the GNU General Public License for more details.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"

View file

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (c) 2019 Hemanth Savarala.
~
~ Licensed under the GNU General Public License v3
~
~ This is free software: you can redistribute it and/or modify it under
~ the terms of the GNU General Public License as published by
~ the Free Software Foundation either version 3 of the License, or (at your option) any later version.
~
~ This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
~ without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
~ See the GNU General Public License for more details.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="48dp"
android:height="48dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@color/md_white_1000"
android:pathData="M8 19c1.1 0 2-0.9 2-2V7c0-1.1-0.9-2-2-2s-2 0.9-2 2v10c0 1.1 0.9 2 2 2zm6-12v10c0 1.1 0.9 2 2 2s2-0.9 2-2V7c0-1.1-0.9-2-2-2s-2 0.9-2 2z" />
</vector>

View file

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (c) 2019 Hemanth Savarala.
~
~ Licensed under the GNU General Public License v3
~
~ This is free software: you can redistribute it and/or modify it under
~ the terms of the GNU General Public License as published by
~ the Free Software Foundation either version 3 of the License, or (at your option) any later version.
~
~ This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
~ without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
~ See the GNU General Public License for more details.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="48dp"
android:height="48dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@color/md_white_1000"
android:pathData="M8 6.82v10.36c0 0.79 0.87 1.27 1.54 0.84 l8.14-5.18c0.62-0.39 0.62 -1.29 0-1.69L9.54 5.98C8.87 5.55 8 6.03 8 6.82z" />
</vector>

View file

@ -0,0 +1,26 @@
<!--
~ Copyright (c) 2019 Hemanth Savarala.
~
~ Licensed under the GNU General Public License v3
~
~ This is free software: you can redistribute it and/or modify it under
~ the terms of the GNU General Public License as published by
~ the Free Software Foundation either version 3 of the License, or (at your option) any later version.
~
~ This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
~ without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
~ See the GNU General Public License for more details.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M12,2A10,10 0,1 1,2 12,10 10,0 0,1 12,2m0,-2a12,12 0,1 0,12 12A12,12 0,0 0,12 0z" />
<path
android:fillColor="#FFFFFFFF"
android:pathData="M8.61,8.61h6.79v2l2.71,-2.71 -2.72,-2.69v2L7.25,7.21v4.07h1.36L8.61,8.61zM15.4,15.4L8.61,15.4v-2l-2.72,2.67 2.71,2.71v-2h8.14v-4.1h-1.35v2.71z" />
</vector>

View file

@ -0,0 +1,23 @@
<!--
~ Copyright (c) 2019 Hemanth Savarala.
~
~ Licensed under the GNU General Public License v3
~
~ This is free software: you can redistribute it and/or modify it under
~ the terms of the GNU General Public License as published by
~ the Free Software Foundation either version 3 of the License, or (at your option) any later version.
~
~ This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
~ without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
~ See the GNU General Public License for more details.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FF000000"
android:pathData="M14.3,13.1l-1.1,1.1l2.5,2.5L14,18.5h4.5V14l-1.7,1.7L14.3,13.1M14,5.5l1.7,1.7L5.5,17.4l1.1,1.1L16.8,8.3l1.7,1.7V5.5M10.9,9.7L6.6,5.5L5.5,6.6l4.2,4.2L10.9,9.7z" />
</vector>

View file

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (c) 2019 Hemanth Savarala.
~
~ Licensed under the GNU General Public License v3
~
~ This is free software: you can redistribute it and/or modify it under
~ the terms of the GNU General Public License as published by
~ the Free Software Foundation either version 3 of the License, or (at your option) any later version.
~
~ This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
~ without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
~ See the GNU General Public License for more details.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FF000000"
android:pathData="M14.3,13.1l-1.1,1.1l2.5,2.5L14,18.5h4.5V14l-1.7,1.7L14.3,13.1M14,5.5l1.7,1.7L5.5,17.4l1.1,1.1L16.8,8.3l1.7,1.7V5.5M10.9,9.7L6.6,5.5L5.5,6.6l4.2,4.2L10.9,9.7z" />
<path
android:fillColor="#00000000"
android:pathData="M0.9,12a11.1,11 0,1 0,22.2 0a11.1,11 0,1 0,-22.2 0z"
android:strokeWidth="1.6"
android:strokeColor="#000000" />
</vector>

View file

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (c) 2019 Hemanth Savarala.
~
~ Licensed under the GNU General Public License v3
~
~ This is free software: you can redistribute it and/or modify it under
~ the terms of the GNU General Public License as published by
~ the Free Software Foundation either version 3 of the License, or (at your option) any later version.
~
~ This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
~ without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
~ See the GNU General Public License for more details.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="@dimen/icon_notification_dimen"
android:height="@dimen/icon_notification_dimen"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@color/md_white_1000"
android:pathData="M7.58 16.89l5.77-4.07c0.56-0.4 0.56 -1.24 0-1.63L7.58 7.11C6.91 6.65 6 7.12 6 7.93v8.14c0 0.81 0.91 1.28 1.58 0.82 zM16 7v10c0 0.55 0.45 1 1 1s1-0.45 1-1V7c0-0.55-0.45-1-1-1s-1 0.45-1 1z" />
</vector>

View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="@dimen/icon_notification_dimen"
android:height="@dimen/icon_notification_dimen"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@color/md_white_1000"
android:pathData="M7 6c0.55 0 1 0.45 1 1v10c0 0.55-0.45 1-1 1s-1-0.45-1-1V7c0-0.55 0.45 -1 1-1zm3.66 6.82l5.77 4.07c0.66 0.47 1.58-0.01 1.58-0.82V7.93c0-0.81-0.91-1.28-1.58-0.82l-5.77 4.07c-0.57 0.4 -0.57 1.24 0 1.64z" />
</vector>

View file

@ -187,7 +187,7 @@
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="?attr/roundSelector"
app:srcCompat="@drawable/ic_pause_white_big"
app:srcCompat="@drawable/ic_pause_white_64dp"
tools:tint="@color/md_black_1000" />
</RelativeLayout>