From 85108be6869aa9a4f8704d52ea182d800900c6ed Mon Sep 17 00:00:00 2001 From: Tonelico Date: Fri, 18 Aug 2017 05:05:31 -0700 Subject: [PATCH 1/2] Android O Notification Building Fix (#655) -Added simple notification channel for Android O. -Fixes notification building failure for background and popup player on Android O. -Reduce notification channel importance to low to avoid making noise on every notification update. --- app/src/main/java/org/schabi/newpipe/App.java | 24 +++++++++++++++++++ .../newpipe/player/BackgroundPlayer.java | 4 ++-- .../newpipe/player/PopupVideoPlayer.java | 6 +++-- app/src/main/res/values/strings.xml | 4 ++++ 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/App.java b/app/src/main/java/org/schabi/newpipe/App.java index 94a3daf4f..09b126104 100644 --- a/app/src/main/java/org/schabi/newpipe/App.java +++ b/app/src/main/java/org/schabi/newpipe/App.java @@ -1,7 +1,10 @@ package org.schabi.newpipe; import android.app.Application; +import android.app.NotificationChannel; +import android.app.NotificationManager; import android.content.Context; +import android.os.Build; import com.facebook.stetho.Stetho; import com.nostra13.universalimageloader.core.ImageLoader; @@ -89,6 +92,8 @@ public class App extends Application { SettingsActivity.initSettings(this); ThemeHelper.setTheme(getApplicationContext()); + + initNotificationChannel(); } /** @@ -112,4 +117,23 @@ public class App extends Application { public static boolean isUsingTor() { return useTor; } + + public void initNotificationChannel() { + if (Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.O) { + return; + } + + final String id = getString(R.string.notification_channel_id); + final CharSequence name = getString(R.string.notification_channel_name); + final String description = getString(R.string.notification_channel_description); + + // Keep this below DEFAULT to avoid making noise on every notification update + final int importance = NotificationManager.IMPORTANCE_LOW; + + NotificationChannel mChannel = new NotificationChannel(id, name, importance); + mChannel.setDescription(description); + + NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); + mNotificationManager.createNotificationChannel(mChannel); + } } diff --git a/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java b/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java index d41fa1ef7..2d11b355c 100644 --- a/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java @@ -145,13 +145,13 @@ public class BackgroundPlayer extends Service { setupNotification(notRemoteView); setupNotification(bigNotRemoteView); - NotificationCompat.Builder builder = new NotificationCompat.Builder(this) + NotificationCompat.Builder builder = new NotificationCompat.Builder(this, getString(R.string.notification_channel_id)) .setOngoing(true) .setSmallIcon(R.drawable.ic_play_circle_filled_white_24dp) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setCustomContentView(notRemoteView) .setCustomBigContentView(bigNotRemoteView); - if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) builder.setPriority(Notification.PRIORITY_MAX); + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) builder.setPriority(NotificationCompat.PRIORITY_MAX); return builder; } diff --git a/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java b/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java index cfb1a5c81..7fb497447 100644 --- a/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java @@ -168,9 +168,11 @@ public class PopupVideoPlayer extends Service { float defaultSize = getResources().getDimension(R.dimen.popup_default_width); popupWidth = popupRememberSizeAndPos ? sharedPreferences.getFloat(POPUP_SAVED_WIDTH, defaultSize) : defaultSize; + final int layoutParamType = Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.O ? WindowManager.LayoutParams.TYPE_PHONE : WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY; + windowLayoutParams = new WindowManager.LayoutParams( (int) popupWidth, (int) getMinimumVideoHeight(popupWidth), - WindowManager.LayoutParams.TYPE_PHONE, + layoutParamType, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, PixelFormat.TRANSLUCENT); windowLayoutParams.gravity = Gravity.LEFT | Gravity.TOP; @@ -225,7 +227,7 @@ public class PopupVideoPlayer extends Service { break; } - return new NotificationCompat.Builder(this) + return new NotificationCompat.Builder(this, getString(R.string.notification_channel_id)) .setOngoing(true) .setSmallIcon(R.drawable.ic_play_arrow_white) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c26f5a9dd..19acddee7 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -117,6 +117,10 @@ Resizing Best resolution + newpipe + NewPipe Notification + Notifications For NewPipe Background and Popup Players + Error Network error From 2b2e954b84e2f2ccb78a293ccfc674d4d4cf3375 Mon Sep 17 00:00:00 2001 From: John Zhen M Date: Fri, 18 Aug 2017 11:07:57 -0700 Subject: [PATCH 2/2] -Updated ExoPlayer to r2.5.1. -Fixes some more deprecations due to Exoplayer and Android O notification updates. --- app/build.gradle | 2 +- .../newpipe/player/BackgroundPlayer.java | 5 ++++ .../org/schabi/newpipe/player/BasePlayer.java | 23 +++++++++++-------- .../newpipe/player/MainVideoPlayer.java | 5 ++++ .../newpipe/player/PopupVideoPlayer.java | 6 ++++- .../schabi/newpipe/player/VideoPlayer.java | 3 ++- .../giga/service/DownloadManagerService.java | 2 +- 7 files changed, 32 insertions(+), 14 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index a110e36e2..bfd37e542 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -67,7 +67,7 @@ dependencies { compile 'de.hdodenhof:circleimageview:2.0.0' compile 'com.github.nirhart:parallaxscroll:1.0' compile 'com.nononsenseapps:filepicker:3.0.0' - compile 'com.google.android.exoplayer:exoplayer:r2.4.2' + compile 'com.google.android.exoplayer:exoplayer:r2.5.1' debugCompile 'com.facebook.stetho:stetho:1.5.0' debugCompile 'com.facebook.stetho:stetho-urlconnection:1.5.0' diff --git a/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java b/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java index 2d11b355c..b52c2e09d 100644 --- a/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java @@ -342,6 +342,11 @@ public class BackgroundPlayer extends Service { // Disable default behavior } + @Override + public void onRepeatModeChanged(int i) { + + } + @Override public void destroy() { super.destroy(); diff --git a/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java b/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java index 8c2e5c6b8..2b837cc7e 100644 --- a/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java @@ -19,10 +19,12 @@ import android.view.View; import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.DefaultLoadControl; +import com.google.android.exoplayer2.DefaultRenderersFactory; import com.google.android.exoplayer2.ExoPlaybackException; -import com.google.android.exoplayer2.ExoPlayer; import com.google.android.exoplayer2.ExoPlayerFactory; import com.google.android.exoplayer2.PlaybackParameters; +import com.google.android.exoplayer2.Player; +import com.google.android.exoplayer2.RenderersFactory; import com.google.android.exoplayer2.SimpleExoPlayer; import com.google.android.exoplayer2.Timeline; import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory; @@ -62,7 +64,7 @@ import java.util.concurrent.atomic.AtomicBoolean; * @author mauriciocolli */ @SuppressWarnings({"WeakerAccess", "unused"}) -public abstract class BasePlayer implements ExoPlayer.EventListener, AudioManager.OnAudioFocusChangeListener { +public abstract class BasePlayer implements Player.EventListener, AudioManager.OnAudioFocusChangeListener { public static final boolean DEBUG = false; public static final String TAG = "BasePlayer"; @@ -158,7 +160,8 @@ public abstract class BasePlayer implements ExoPlayer.EventListener, AudioManage DefaultTrackSelector defaultTrackSelector = new DefaultTrackSelector(trackSelectionFactory); DefaultLoadControl loadControl = new DefaultLoadControl(); - simpleExoPlayer = ExoPlayerFactory.newSimpleInstance(context, defaultTrackSelector, loadControl); + final RenderersFactory renderFactory = new DefaultRenderersFactory(context); + simpleExoPlayer = ExoPlayerFactory.newSimpleInstance(renderFactory, defaultTrackSelector, loadControl); simpleExoPlayer.addListener(this); } @@ -220,7 +223,7 @@ public abstract class BasePlayer implements ExoPlayer.EventListener, AudioManage isPrepared = false; mediaSource = buildMediaSource(url, format); - if (simpleExoPlayer.getPlaybackState() != ExoPlayer.STATE_IDLE) simpleExoPlayer.stop(); + if (simpleExoPlayer.getPlaybackState() != Player.STATE_IDLE) simpleExoPlayer.stop(); if (videoStartPos > 0) simpleExoPlayer.seekTo(videoStartPos); simpleExoPlayer.prepare(mediaSource); simpleExoPlayer.setPlayWhenReady(autoPlay); @@ -477,13 +480,13 @@ public abstract class BasePlayer implements ExoPlayer.EventListener, AudioManage } switch (playbackState) { - case ExoPlayer.STATE_IDLE: // 1 + case Player.STATE_IDLE: // 1 isPrepared = false; break; - case ExoPlayer.STATE_BUFFERING: // 2 + case Player.STATE_BUFFERING: // 2 if (isPrepared && getCurrentState() != STATE_LOADING) changeState(STATE_BUFFERING); break; - case ExoPlayer.STATE_READY: //3 + case Player.STATE_READY: //3 if (!isPrepared) { isPrepared = true; onPrepared(playWhenReady); @@ -492,7 +495,7 @@ public abstract class BasePlayer implements ExoPlayer.EventListener, AudioManage if (currentState == STATE_PAUSED_SEEK) break; changeState(playWhenReady ? STATE_PLAYING : STATE_PAUSED); break; - case ExoPlayer.STATE_ENDED: // 4 + case Player.STATE_ENDED: // 4 changeState(STATE_COMPLETED); isPrepared = false; break; @@ -569,7 +572,7 @@ public abstract class BasePlayer implements ExoPlayer.EventListener, AudioManage } public boolean isPlaying() { - return simpleExoPlayer.getPlaybackState() == ExoPlayer.STATE_READY && simpleExoPlayer.getPlayWhenReady(); + return simpleExoPlayer.getPlaybackState() == Player.STATE_READY && simpleExoPlayer.getPlayWhenReady(); } /*////////////////////////////////////////////////////////////////////////// @@ -715,7 +718,7 @@ public abstract class BasePlayer implements ExoPlayer.EventListener, AudioManage } public boolean isCompleted() { - return simpleExoPlayer != null && simpleExoPlayer.getPlaybackState() == ExoPlayer.STATE_ENDED; + return simpleExoPlayer != null && simpleExoPlayer.getPlaybackState() == Player.STATE_ENDED; } public boolean isPrepared() { diff --git a/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java b/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java index 547d6447e..6706ab4ef 100644 --- a/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java @@ -422,6 +422,11 @@ public class MainVideoPlayer extends Activity { public ImageButton getPlayPauseButton() { return playPauseButton; } + + @Override + public void onRepeatModeChanged(int i) { + + } } private class MySimpleOnGestureListener extends GestureDetector.SimpleOnGestureListener implements View.OnTouchListener { diff --git a/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java b/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java index 7fb497447..f40843726 100644 --- a/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java @@ -431,7 +431,7 @@ public class PopupVideoPlayer extends Service { hideControls(100, 0); } } -/*////////////////////////////////////////////////////////////////////////// + /*////////////////////////////////////////////////////////////////////////// // Broadcast Receiver //////////////////////////////////////////////////////////////////////////*/ @@ -511,6 +511,10 @@ public class PopupVideoPlayer extends Service { public TextView getResizingIndicator() { return resizingIndicator; } + + @Override + public void onRepeatModeChanged(int i) { + } } private class MySimpleOnGestureListener extends GestureDetector.SimpleOnGestureListener implements View.OnTouchListener { diff --git a/app/src/main/java/org/schabi/newpipe/player/VideoPlayer.java b/app/src/main/java/org/schabi/newpipe/player/VideoPlayer.java index c16acd766..39e94471f 100644 --- a/app/src/main/java/org/schabi/newpipe/player/VideoPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/VideoPlayer.java @@ -27,6 +27,7 @@ import android.widget.SeekBar; import android.widget.TextView; import com.google.android.exoplayer2.ExoPlayer; +import com.google.android.exoplayer2.Player; import com.google.android.exoplayer2.SimpleExoPlayer; import com.google.android.exoplayer2.source.ExtractorMediaSource; import com.google.android.exoplayer2.source.MediaSource; @@ -52,7 +53,7 @@ import static org.schabi.newpipe.util.AnimationUtils.animateView; * @author mauriciocolli */ @SuppressWarnings({"WeakerAccess", "unused"}) -public abstract class VideoPlayer extends BasePlayer implements SimpleExoPlayer.VideoListener, SeekBar.OnSeekBarChangeListener, View.OnClickListener, ExoPlayer.EventListener, PopupMenu.OnMenuItemClickListener, PopupMenu.OnDismissListener { +public abstract class VideoPlayer extends BasePlayer implements SimpleExoPlayer.VideoListener, SeekBar.OnSeekBarChangeListener, View.OnClickListener, Player.EventListener, PopupMenu.OnMenuItemClickListener, PopupMenu.OnDismissListener { public static final boolean DEBUG = BasePlayer.DEBUG; public final String TAG; diff --git a/app/src/main/java/us/shandian/giga/service/DownloadManagerService.java b/app/src/main/java/us/shandian/giga/service/DownloadManagerService.java index 81d23a0ae..d60ae86ab 100755 --- a/app/src/main/java/us/shandian/giga/service/DownloadManagerService.java +++ b/app/src/main/java/us/shandian/giga/service/DownloadManagerService.java @@ -98,7 +98,7 @@ public class DownloadManagerService extends Service { Drawable icon = ContextCompat.getDrawable(this, R.mipmap.ic_launcher); - Builder builder = new Builder(this) + Builder builder = new Builder(this, getString(R.string.notification_channel_id)) .setContentIntent(pendingIntent) .setSmallIcon(android.R.drawable.stat_sys_download) .setLargeIcon(((BitmapDrawable) icon).getBitmap())