forked from TeamNewPipe/NewPipe
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request TeamNewPipe#10712 from Stypox/notification-actions…
…-api-33-2 [Android 13+] Restore support of custom notification actions
- Loading branch information
Showing
9 changed files
with
684 additions
and
374 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
app/src/main/java/org/schabi/newpipe/player/mediasession/SessionConnectorActionProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package org.schabi.newpipe.player.mediasession; | ||
|
||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.os.Bundle; | ||
import android.support.v4.media.session.PlaybackStateCompat; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
|
||
import com.google.android.exoplayer2.Player; | ||
import com.google.android.exoplayer2.ext.mediasession.MediaSessionConnector; | ||
|
||
import org.schabi.newpipe.player.notification.NotificationActionData; | ||
|
||
import java.lang.ref.WeakReference; | ||
|
||
public class SessionConnectorActionProvider implements MediaSessionConnector.CustomActionProvider { | ||
|
||
private final NotificationActionData data; | ||
@NonNull | ||
private final WeakReference<Context> context; | ||
|
||
public SessionConnectorActionProvider(final NotificationActionData notificationActionData, | ||
@NonNull final Context context) { | ||
this.data = notificationActionData; | ||
this.context = new WeakReference<>(context); | ||
} | ||
|
||
@Override | ||
public void onCustomAction(@NonNull final Player player, | ||
@NonNull final String action, | ||
@Nullable final Bundle extras) { | ||
final Context actualContext = context.get(); | ||
if (actualContext != null) { | ||
actualContext.sendBroadcast(new Intent(action)); | ||
} | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public PlaybackStateCompat.CustomAction getCustomAction(@NonNull final Player player) { | ||
return new PlaybackStateCompat.CustomAction.Builder( | ||
data.action(), data.name(), data.icon() | ||
).build(); | ||
} | ||
} |
Oops, something went wrong.