diff --git a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java index f277c13d267..437490544e2 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java @@ -11,7 +11,6 @@ import android.text.Html; import android.text.Spanned; import android.text.TextUtils; -import android.text.method.LinkMovementMethod; import android.text.util.Linkify; import android.util.DisplayMetrics; import android.util.Log; diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java index 37082b6712c..c87096712de 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java @@ -16,7 +16,6 @@ import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AppCompatActivity; import androidx.recyclerview.widget.GridLayoutManager; -import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import org.schabi.newpipe.R; @@ -35,7 +34,6 @@ import org.schabi.newpipe.util.OnClickGesture; import org.schabi.newpipe.util.StateSaver; import org.schabi.newpipe.util.StreamDialogEntry; -import org.schabi.newpipe.views.NewPipeRecyclerView; import org.schabi.newpipe.views.SuperScrollLayoutManager; import java.util.List; @@ -166,13 +164,15 @@ public void readFrom(@NonNull final Queue savedObjects) throws Exception restoreFocus((Integer) savedObjects.poll()); } - private void restoreFocus(Integer position) { + private void restoreFocus(final Integer position) { if (position == null || position < 0) { return; } itemsList.post(() -> { - RecyclerView.ViewHolder focusedHolder = itemsList.findViewHolderForAdapterPosition(position); + RecyclerView.ViewHolder focusedHolder = + itemsList.findViewHolderForAdapterPosition(position); + if (focusedHolder != null) { focusedHolder.itemView.requestFocus(); } diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListInfoFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListInfoFragment.java index 2a6ae180db0..aed7c4795a4 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListInfoFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListInfoFragment.java @@ -18,8 +18,6 @@ import io.reactivex.Single; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; -import io.reactivex.functions.Action; -import io.reactivex.functions.Consumer; import io.reactivex.schedulers.Schedulers; public abstract class BaseListInfoFragment diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java index ecdea4c1e90..71a530b3935 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java @@ -511,7 +511,7 @@ private void initSearchListeners() { if (isSuggestionsEnabled && errorPanelRoot.getVisibility() != View.VISIBLE) { showSuggestionsPanel(); } - if(AndroidTvUtils.isTv()){ + if (AndroidTvUtils.isTv()) { showKeyboardSearch(); } }); 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 bafd74341ea..1b8d0ccf610 100644 --- a/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java @@ -78,10 +78,8 @@ import java.io.IOException; import java.net.UnknownHostException; -import java.util.concurrent.TimeUnit; import io.reactivex.Observable; -import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.CompositeDisposable; import io.reactivex.disposables.Disposable; import io.reactivex.disposables.SerialDisposable; @@ -90,6 +88,8 @@ import static com.google.android.exoplayer2.Player.DISCONTINUITY_REASON_PERIOD_TRANSITION; import static com.google.android.exoplayer2.Player.DISCONTINUITY_REASON_SEEK; import static com.google.android.exoplayer2.Player.DISCONTINUITY_REASON_SEEK_ADJUSTMENT; +import static io.reactivex.android.schedulers.AndroidSchedulers.mainThread; +import static java.util.concurrent.TimeUnit.MILLISECONDS; /** * Base for the players, joining the common properties. @@ -304,7 +304,7 @@ public void handleIntent(final Intent intent) { final PlayQueueItem item = queue.getItem(); if (item != null && item.getRecoveryPosition() == PlayQueueItem.RECOVERY_UNSET) { stateLoader = recordManager.loadStreamState(item) - .observeOn(AndroidSchedulers.mainThread()) + .observeOn(mainThread()) .doFinally(() -> initPlayback(queue, repeatMode, playbackSpeed, playbackPitch, playbackSkipSilence, true, isMuted)) .subscribe( @@ -655,8 +655,8 @@ public void triggerProgressUpdate() { } private Disposable getProgressReactor() { - return Observable.interval(PROGRESS_LOOP_INTERVAL_MILLIS, TimeUnit.MILLISECONDS, AndroidSchedulers.mainThread()) - .observeOn(AndroidSchedulers.mainThread()) + return Observable.interval(PROGRESS_LOOP_INTERVAL_MILLIS, MILLISECONDS, mainThread()) + .observeOn(mainThread()) .subscribe(ignored -> triggerProgressUpdate(), error -> Log.e(TAG, "Progress update failure: ", error)); } @@ -1261,7 +1261,7 @@ private void savePlaybackState(final StreamInfo info, final long progress) { final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); if (prefs.getBoolean(context.getString(R.string.enable_watch_history_key), true)) { final Disposable stateSaver = recordManager.saveStreamState(info, progress) - .observeOn(AndroidSchedulers.mainThread()) + .observeOn(mainThread()) .doOnError((e) -> { if (DEBUG) { e.printStackTrace(); @@ -1281,7 +1281,7 @@ private void resetPlaybackState(final PlayQueueItem queueItem) { if (prefs.getBoolean(context.getString(R.string.enable_watch_history_key), true)) { final Disposable stateSaver = queueItem.getStream() .flatMapCompletable(info -> recordManager.saveStreamState(info, 0)) - .observeOn(AndroidSchedulers.mainThread()) + .observeOn(mainThread()) .doOnError((e) -> { if (DEBUG) { e.printStackTrace(); 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 ad20bc97426..0654bb91dea 100644 --- a/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java @@ -176,8 +176,10 @@ protected void onCreate(@Nullable final Bundle savedInstanceState) { public void onChange(final boolean selfChange) { super.onChange(selfChange); if (globalScreenOrientationLocked()) { + final String orientKey = getString(R.string.last_orientation_landscape_key); + final boolean lastOrientationWasLandscape = defaultPreferences - .getBoolean(getString(R.string.last_orientation_landscape_key), AndroidTvUtils.isTv()); + .getBoolean(orientKey, AndroidTvUtils.isTv()); setLandscape(lastOrientationWasLandscape); } else { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); @@ -216,7 +218,7 @@ protected void onNewIntent(final Intent intent) { } @Override - public boolean onKeyDown(int keyCode, KeyEvent event) { + public boolean onKeyDown(final int keyCode, final KeyEvent event) { switch (event.getKeyCode()) { default: break; @@ -258,8 +260,10 @@ protected void onResume() { super.onResume(); if (globalScreenOrientationLocked()) { + final String orientKey = getString(R.string.last_orientation_landscape_key); + boolean lastOrientationWasLandscape = defaultPreferences - .getBoolean(getString(R.string.last_orientation_landscape_key), AndroidTvUtils.isTv()); + .getBoolean(orientKey, AndroidTvUtils.isTv()); setLandscape(lastOrientationWasLandscape); } @@ -1077,7 +1081,7 @@ public void showControls(final long duration) { } @Override - public void safeHideControls(long duration, final long delay) { + public void safeHideControls(final long duration, final long delay) { if (DEBUG) { Log.d(TAG, "safeHideControls() called with: delay = [" + delay + "]"); } @@ -1085,8 +1089,9 @@ public void safeHideControls(long duration, final long delay) { View controlsRoot = getControlsRoot(); if (controlsRoot.isInTouchMode()) { getControlsVisibilityHandler().removeCallbacksAndMessages(null); - getControlsVisibilityHandler().postDelayed( - () -> animateView(controlsRoot, false, duration, 0, MainVideoPlayer.this::hideSystemUi), delay); + getControlsVisibilityHandler().postDelayed(() -> + animateView(controlsRoot, false, duration, 0, + MainVideoPlayer.this::hideSystemUi), delay); } } 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 c95a455d29b..5fb94e6c514 100644 --- a/app/src/main/java/org/schabi/newpipe/player/VideoPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/VideoPlayer.java @@ -969,7 +969,9 @@ public void showControlsThenHide() { Log.d(TAG, "showControlsThenHide() called"); } - final int hideTime = controlsRoot.isInTouchMode() ? DEFAULT_CONTROLS_HIDE_TIME : DPAD_CONTROLS_HIDE_TIME; + final int hideTime = controlsRoot.isInTouchMode() + ? DEFAULT_CONTROLS_HIDE_TIME + : DPAD_CONTROLS_HIDE_TIME; animateView(controlsRoot, true, DEFAULT_CONTROLS_DURATION, 0, () -> hideControls(DEFAULT_CONTROLS_DURATION, hideTime)); diff --git a/app/src/main/java/org/schabi/newpipe/util/AndroidTvUtils.java b/app/src/main/java/org/schabi/newpipe/util/AndroidTvUtils.java index 7b41b2beb60..f47eb71077b 100644 --- a/app/src/main/java/org/schabi/newpipe/util/AndroidTvUtils.java +++ b/app/src/main/java/org/schabi/newpipe/util/AndroidTvUtils.java @@ -7,12 +7,12 @@ import org.schabi.newpipe.App; public final class AndroidTvUtils { + private static final String AMAZON_FEATURE_FIRE_TV = "amazon.hardware.fire_tv"; + private AndroidTvUtils() { } @SuppressLint("InlinedApi") - public static boolean isTv(){ - final String AMAZON_FEATURE_FIRE_TV = "amazon.hardware.fire_tv"; - + public static boolean isTv() { PackageManager pm = App.getApp().getPackageManager(); return pm.hasSystemFeature(AMAZON_FEATURE_FIRE_TV) diff --git a/app/src/main/java/org/schabi/newpipe/views/FocusAwareCoordinator.java b/app/src/main/java/org/schabi/newpipe/views/FocusAwareCoordinator.java index b6d5b365edf..1ffb7d06946 100644 --- a/app/src/main/java/org/schabi/newpipe/views/FocusAwareCoordinator.java +++ b/app/src/main/java/org/schabi/newpipe/views/FocusAwareCoordinator.java @@ -34,11 +34,13 @@ public FocusAwareCoordinator(@NonNull final Context context) { super(context); } - public FocusAwareCoordinator(@NonNull final Context context, @Nullable final AttributeSet attrs) { + public FocusAwareCoordinator(@NonNull final Context context, + @Nullable final AttributeSet attrs) { super(context, attrs); } - public FocusAwareCoordinator(@NonNull final Context context, @Nullable final AttributeSet attrs, final int defStyleAttr) { + public FocusAwareCoordinator(@NonNull final Context context, + @Nullable final AttributeSet attrs, final int defStyleAttr) { super(context, attrs, defStyleAttr); } @@ -54,7 +56,8 @@ public void requestChildFocus(final View child, final View focused) { } else { focused.getHitRect(childFocus); - ((ViewGroup) child).offsetDescendantRectToMyCoords((View) focused.getParent(), childFocus); + ((ViewGroup) child).offsetDescendantRectToMyCoords((View) focused.getParent(), + childFocus); } requestChildRectangleOnScreen(child, childFocus, false); diff --git a/app/src/main/java/org/schabi/newpipe/views/FocusAwareDrawerLayout.java b/app/src/main/java/org/schabi/newpipe/views/FocusAwareDrawerLayout.java index dbc0ab77a43..eed2f52504b 100644 --- a/app/src/main/java/org/schabi/newpipe/views/FocusAwareDrawerLayout.java +++ b/app/src/main/java/org/schabi/newpipe/views/FocusAwareDrawerLayout.java @@ -37,18 +37,23 @@ public FocusAwareDrawerLayout(@NonNull final Context context) { super(context); } - public FocusAwareDrawerLayout(@NonNull final Context context, @Nullable final AttributeSet attrs) { + public FocusAwareDrawerLayout(@NonNull final Context context, + @Nullable final AttributeSet attrs) { super(context, attrs); } - public FocusAwareDrawerLayout(@NonNull final Context context, @Nullable final AttributeSet attrs, final int defStyle) { + public FocusAwareDrawerLayout(@NonNull final Context context, + @Nullable final AttributeSet attrs, + final int defStyle) { super(context, attrs, defStyle); } @Override - protected boolean onRequestFocusInDescendants(final int direction, final Rect previouslyFocusedRect) { - // SDK implementation of this method picks whatever visible View takes the focus first without regard to addFocusables - // if the open drawer is temporarily empty, the focus escapes outside of it, which can be confusing + protected boolean onRequestFocusInDescendants(final int direction, + final Rect previouslyFocusedRect) { + // SDK implementation of this method picks whatever visible View takes the focus first + // without regard to addFocusables. If the open drawer is temporarily empty, the focus + // escapes outside of it, which can be confusing boolean hasOpenPanels = false; @@ -74,7 +79,8 @@ protected boolean onRequestFocusInDescendants(final int direction, final Rect pr } @Override - public void addFocusables(final ArrayList views, final int direction, final int focusableMode) { + public void addFocusables(final ArrayList views, final int direction, + final int focusableMode) { boolean hasOpenPanels = false; View content = null; diff --git a/app/src/main/java/org/schabi/newpipe/views/FocusAwareSeekBar.java b/app/src/main/java/org/schabi/newpipe/views/FocusAwareSeekBar.java index ca682ac84b2..179e32e4c5b 100644 --- a/app/src/main/java/org/schabi/newpipe/views/FocusAwareSeekBar.java +++ b/app/src/main/java/org/schabi/newpipe/views/FocusAwareSeekBar.java @@ -45,7 +45,8 @@ public FocusAwareSeekBar(final Context context, final AttributeSet attrs) { super(context, attrs); } - public FocusAwareSeekBar(final Context context, final AttributeSet attrs, final int defStyleAttr) { + public FocusAwareSeekBar(final Context context, final AttributeSet attrs, + final int defStyleAttr) { super(context, attrs, defStyleAttr); } @@ -66,7 +67,8 @@ public boolean onKeyDown(final int keyCode, final KeyEvent event) { } @Override - protected void onFocusChanged(final boolean gainFocus, final int direction, final Rect previouslyFocusedRect) { + protected void onFocusChanged(final boolean gainFocus, final int direction, + final Rect previouslyFocusedRect) { super.onFocusChanged(gainFocus, direction, previouslyFocusedRect); if (!isInTouchMode() && !gainFocus) { @@ -116,7 +118,8 @@ private NestedListener(final OnSeekBarChangeListener delegate) { } @Override - public void onProgressChanged(final SeekBar seekBar, final int progress, final boolean fromUser) { + public void onProgressChanged(final SeekBar seekBar, final int progress, + final boolean fromUser) { if (!seekBar.isInTouchMode() && !isSeeking && fromUser) { isSeeking = true; diff --git a/app/src/main/java/org/schabi/newpipe/views/NewPipeRecyclerView.java b/app/src/main/java/org/schabi/newpipe/views/NewPipeRecyclerView.java index f0a2bbc3a9b..655b8681899 100644 --- a/app/src/main/java/org/schabi/newpipe/views/NewPipeRecyclerView.java +++ b/app/src/main/java/org/schabi/newpipe/views/NewPipeRecyclerView.java @@ -44,13 +44,15 @@ public NewPipeRecyclerView(@NonNull final Context context) { init(); } - public NewPipeRecyclerView(@NonNull final Context context, @Nullable final AttributeSet attrs) { + public NewPipeRecyclerView(@NonNull final Context context, + @Nullable final AttributeSet attrs) { super(context, attrs); init(); } - public NewPipeRecyclerView(@NonNull final Context context, @Nullable final AttributeSet attrs, final int defStyle) { + public NewPipeRecyclerView(@NonNull final Context context, + @Nullable final AttributeSet attrs, final int defStyle) { super(context, attrs, defStyle); init(); @@ -90,9 +92,9 @@ protected void removeDetachedView(final View child, final boolean animate) { super.removeDetachedView(child, animate); } - // we override focusSearch to always return null, so all moves moves lead to dispatchUnhandledMove() - // as added advantage, we can fully swallow some kinds of moves (such as downward movement, that - // happens when loading additional contents is in progress + // we override focusSearch to always return null, so all moves moves lead to + // dispatchUnhandledMove(). As added advantage, we can fully swallow some kinds of moves + // (such as downward movement, that happens when loading additional contents is in progress @Override public boolean dispatchUnhandledMove(final View focused, final int direction) { @@ -116,8 +118,9 @@ public boolean dispatchUnhandledMove(final View focused, final int direction) { } if (arrowScroll(direction)) { - // if RecyclerView can not yield focus, but there is still some scrolling space in indicated, - // direction, scroll some fixed amount in that direction (the same logic in ScrollView) + // if RecyclerView can not yield focus, but there is still some scrolling space in + // indicated, direction, scroll some fixed amount in that direction + // (the same logic in ScrollView) return true; } @@ -140,8 +143,8 @@ public boolean dispatchUnhandledMove(final View focused, final int direction) { private boolean tryFocusFinder(final int direction) { if (Build.VERSION.SDK_INT >= 28) { - // Android 9 implemented bunch of handy changes to focus, that render code below less useful, and - // also broke findNextFocusFromRect in way, that render this hack useless + // Android 9 implemented bunch of handy changes to focus, that render code below less + // useful, and also broke findNextFocusFromRect in way, that render this hack useless return false; } diff --git a/app/src/main/java/org/schabi/newpipe/views/SuperScrollLayoutManager.java b/app/src/main/java/org/schabi/newpipe/views/SuperScrollLayoutManager.java index 1ab96c9e576..6c4d2060328 100644 --- a/app/src/main/java/org/schabi/newpipe/views/SuperScrollLayoutManager.java +++ b/app/src/main/java/org/schabi/newpipe/views/SuperScrollLayoutManager.java @@ -39,7 +39,11 @@ public SuperScrollLayoutManager(final Context context) { } @Override - public boolean requestChildRectangleOnScreen(@NonNull final RecyclerView parent, @NonNull final View child, @NonNull final Rect rect, final boolean immediate, final boolean focusedChildVisible) { + public boolean requestChildRectangleOnScreen(@NonNull final RecyclerView parent, + @NonNull final View child, + @NonNull final Rect rect, + final boolean immediate, + final boolean focusedChildVisible) { if (!parent.isInTouchMode()) { // only activate when in directional navigation mode (Android TV etc) — fine grained // touch scrolling is better served by nested scroll system @@ -53,7 +57,8 @@ public boolean requestChildRectangleOnScreen(@NonNull final RecyclerView parent, } } - return super.requestChildRectangleOnScreen(parent, child, rect, immediate, focusedChildVisible); + return super.requestChildRectangleOnScreen(parent, child, rect, immediate, + focusedChildVisible); } @Nullable @@ -90,7 +95,9 @@ public View onInterceptFocusSearch(@NonNull final View focused, final int direct focusables.clear(); - recycler.addFocusables(focusables, direction, recycler.isInTouchMode() ? View.FOCUSABLES_TOUCH_MODE : View.FOCUSABLES_ALL); + recycler.addFocusables(focusables, direction, recycler.isInTouchMode() + ? View.FOCUSABLES_TOUCH_MODE + : View.FOCUSABLES_ALL); try { for (View view : focusables) {