Skip to content

Commit

Permalink
Comply with Checkstyle rules
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-- committed Apr 11, 2020
1 parent ac5571a commit 53b3bda
Show file tree
Hide file tree
Showing 13 changed files with 75 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -166,13 +164,15 @@ public void readFrom(@NonNull final Queue<Object> 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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<I extends ListInfo>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ private void initSearchListeners() {
if (isSuggestionsEnabled && errorPanelRoot.getVisibility() != View.VISIBLE) {
showSuggestionsPanel();
}
if(AndroidTvUtils.isTv()){
if (AndroidTvUtils.isTv()) {
showKeyboardSearch();
}
});
Expand Down
14 changes: 7 additions & 7 deletions app/src/main/java/org/schabi/newpipe/player/BasePlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down
17 changes: 11 additions & 6 deletions app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -1077,16 +1081,17 @@ 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 + "]");
}

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

Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/org/schabi/newpipe/player/VideoPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/org/schabi/newpipe/util/AndroidTvUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -74,7 +79,8 @@ protected boolean onRequestFocusInDescendants(final int direction, final Rect pr
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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) {
Expand Down Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 53b3bda

Please sign in to comment.