From 53b3bda9095a690b41a4db5a844687699994f076 Mon Sep 17 00:00:00 2001 From: Alexander-- Date: Sat, 11 Apr 2020 09:02:22 +0659 Subject: [PATCH] Comply with Checkstyle rules --- .../fragments/detail/VideoDetailFragment.java | 1 - .../fragments/list/BaseListFragment.java | 8 +++---- .../fragments/list/BaseListInfoFragment.java | 2 -- .../fragments/list/search/SearchFragment.java | 2 +- .../org/schabi/newpipe/player/BasePlayer.java | 14 ++++++------- .../newpipe/player/MainVideoPlayer.java | 17 +++++++++------ .../schabi/newpipe/player/VideoPlayer.java | 4 +++- .../schabi/newpipe/util/AndroidTvUtils.java | 6 +++--- .../newpipe/views/FocusAwareCoordinator.java | 9 +++++--- .../newpipe/views/FocusAwareDrawerLayout.java | 18 ++++++++++------ .../newpipe/views/FocusAwareSeekBar.java | 9 +++++--- .../newpipe/views/NewPipeRecyclerView.java | 21 +++++++++++-------- .../views/SuperScrollLayoutManager.java | 13 +++++++++--- 13 files changed, 75 insertions(+), 49 deletions(-) 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 f277c13d2..437490544 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.preference.PreferenceManager; 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 37082b671..c87096712 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.annotation.NonNull; 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.NavigationHelper; 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 abstract class BaseListFragment extends BaseStateFragment 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 2a6ae180d..aed7c4795 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 icepick.State; 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 ecdea4c1e..71a530b39 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 @@ public class SearchFragment extends BaseListFragment initPlayback(queue, repeatMode, playbackSpeed, playbackPitch, playbackSkipSilence, true, isMuted)) .subscribe( @@ -655,8 +655,8 @@ public abstract class BasePlayer implements } 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 @@ public abstract class BasePlayer implements 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 @@ public abstract class BasePlayer implements 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 ad20bc974..0654bb91d 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 @@ public final class MainVideoPlayer extends AppCompatActivity 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 @@ public final class MainVideoPlayer extends AppCompatActivity } @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 @@ public final class MainVideoPlayer extends AppCompatActivity 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 final class MainVideoPlayer extends AppCompatActivity } @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 final class MainVideoPlayer extends AppCompatActivity 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 c95a455d2..5fb94e6c5 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 abstract class VideoPlayer extends BasePlayer 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 7b41b2beb..f47eb7107 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 android.view.KeyEvent; 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 b6d5b365e..1ffb7d069 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 final class FocusAwareCoordinator extends CoordinatorLayout { 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 final class FocusAwareCoordinator extends CoordinatorLayout { } 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 dbc0ab77a..eed2f5250 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 final class FocusAwareDrawerLayout extends DrawerLayout { 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 @@ public final class FocusAwareDrawerLayout extends DrawerLayout { } @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 ca682ac84..179e32e4c 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 final class FocusAwareSeekBar extends AppCompatSeekBar { 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 final class FocusAwareSeekBar extends AppCompatSeekBar { } @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 @@ public final class FocusAwareSeekBar extends AppCompatSeekBar { } @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 f0a2bbc3a..655b86818 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 class NewPipeRecyclerView extends RecyclerView { 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 @@ public class NewPipeRecyclerView extends RecyclerView { 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 class NewPipeRecyclerView extends RecyclerView { } 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 class NewPipeRecyclerView extends RecyclerView { 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 1ab96c9e5..6c4d20603 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 final class SuperScrollLayoutManager extends LinearLayoutManager { } @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 final class SuperScrollLayoutManager extends LinearLayoutManager { } } - return super.requestChildRectangleOnScreen(parent, child, rect, immediate, focusedChildVisible); + return super.requestChildRectangleOnScreen(parent, child, rect, immediate, + focusedChildVisible); } @Nullable @@ -90,7 +95,9 @@ public final class SuperScrollLayoutManager extends LinearLayoutManager { 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) {