Skip to content

Commit

Permalink
Show set bookmark action in notification
Browse files Browse the repository at this point in the history
Addresses #119
  • Loading branch information
flackbash committed Aug 22, 2021
1 parent 1d3914c commit 5419bc7
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public class MediaPlayerService extends Service implements MediaPlayer.OnComplet
public static final String ACTION_BACKWARD = "com.prangesoftwaresolutions.audioanchor.ACTION_BACKWARD";
public static final String ACTION_FORWARD = "com.prangesoftwaresolutions.audioanchor.ACTION_FORWARD";
public static final String ACTION_STOP = "com.prangesoftwaresolutions.audioanchor.ACTION_STOP";
public static final String ACTION_BOOKMARK = "com.prangesoftwaresolutions.audioanchor.ACTION_BOOKMARK";

public static final String SERVICE_PLAY_STATUS_CHANGE = "com.prangesoftwaresolutions.audioanchor.SERVICE_PLAY_STATUS_CHANGE";
public static final String SERVICE_MESSAGE_PLAY_STATUS = "com.prangesoftwaresolutions.audioanchor.SERVICE_MESSAGE_PLAYING";
Expand Down Expand Up @@ -671,7 +672,7 @@ private void buildNotification() {
// Attach our MediaSession token
.setMediaSession(mediaSession.getSessionToken())
// Show our playback controls in the compat view
.setShowActionsInCompactView(0, 1, 2))
.setShowActionsInCompactView(1, 2, 3))
// Set the notification color
.setColor(getResources().getColor(R.color.colorAccent))
// Set the large and small icons
Expand All @@ -689,6 +690,7 @@ private void buildNotification() {
// Make notification non-removable if the track is currently playing
.setOngoing(title.equals(getString(R.string.button_pause)))
// Add playback actions
.addAction(R.drawable.ic_media_bookmark, getString(R.string.button_bookmark), playbackAction(4))
.addAction(R.drawable.ic_media_backward, getString(R.string.button_backward), playbackAction(3))
.addAction(notificationAction, title, play_pauseAction)
.addAction(R.drawable.ic_media_forward, getString(R.string.button_forward), playbackAction(2));
Expand Down Expand Up @@ -720,6 +722,10 @@ private PendingIntent playbackAction(int actionNumber) {
// Skip backward
playbackActionIntent.setAction(ACTION_BACKWARD);
return PendingIntent.getService(this, actionNumber, playbackActionIntent, 0);
case 4:
// Set bookmark
playbackActionIntent.setAction(ACTION_BOOKMARK);
return PendingIntent.getService(this, actionNumber, playbackActionIntent, 0);
default:
break;
}
Expand Down Expand Up @@ -748,9 +754,17 @@ private void handleIncomingActions(Intent playbackAction) {
forward(30);
} else if (actionString.equalsIgnoreCase(ACTION_BACKWARD)) {
backward(30);
} else if (actionString.equalsIgnoreCase(ACTION_BOOKMARK)) {
setBookmark();
}
}

private void setBookmark() {
String title = getResources().getString(R.string.untitled_bookmark);
Bookmark bookmark = new Bookmark(title, getCurrentPosition(), mActiveAudio.getID());
bookmark.insertIntoDB(this);
}

public boolean isPlaying() {
if (mMediaPlayer != null) {
return mMediaPlayer.isPlaying();
Expand Down
15 changes: 15 additions & 0 deletions app/src/main/res/drawable-anydpi-v24/ic_media_bookmark.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="#FFFFFF">
<group android:scaleX="1.127451"
android:scaleY="1.127451"
android:translateX="-1.5294118"
android:translateY="-1.5294118">
<path
android:fillColor="@android:color/white"
android:pathData="M17,3L7,3c-1.1,0 -1.99,0.9 -1.99,2L5,21l7,-3 7,3L19,5c0,-1.1 -0.9,-2 -2,-2zM17,18l-5,-2.18L7,18L7,5h10v13z"/>
</group>
</vector>
Binary file added app/src/main/res/drawable-hdpi/ic_media_bookmark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-mdpi/ic_media_bookmark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<string name="button_play">Play</string>
<string name="button_backward">Backward</string>
<string name="button_forward">Forward</string>
<string name="button_bookmark">Bookmark</string>

<!-- Toast messages -->
<string name="no_albums">It\'s a bit empty here. Start by adding a directory to your library.</string>
Expand Down

0 comments on commit 5419bc7

Please sign in to comment.