Skip to content

Commit 37b8a93

Browse files
committed
Small improvements to code quality and readability
Add annotations to methods and parameters. Replace Jetbrains' @NotNull with Androidx' @nonnull annotatiation. Make class variables static if possible. Use constants for some Strings. Simplify if conditions.
1 parent d71af9a commit 37b8a93

File tree

8 files changed

+44
-39
lines changed

8 files changed

+44
-39
lines changed

app/src/main/java/com/google/android/material/appbar/FlingBehavior.java

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public boolean onRequestChildRectangleOnScreen(
6363
return consumed == dy;
6464
}
6565

66+
@Override
6667
public boolean onInterceptTouchEvent(@NonNull final CoordinatorLayout parent,
6768
@NonNull final AppBarLayout child,
6869
@NonNull final MotionEvent ev) {

app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ private void showDeleteSuggestionDialog(final SuggestionItem item) {
724724
@Override
725725
public boolean onBackPressed() {
726726
if (suggestionsPanelVisible
727-
&& infoListAdapter.getItemsList().size() > 0
727+
&& !infoListAdapter.getItemsList().isEmpty()
728728
&& !isLoading.get()) {
729729
hideSuggestionsPanel();
730730
hideKeyboardSearch();

app/src/main/java/org/schabi/newpipe/local/subscription/item/ChannelItem.kt

+3-5
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,9 @@ class ChannelItem(
5454
context.getString(R.string.subscribers_count_not_available)
5555
}
5656

57-
if (itemVersion == ItemVersion.NORMAL) {
58-
if (infoItem.streamCount >= 0) {
59-
val formattedVideoAmount = Localization.localizeStreamCount(context, infoItem.streamCount)
60-
details = Localization.concatenateStrings(details, formattedVideoAmount)
61-
}
57+
if (itemVersion == ItemVersion.NORMAL && infoItem.streamCount >= 0) {
58+
val formattedVideoAmount = Localization.localizeStreamCount(context, infoItem.streamCount)
59+
details = Localization.concatenateStrings(details, formattedVideoAmount)
6260
}
6361
return details
6462
}

app/src/main/java/org/schabi/newpipe/player/Player.java

+14-12
Original file line numberDiff line numberDiff line change
@@ -2348,7 +2348,8 @@ private void onShuffleOrRepeatModeChanged() {
23482348
NotificationUtil.getInstance().createNotificationIfNeededAndUpdate(this, false);
23492349
}
23502350

2351-
private void setRepeatModeButton(final AppCompatImageButton imageButton, final int repeatMode) {
2351+
private void setRepeatModeButton(final AppCompatImageButton imageButton,
2352+
@RepeatMode final int repeatMode) {
23522353
switch (repeatMode) {
23532354
case REPEAT_MODE_OFF:
23542355
imageButton.setImageResource(R.drawable.exo_controls_repeat_off);
@@ -2362,7 +2363,7 @@ private void setRepeatModeButton(final AppCompatImageButton imageButton, final i
23622363
}
23632364
}
23642365

2365-
private void setShuffleButton(final ImageButton button, final boolean shuffled) {
2366+
private void setShuffleButton(@NonNull final ImageButton button, final boolean shuffled) {
23662367
button.setImageAlpha(shuffled ? 255 : 77);
23672368
}
23682369
//endregion
@@ -2387,7 +2388,7 @@ boolean isMuted() {
23872388
return !exoPlayerIsNull() && simpleExoPlayer.getVolume() == 0;
23882389
}
23892390

2390-
private void setMuteButton(final ImageButton button, final boolean isMuted) {
2391+
private void setMuteButton(@NonNull final ImageButton button, final boolean isMuted) {
23912392
button.setImageDrawable(AppCompatResources.getDrawable(context, isMuted
23922393
? R.drawable.ic_volume_off : R.drawable.ic_volume_up));
23932394
}
@@ -2876,7 +2877,7 @@ private void saveStreamProgressState(final long progressMillis) {
28762877
databaseUpdateDisposable
28772878
.add(recordManager.saveStreamState(currentMetadata.getMetadata(), progressMillis)
28782879
.observeOn(AndroidSchedulers.mainThread())
2879-
.doOnError((e) -> {
2880+
.doOnError(e -> {
28802881
if (DEBUG) {
28812882
e.printStackTrace();
28822883
}
@@ -3386,7 +3387,7 @@ private void buildPlaybackSpeedMenu() {
33863387
playbackSpeedPopupMenu.setOnDismissListener(this);
33873388
}
33883389

3389-
private void buildCaptionMenu(final List<String> availableLanguages) {
3390+
private void buildCaptionMenu(@NonNull final List<String> availableLanguages) {
33903391
if (captionPopupMenu == null) {
33913392
return;
33923393
}
@@ -3454,7 +3455,7 @@ private void buildCaptionMenu(final List<String> availableLanguages) {
34543455
* Called when an item of the quality selector or the playback speed selector is selected.
34553456
*/
34563457
@Override
3457-
public boolean onMenuItemClick(final MenuItem menuItem) {
3458+
public boolean onMenuItemClick(@NonNull final MenuItem menuItem) {
34583459
if (DEBUG) {
34593460
Log.d(TAG, "onMenuItemClick() called with: "
34603461
+ "menuItem = [" + menuItem + "], "
@@ -3491,7 +3492,7 @@ public boolean onMenuItemClick(final MenuItem menuItem) {
34913492
* Called when some popup menu is dismissed.
34923493
*/
34933494
@Override
3494-
public void onDismiss(final PopupMenu menu) {
3495+
public void onDismiss(@Nullable final PopupMenu menu) {
34953496
if (DEBUG) {
34963497
Log.d(TAG, "onDismiss() called with: menu = [" + menu + "]");
34973498
}
@@ -3544,7 +3545,7 @@ private void onCaptionClicked() {
35443545
isSomePopupMenuVisible = true;
35453546
}
35463547

3547-
private void setPlaybackQuality(final String quality) {
3548+
private void setPlaybackQuality(@Nullable final String quality) {
35483549
videoResolver.setPlaybackQuality(quality);
35493550
}
35503551
//endregion
@@ -3568,7 +3569,7 @@ private void setupSubtitleView() {
35683569
final int minimumLength = Math.min(metrics.heightPixels, metrics.widthPixels);
35693570
final float captionRatioInverse = 20f + 4f * (1.0f - captionScale);
35703571
binding.subtitleView.setFixedTextSize(
3571-
TypedValue.COMPLEX_UNIT_PX, (float) minimumLength / captionRatioInverse);
3572+
TypedValue.COMPLEX_UNIT_PX, minimumLength / captionRatioInverse);
35723573
}
35733574
binding.subtitleView.setApplyEmbeddedStyles(captionStyle == CaptionStyleCompat.DEFAULT);
35743575
binding.subtitleView.setStyle(captionStyle);
@@ -3845,7 +3846,7 @@ void onResizeClicked() {
38453846
}
38463847

38473848
@Override // exoplayer listener
3848-
public void onVideoSizeChanged(final VideoSize videoSize) {
3849+
public void onVideoSizeChanged(@NonNull final VideoSize videoSize) {
38493850
if (DEBUG) {
38503851
Log.d(TAG, "onVideoSizeChanged() called with: "
38513852
+ "width / height = [" + videoSize.width + " / " + videoSize.height
@@ -3959,7 +3960,7 @@ private void setInitialGestureValues() {
39593960
}
39603961
}
39613962

3962-
private int distanceFromCloseButton(final MotionEvent popupMotionEvent) {
3963+
private int distanceFromCloseButton(@NonNull final MotionEvent popupMotionEvent) {
39633964
final int closeOverlayButtonX = closeOverlayBinding.closeButton.getLeft()
39643965
+ closeOverlayBinding.closeButton.getWidth() / 2;
39653966
final int closeOverlayButtonY = closeOverlayBinding.closeButton.getTop()
@@ -3978,7 +3979,7 @@ private float getClosingRadius() {
39783979
return buttonRadius * 1.2f;
39793980
}
39803981

3981-
public boolean isInsideClosingRadius(final MotionEvent popupMotionEvent) {
3982+
public boolean isInsideClosingRadius(@NonNull final MotionEvent popupMotionEvent) {
39823983
return distanceFromCloseButton(popupMotionEvent) <= getClosingRadius();
39833984
}
39843985
//endregion
@@ -4098,6 +4099,7 @@ private void notifyProgressUpdateToListeners(final int currentProgress,
40984099
}
40994100
}
41004101

4102+
@Nullable
41014103
public AppCompatActivity getParentActivity() {
41024104
// ! instanceof ViewGroup means that view was added via windowManager for Popup
41034105
if (binding == null || !(binding.getRoot().getParent() instanceof ViewGroup)) {

app/src/main/java/org/schabi/newpipe/player/event/PlayerGestureListener.java

+17-17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
package org.schabi.newpipe.player.event;
22

3+
import static org.schabi.newpipe.ktx.AnimationType.ALPHA;
4+
import static org.schabi.newpipe.ktx.AnimationType.SCALE_AND_ALPHA;
5+
import static org.schabi.newpipe.ktx.ViewUtils.animate;
6+
import static org.schabi.newpipe.player.Player.DEFAULT_CONTROLS_DURATION;
7+
import static org.schabi.newpipe.player.Player.DEFAULT_CONTROLS_HIDE_TIME;
8+
import static org.schabi.newpipe.player.Player.STATE_PLAYING;
9+
310
import android.app.Activity;
411
import android.util.Log;
512
import android.view.MotionEvent;
@@ -8,22 +15,15 @@
815
import android.view.WindowManager;
916
import android.widget.ProgressBar;
1017

18+
import androidx.annotation.NonNull;
1119
import androidx.appcompat.content.res.AppCompatResources;
1220

13-
import org.jetbrains.annotations.NotNull;
1421
import org.schabi.newpipe.MainActivity;
1522
import org.schabi.newpipe.R;
1623
import org.schabi.newpipe.player.MainPlayer;
1724
import org.schabi.newpipe.player.Player;
1825
import org.schabi.newpipe.player.helper.PlayerHelper;
1926

20-
import static org.schabi.newpipe.ktx.AnimationType.ALPHA;
21-
import static org.schabi.newpipe.ktx.AnimationType.SCALE_AND_ALPHA;
22-
import static org.schabi.newpipe.ktx.ViewUtils.animate;
23-
import static org.schabi.newpipe.player.Player.DEFAULT_CONTROLS_DURATION;
24-
import static org.schabi.newpipe.player.Player.DEFAULT_CONTROLS_HIDE_TIME;
25-
import static org.schabi.newpipe.player.Player.STATE_PLAYING;
26-
2727
/**
2828
* GestureListener for the player
2929
*
@@ -45,8 +45,8 @@ public PlayerGestureListener(final Player player, final MainPlayer service) {
4545
}
4646

4747
@Override
48-
public void onDoubleTap(@NotNull final MotionEvent event,
49-
@NotNull final DisplayPortion portion) {
48+
public void onDoubleTap(@NonNull final MotionEvent event,
49+
@NonNull final DisplayPortion portion) {
5050
if (DEBUG) {
5151
Log.d(TAG, "onDoubleTap called with playerType = ["
5252
+ player.getPlayerType() + "], portion = [" + portion + "]");
@@ -65,7 +65,7 @@ public void onDoubleTap(@NotNull final MotionEvent event,
6565
}
6666

6767
@Override
68-
public void onSingleTap(@NotNull final MainPlayer.PlayerType playerType) {
68+
public void onSingleTap(@NonNull final MainPlayer.PlayerType playerType) {
6969
if (DEBUG) {
7070
Log.d(TAG, "onSingleTap called with playerType = [" + player.getPlayerType() + "]");
7171
}
@@ -85,10 +85,10 @@ public void onSingleTap(@NotNull final MainPlayer.PlayerType playerType) {
8585
}
8686

8787
@Override
88-
public void onScroll(@NotNull final MainPlayer.PlayerType playerType,
89-
@NotNull final DisplayPortion portion,
90-
@NotNull final MotionEvent initialEvent,
91-
@NotNull final MotionEvent movingEvent,
88+
public void onScroll(@NonNull final MainPlayer.PlayerType playerType,
89+
@NonNull final DisplayPortion portion,
90+
@NonNull final MotionEvent initialEvent,
91+
@NonNull final MotionEvent movingEvent,
9292
final float distanceX, final float distanceY) {
9393
if (DEBUG) {
9494
Log.d(TAG, "onScroll called with playerType = ["
@@ -197,8 +197,8 @@ private void onScrollMainBrightness(final float distanceX, final float distanceY
197197
}
198198

199199
@Override
200-
public void onScrollEnd(@NotNull final MainPlayer.PlayerType playerType,
201-
@NotNull final MotionEvent event) {
200+
public void onScrollEnd(@NonNull final MainPlayer.PlayerType playerType,
201+
@NonNull final MotionEvent event) {
202202
if (DEBUG) {
203203
Log.d(TAG, "onScrollEnd called with playerType = ["
204204
+ player.getPlayerType() + "]");

app/src/main/java/org/schabi/newpipe/player/helper/PlayerHolder.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ public static synchronized PlayerHolder getInstance() {
3535
return PlayerHolder.instance;
3636
}
3737

38-
private final boolean DEBUG = MainActivity.DEBUG;
39-
private final String TAG = PlayerHolder.class.getSimpleName();
38+
private static final boolean DEBUG = MainActivity.DEBUG;
39+
private static final String TAG = PlayerHolder.class.getSimpleName();
4040

4141
private PlayerServiceExtendedEventListener listener;
4242

@@ -152,7 +152,7 @@ public void onServiceConnected(final ComponentName compName, final IBinder servi
152152
}
153153
startPlayerListener();
154154
}
155-
};
155+
}
156156

157157
private void bind(final Context context) {
158158
if (DEBUG) {

app/src/main/java/org/schabi/newpipe/settings/BasePreferenceFragment.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
public abstract class BasePreferenceFragment extends PreferenceFragmentCompat {
2020
protected final String TAG = getClass().getSimpleName() + "@" + Integer.toHexString(hashCode());
21-
protected final boolean DEBUG = MainActivity.DEBUG;
21+
protected static final boolean DEBUG = MainActivity.DEBUG;
2222

2323
SharedPreferences defaultPreferences;
2424

app/src/main/java/us/shandian/giga/io/FileStreamSAF.java

+4
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,12 @@ public boolean canWrite() {
108108
return true;
109109
}
110110

111+
@Override
111112
public boolean canSetLength() {
112113
return true;
113114
}
114115

116+
@Override
115117
public boolean canSeek() {
116118
return true;
117119
}
@@ -131,10 +133,12 @@ public void write(byte[] buffer, int offset, int count) throws IOException {
131133
out.write(buffer, offset, count);
132134
}
133135

136+
@Override
134137
public void setLength(long length) throws IOException {
135138
channel.truncate(length);
136139
}
137140

141+
@Override
138142
public void seek(long offset) throws IOException {
139143
channel.position(offset);
140144
}

0 commit comments

Comments
 (0)