1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-11-19 00:04:56 +00:00

-Added back notification on popup player.

This commit is contained in:
John Zhen M 2017-09-09 16:33:51 -07:00 committed by John Zhen Mo
parent c24d46cf0f
commit 9413856463

View File

@ -119,7 +119,10 @@ public class PopupVideoPlayer extends Service {
private float minimumWidth, minimumHeight; private float minimumWidth, minimumHeight;
private float maximumWidth, maximumHeight; private float maximumWidth, maximumHeight;
private final String setAlphaMethodName = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) ? "setImageAlpha" : "setAlpha";
private NotificationManager notificationManager; private NotificationManager notificationManager;
private NotificationCompat.Builder notBuilder;
private RemoteViews notRemoteView;
private VideoPlayerImpl playerImpl; private VideoPlayerImpl playerImpl;
private Disposable currentWorker; private Disposable currentWorker;
@ -241,6 +244,58 @@ public class PopupVideoPlayer extends Service {
windowManager.addView(rootView, windowLayoutParams); windowManager.addView(rootView, windowLayoutParams);
} }
/*//////////////////////////////////////////////////////////////////////////
// Notification
//////////////////////////////////////////////////////////////////////////*/
private NotificationCompat.Builder createNotification() {
notRemoteView = new RemoteViews(BuildConfig.APPLICATION_ID, R.layout.player_popup_notification);
notRemoteView.setTextViewText(R.id.notificationSongName, playerImpl.getVideoTitle());
notRemoteView.setTextViewText(R.id.notificationArtist, playerImpl.getUploaderName());
notRemoteView.setOnClickPendingIntent(R.id.notificationPlayPause,
PendingIntent.getBroadcast(this, NOTIFICATION_ID, new Intent(ACTION_PLAY_PAUSE), PendingIntent.FLAG_UPDATE_CURRENT));
notRemoteView.setOnClickPendingIntent(R.id.notificationStop,
PendingIntent.getBroadcast(this, NOTIFICATION_ID, new Intent(ACTION_CLOSE), PendingIntent.FLAG_UPDATE_CURRENT));
notRemoteView.setOnClickPendingIntent(R.id.notificationContent,
PendingIntent.getBroadcast(this, NOTIFICATION_ID, new Intent(ACTION_OPEN_DETAIL), PendingIntent.FLAG_UPDATE_CURRENT));
notRemoteView.setOnClickPendingIntent(R.id.notificationRepeat,
PendingIntent.getBroadcast(this, NOTIFICATION_ID, new Intent(ACTION_REPEAT), PendingIntent.FLAG_UPDATE_CURRENT));
switch (playerImpl.simpleExoPlayer.getRepeatMode()) {
case Player.REPEAT_MODE_OFF:
notRemoteView.setInt(R.id.notificationRepeat, setAlphaMethodName, 77);
break;
case Player.REPEAT_MODE_ONE:
//todo change image
notRemoteView.setInt(R.id.notificationRepeat, setAlphaMethodName, 168);
break;
case Player.REPEAT_MODE_ALL:
notRemoteView.setInt(R.id.notificationRepeat, setAlphaMethodName, 255);
break;
}
return new NotificationCompat.Builder(this, getString(R.string.notification_channel_id))
.setOngoing(true)
.setSmallIcon(R.drawable.ic_play_arrow_white)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setContent(notRemoteView);
}
/**
* Updates the notification, and the play/pause button in it.
* Used for changes on the remoteView
*
* @param drawableId if != -1, sets the drawable with that id on the play/pause button
*/
private void updateNotification(int drawableId) {
if (DEBUG) Log.d(TAG, "updateNotification() called with: drawableId = [" + drawableId + "]");
if (notBuilder == null || notRemoteView == null) return;
if (drawableId != -1) notRemoteView.setImageViewResource(R.id.notificationPlayPause, drawableId);
notificationManager.notify(NOTIFICATION_ID, notBuilder.build());
}
/*////////////////////////////////////////////////////////////////////////// /*//////////////////////////////////////////////////////////////////////////
// Misc // Misc
//////////////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////////////*/
@ -341,11 +396,20 @@ public class PopupVideoPlayer extends Service {
@Override @Override
public void destroy() { public void destroy() {
super.destroy(); super.destroy();
if (notRemoteView != null) notRemoteView.setImageViewBitmap(R.id.notificationCover, null);
} }
@Override @Override
public void onThumbnailReceived(Bitmap thumbnail) { public void onThumbnailReceived(Bitmap thumbnail) {
super.onThumbnailReceived(thumbnail); super.onThumbnailReceived(thumbnail);
if (thumbnail != null) {
// rebuild notification here since remote view does not release bitmaps, causing memory leaks
notBuilder = createNotification();
if (notRemoteView != null) notRemoteView.setImageViewBitmap(R.id.notificationCover, thumbnail);
updateNotification(-1);
}
} }
@Override @Override
@ -371,6 +435,27 @@ public class PopupVideoPlayer extends Service {
stopSelf(); stopSelf();
} }
@Override
public void onRepeatClicked() {
super.onRepeatClicked();
switch (simpleExoPlayer.getRepeatMode()) {
case Player.REPEAT_MODE_OFF:
// Drawable didn't work on low API :/
//notRemoteView.setImageViewResource(R.id.notificationRepeat, R.drawable.ic_repeat_disabled_white);
// Set the icon to 30% opacity - 255 (max) * .3
notRemoteView.setInt(R.id.notificationRepeat, setAlphaMethodName, 77);
break;
case Player.REPEAT_MODE_ONE:
// todo change image
notRemoteView.setInt(R.id.notificationRepeat, setAlphaMethodName, 168);
break;
case Player.REPEAT_MODE_ALL:
notRemoteView.setInt(R.id.notificationRepeat, setAlphaMethodName, 255);
break;
}
updateNotification(-1);
}
@Override @Override
public void onDismiss(PopupMenu menu) { public void onDismiss(PopupMenu menu) {
super.onDismiss(menu); super.onDismiss(menu);
@ -441,32 +526,38 @@ public class PopupVideoPlayer extends Service {
@Override @Override
public void onLoading() { public void onLoading() {
super.onLoading(); super.onLoading();
updateNotification(R.drawable.ic_play_arrow_white);
} }
@Override @Override
public void onPlaying() { public void onPlaying() {
super.onPlaying(); super.onPlaying();
updateNotification(R.drawable.ic_pause_white);
} }
@Override @Override
public void onBuffering() { public void onBuffering() {
super.onBuffering(); super.onBuffering();
updateNotification(R.drawable.ic_play_arrow_white);
} }
@Override @Override
public void onPaused() { public void onPaused() {
super.onPaused(); super.onPaused();
updateNotification(R.drawable.ic_play_arrow_white);
showAndAnimateControl(R.drawable.ic_play_arrow_white, false); showAndAnimateControl(R.drawable.ic_play_arrow_white, false);
} }
@Override @Override
public void onPausedSeek() { public void onPausedSeek() {
super.onPausedSeek(); super.onPausedSeek();
updateNotification(R.drawable.ic_play_arrow_white);
} }
@Override @Override
public void onCompleted() { public void onCompleted() {
super.onCompleted(); super.onCompleted();
updateNotification(R.drawable.ic_replay_white);
showAndAnimateControl(R.drawable.ic_replay_white, false); showAndAnimateControl(R.drawable.ic_replay_white, false);
} }