Skip to content

Commit 6cd25d7

Browse files
authored
Merge pull request #7412 from litetex/code-cleanup
Some code cleanup(s)
2 parents d8236bb + c9488eb commit 6cd25d7

5 files changed

Lines changed: 39 additions & 59 deletions

File tree

app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import android.graphics.drawable.Drawable
2929
import android.graphics.drawable.LayerDrawable
3030
import android.os.Bundle
3131
import android.os.Parcelable
32+
import android.util.Log
3233
import android.view.LayoutInflater
3334
import android.view.Menu
3435
import android.view.MenuInflater
@@ -504,7 +505,7 @@ class FeedFragment : BaseStateFragment<FeedState>() {
504505
errors.subList(i + 1, errors.size)
505506
)
506507
},
507-
{ throwable -> throwable.printStackTrace() }
508+
{ throwable -> Log.e(TAG, "Unable to process", throwable) }
508509
)
509510
return // this will be called on the remaining errors by handleFeedNotAvailable()
510511
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ && isPlaybackResumeEnabled(this)
693693
},
694694
error -> {
695695
if (DEBUG) {
696-
error.printStackTrace();
696+
Log.w(TAG, "Failed to start playback", error);
697697
}
698698
// In case any error we can start playback without history
699699
initPlayback(newQueue, repeatMode, playbackSpeed, playbackPitch,
@@ -4187,8 +4187,7 @@ private boolean isLive() {
41874187
} catch (@NonNull final IndexOutOfBoundsException e) {
41884188
// Why would this even happen =(... but lets log it anyway, better safe than sorry
41894189
if (DEBUG) {
4190-
Log.d(TAG, "player.isCurrentWindowDynamic() failed: " + e.getMessage());
4191-
e.printStackTrace();
4190+
Log.d(TAG, "player.isCurrentWindowDynamic() failed: ", e);
41924191
}
41934192
return false;
41944193
}

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

Lines changed: 25 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -69,26 +69,18 @@ public void onSingleTap(@NotNull final MainPlayer.PlayerType playerType) {
6969
if (DEBUG) {
7070
Log.d(TAG, "onSingleTap called with playerType = [" + player.getPlayerType() + "]");
7171
}
72-
if (playerType == MainPlayer.PlayerType.POPUP) {
7372

74-
if (player.isControlsVisible()) {
75-
player.hideControls(100, 100);
76-
} else {
77-
player.getPlayPauseButton().requestFocus();
78-
player.showControlsThenHide();
79-
}
80-
81-
} else /* playerType == MainPlayer.PlayerType.VIDEO */ {
73+
if (player.isControlsVisible()) {
74+
player.hideControls(150, 0);
75+
return;
76+
}
77+
// -- Controls are not visible --
8278

83-
if (player.isControlsVisible()) {
84-
player.hideControls(150, 0);
85-
} else {
86-
if (player.getCurrentState() == Player.STATE_COMPLETED) {
87-
player.showControls(0);
88-
} else {
89-
player.showControlsThenHide();
90-
}
91-
}
79+
// When player is completed show controls and don't hide them later
80+
if (player.getCurrentState() == Player.STATE_COMPLETED) {
81+
player.showControls(0);
82+
} else {
83+
player.showControlsThenHide();
9284
}
9385
}
9486

@@ -103,6 +95,8 @@ public void onScroll(@NotNull final MainPlayer.PlayerType playerType,
10395
+ player.getPlayerType() + "], portion = [" + portion + "]");
10496
}
10597
if (playerType == MainPlayer.PlayerType.VIDEO) {
98+
99+
// -- Brightness and Volume control --
106100
final boolean isBrightnessGestureEnabled =
107101
PlayerHelper.isBrightnessGestureEnabled(service);
108102
final boolean isVolumeGestureEnabled = PlayerHelper.isVolumeGestureEnabled(service);
@@ -121,15 +115,14 @@ public void onScroll(@NotNull final MainPlayer.PlayerType playerType,
121115
}
122116

123117
} else /* MainPlayer.PlayerType.POPUP */ {
118+
119+
// -- Determine if the ClosingOverlayView (red X) has to be shown or hidden --
124120
final View closingOverlayView = player.getClosingOverlayView();
125-
if (player.isInsideClosingRadius(movingEvent)) {
126-
if (closingOverlayView.getVisibility() == View.GONE) {
127-
animate(closingOverlayView, true, 200);
128-
}
129-
} else {
130-
if (closingOverlayView.getVisibility() == View.VISIBLE) {
131-
animate(closingOverlayView, false, 200);
132-
}
121+
final boolean showClosingOverlayView = player.isInsideClosingRadius(movingEvent);
122+
// Check if an view is in expected state and if not animate it into the correct state
123+
final int expectedVisibility = showClosingOverlayView ? View.VISIBLE : View.GONE;
124+
if (closingOverlayView.getVisibility() != expectedVisibility) {
125+
animate(closingOverlayView, showClosingOverlayView, 200);
133126
}
134127
}
135128
}
@@ -210,11 +203,12 @@ public void onScrollEnd(@NotNull final MainPlayer.PlayerType playerType,
210203
Log.d(TAG, "onScrollEnd called with playerType = ["
211204
+ player.getPlayerType() + "]");
212205
}
213-
if (playerType == MainPlayer.PlayerType.VIDEO) {
214-
if (DEBUG) {
215-
Log.d(TAG, "onScrollEnd() called");
216-
}
217206

207+
if (player.isControlsVisible() && player.getCurrentState() == STATE_PLAYING) {
208+
player.hideControls(DEFAULT_CONTROLS_DURATION, DEFAULT_CONTROLS_HIDE_TIME);
209+
}
210+
211+
if (playerType == MainPlayer.PlayerType.VIDEO) {
218212
if (player.getVolumeRelativeLayout().getVisibility() == View.VISIBLE) {
219213
animate(player.getVolumeRelativeLayout(), false, 200, SCALE_AND_ALPHA,
220214
200);
@@ -223,15 +217,7 @@ public void onScrollEnd(@NotNull final MainPlayer.PlayerType playerType,
223217
animate(player.getBrightnessRelativeLayout(), false, 200, SCALE_AND_ALPHA,
224218
200);
225219
}
226-
227-
if (player.isControlsVisible() && player.getCurrentState() == STATE_PLAYING) {
228-
player.hideControls(DEFAULT_CONTROLS_DURATION, DEFAULT_CONTROLS_HIDE_TIME);
229-
}
230-
} else {
231-
if (player.isControlsVisible() && player.getCurrentState() == STATE_PLAYING) {
232-
player.hideControls(DEFAULT_CONTROLS_DURATION, DEFAULT_CONTROLS_HIDE_TIME);
233-
}
234-
220+
} else /* Popup-Player */ {
235221
if (player.isInsideClosingRadius(event)) {
236222
player.closePopup();
237223
} else if (!player.isPopupClosing()) {

app/src/main/java/org/schabi/newpipe/settings/ContentSettingsManager.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.schabi.newpipe.settings
22

33
import android.content.SharedPreferences
4+
import android.util.Log
45
import org.schabi.newpipe.streams.io.SharpOutputStream
56
import org.schabi.newpipe.streams.io.StoredFileHelper
67
import org.schabi.newpipe.util.ZipHelper
@@ -13,6 +14,9 @@ import java.io.ObjectOutputStream
1314
import java.util.zip.ZipOutputStream
1415

1516
class ContentSettingsManager(private val fileLocator: NewPipeFileLocator) {
17+
companion object {
18+
const val TAG = "ContentSetManager"
19+
}
1620

1721
/**
1822
* Exports given [SharedPreferences] to the file in given outputPath.
@@ -31,7 +35,7 @@ class ContentSettingsManager(private val fileLocator: NewPipeFileLocator) {
3135
output.flush()
3236
}
3337
} catch (e: IOException) {
34-
e.printStackTrace()
38+
Log.e(TAG, "Unable to exportDatabase", e)
3539
}
3640

3741
ZipHelper.addFileToZip(outZip, fileLocator.settings.path, "newpipe.settings")
@@ -101,9 +105,9 @@ class ContentSettingsManager(private val fileLocator: NewPipeFileLocator) {
101105
preferenceEditor.commit()
102106
}
103107
} catch (e: IOException) {
104-
e.printStackTrace()
108+
Log.e(TAG, "Unable to loadSharedPreferences", e)
105109
} catch (e: ClassNotFoundException) {
106-
e.printStackTrace()
110+
Log.e(TAG, "Unable to loadSharedPreferences", e)
107111
}
108112
}
109113
}

app/src/main/java/org/schabi/newpipe/util/TLSSocketFactoryCompat.java

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@
1010
import javax.net.ssl.SSLContext;
1111
import javax.net.ssl.SSLSocket;
1212
import javax.net.ssl.SSLSocketFactory;
13-
import javax.net.ssl.TrustManager;
1413

15-
import static org.schabi.newpipe.MainActivity.DEBUG;
14+
import android.util.Log;
1615

1716

1817
/**
@@ -21,6 +20,7 @@
2120
*/
2221
public class TLSSocketFactoryCompat extends SSLSocketFactory {
2322

23+
private static final String TAG = "TLSSocketFactoryCom";
2424

2525
private static TLSSocketFactoryCompat instance = null;
2626

@@ -32,14 +32,6 @@ public TLSSocketFactoryCompat() throws KeyManagementException, NoSuchAlgorithmEx
3232
internalSSLSocketFactory = context.getSocketFactory();
3333
}
3434

35-
36-
public TLSSocketFactoryCompat(final TrustManager[] tm)
37-
throws KeyManagementException, NoSuchAlgorithmException {
38-
final SSLContext context = SSLContext.getInstance("TLS");
39-
context.init(null, tm, new java.security.SecureRandom());
40-
internalSSLSocketFactory = context.getSocketFactory();
41-
}
42-
4335
public static TLSSocketFactoryCompat getInstance()
4436
throws NoSuchAlgorithmException, KeyManagementException {
4537
if (instance != null) {
@@ -53,9 +45,7 @@ public static void setAsDefault() {
5345
try {
5446
HttpsURLConnection.setDefaultSSLSocketFactory(getInstance());
5547
} catch (NoSuchAlgorithmException | KeyManagementException e) {
56-
if (DEBUG) {
57-
e.printStackTrace();
58-
}
48+
Log.e(TAG, "Unable to setAsDefault", e);
5949
}
6050
}
6151

0 commit comments

Comments
 (0)