Comply with Checkstyle rules

This commit is contained in:
Alexander-- 2020-04-11 09:02:22 +06:59
parent ac5571a363
commit 53b3bda909
13 changed files with 75 additions and 49 deletions

View File

@ -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;

View File

@ -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<I, N> extends BaseStateFragment<I>
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();
}

View File

@ -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<I extends ListInfo>

View File

@ -511,7 +511,7 @@ public class SearchFragment extends BaseListFragment<SearchInfo, ListExtractor.I
if (isSuggestionsEnabled && errorPanelRoot.getVisibility() != View.VISIBLE) {
showSuggestionsPanel();
}
if(AndroidTvUtils.isTv()){
if (AndroidTvUtils.isTv()) {
showKeyboardSearch();
}
});

View File

@ -78,10 +78,8 @@ import org.schabi.newpipe.util.SerializedCache;
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_INTERNAL
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 abstract class BasePlayer implements
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 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();

View File

@ -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);
}
}

View File

@ -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));

View File

@ -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)

View File

@ -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);

View File

@ -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<View> views, final int direction, final int focusableMode) {
public void addFocusables(final ArrayList<View> views, final int direction,
final int focusableMode) {
boolean hasOpenPanels = false;
View content = null;

View File

@ -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;

View File

@ -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;
}

View File

@ -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) {