Skip to content

Commit

Permalink
feat: Add action button for quick hide in notification (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
deltazefiro committed Apr 8, 2024
1 parent f1cf0ba commit a2d014d
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions app/src/main/java/deltazero/amarok/QuickHideService.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.hjq.window.EasyWindow;
import com.hjq.window.draggable.SpringBackDraggable;

import deltazero.amarok.receivers.ActionReceiver;
import deltazero.amarok.ui.MainActivity;

public class QuickHideService extends LifecycleService {
Expand All @@ -31,6 +32,7 @@ public class QuickHideService extends LifecycleService {
private ImageView ivPanicButton;

private PendingIntent activityPendingIntent;
private NotificationCompat.Action action;
private static final String CHANNEL_ID = "QUICK_HIDE_CHANNEL";
private static final int NOTIFICATION_ID = 1;

Expand All @@ -45,6 +47,14 @@ public void onCreate() {
getString(R.string.notification_channel_name), NotificationManager.IMPORTANCE_DEFAULT);
getSystemService(NotificationManager.class).createNotificationChannel(channel);

Intent actionIntent = new Intent(this, ActionReceiver.class);
actionIntent.setAction("deltazero.amarok.HIDE");
PendingIntent actionPendingIntent = PendingIntent.getBroadcast(this, 1,
actionIntent, PendingIntent.FLAG_IMMUTABLE);
action = new NotificationCompat.Action.Builder(
R.drawable.ic_paw,
getString(R.string.hide), actionPendingIntent).build();

activityPendingIntent = PendingIntent.getActivity(this, 0,
new Intent(this, MainActivity.class), PendingIntent.FLAG_IMMUTABLE);

Expand All @@ -70,6 +80,7 @@ public int onStartCommand(Intent intent, int flags, int startId) {
.setSmallIcon(R.drawable.ic_paw)
.setContentIntent(activityPendingIntent)
.setOngoing(true)
.addAction(action)
.build();

if (Build.VERSION.SDK_INT >= 34) {
Expand Down

0 comments on commit a2d014d

Please sign in to comment.