Skip to content

Commit

Permalink
Merge pull request #7412 from litetex/code-cleanup
Browse files Browse the repository at this point in the history
Some code cleanup(s)
  • Loading branch information
Stypox authored Nov 23, 2021
2 parents d8236bb + c9488eb commit 6cd25d7
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import android.graphics.drawable.Drawable
import android.graphics.drawable.LayerDrawable
import android.os.Bundle
import android.os.Parcelable
import android.util.Log
import android.view.LayoutInflater
import android.view.Menu
import android.view.MenuInflater
Expand Down Expand Up @@ -504,7 +505,7 @@ class FeedFragment : BaseStateFragment<FeedState>() {
errors.subList(i + 1, errors.size)
)
},
{ throwable -> throwable.printStackTrace() }
{ throwable -> Log.e(TAG, "Unable to process", throwable) }
)
return // this will be called on the remaining errors by handleFeedNotAvailable()
}
Expand Down
5 changes: 2 additions & 3 deletions app/src/main/java/org/schabi/newpipe/player/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ && isPlaybackResumeEnabled(this)
},
error -> {
if (DEBUG) {
error.printStackTrace();
Log.w(TAG, "Failed to start playback", error);
}
// In case any error we can start playback without history
initPlayback(newQueue, repeatMode, playbackSpeed, playbackPitch,
Expand Down Expand Up @@ -4187,8 +4187,7 @@ private boolean isLive() {
} catch (@NonNull final IndexOutOfBoundsException e) {
// Why would this even happen =(... but lets log it anyway, better safe than sorry
if (DEBUG) {
Log.d(TAG, "player.isCurrentWindowDynamic() failed: " + e.getMessage());
e.printStackTrace();
Log.d(TAG, "player.isCurrentWindowDynamic() failed: ", e);
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,26 +69,18 @@ public void onSingleTap(@NotNull final MainPlayer.PlayerType playerType) {
if (DEBUG) {
Log.d(TAG, "onSingleTap called with playerType = [" + player.getPlayerType() + "]");
}
if (playerType == MainPlayer.PlayerType.POPUP) {

if (player.isControlsVisible()) {
player.hideControls(100, 100);
} else {
player.getPlayPauseButton().requestFocus();
player.showControlsThenHide();
}

} else /* playerType == MainPlayer.PlayerType.VIDEO */ {
if (player.isControlsVisible()) {
player.hideControls(150, 0);
return;
}
// -- Controls are not visible --

if (player.isControlsVisible()) {
player.hideControls(150, 0);
} else {
if (player.getCurrentState() == Player.STATE_COMPLETED) {
player.showControls(0);
} else {
player.showControlsThenHide();
}
}
// When player is completed show controls and don't hide them later
if (player.getCurrentState() == Player.STATE_COMPLETED) {
player.showControls(0);
} else {
player.showControlsThenHide();
}
}

Expand All @@ -103,6 +95,8 @@ public void onScroll(@NotNull final MainPlayer.PlayerType playerType,
+ player.getPlayerType() + "], portion = [" + portion + "]");
}
if (playerType == MainPlayer.PlayerType.VIDEO) {

// -- Brightness and Volume control --
final boolean isBrightnessGestureEnabled =
PlayerHelper.isBrightnessGestureEnabled(service);
final boolean isVolumeGestureEnabled = PlayerHelper.isVolumeGestureEnabled(service);
Expand All @@ -121,15 +115,14 @@ public void onScroll(@NotNull final MainPlayer.PlayerType playerType,
}

} else /* MainPlayer.PlayerType.POPUP */ {

// -- Determine if the ClosingOverlayView (red X) has to be shown or hidden --
final View closingOverlayView = player.getClosingOverlayView();
if (player.isInsideClosingRadius(movingEvent)) {
if (closingOverlayView.getVisibility() == View.GONE) {
animate(closingOverlayView, true, 200);
}
} else {
if (closingOverlayView.getVisibility() == View.VISIBLE) {
animate(closingOverlayView, false, 200);
}
final boolean showClosingOverlayView = player.isInsideClosingRadius(movingEvent);
// Check if an view is in expected state and if not animate it into the correct state
final int expectedVisibility = showClosingOverlayView ? View.VISIBLE : View.GONE;
if (closingOverlayView.getVisibility() != expectedVisibility) {
animate(closingOverlayView, showClosingOverlayView, 200);
}
}
}
Expand Down Expand Up @@ -210,11 +203,12 @@ public void onScrollEnd(@NotNull final MainPlayer.PlayerType playerType,
Log.d(TAG, "onScrollEnd called with playerType = ["
+ player.getPlayerType() + "]");
}
if (playerType == MainPlayer.PlayerType.VIDEO) {
if (DEBUG) {
Log.d(TAG, "onScrollEnd() called");
}

if (player.isControlsVisible() && player.getCurrentState() == STATE_PLAYING) {
player.hideControls(DEFAULT_CONTROLS_DURATION, DEFAULT_CONTROLS_HIDE_TIME);
}

if (playerType == MainPlayer.PlayerType.VIDEO) {
if (player.getVolumeRelativeLayout().getVisibility() == View.VISIBLE) {
animate(player.getVolumeRelativeLayout(), false, 200, SCALE_AND_ALPHA,
200);
Expand All @@ -223,15 +217,7 @@ public void onScrollEnd(@NotNull final MainPlayer.PlayerType playerType,
animate(player.getBrightnessRelativeLayout(), false, 200, SCALE_AND_ALPHA,
200);
}

if (player.isControlsVisible() && player.getCurrentState() == STATE_PLAYING) {
player.hideControls(DEFAULT_CONTROLS_DURATION, DEFAULT_CONTROLS_HIDE_TIME);
}
} else {
if (player.isControlsVisible() && player.getCurrentState() == STATE_PLAYING) {
player.hideControls(DEFAULT_CONTROLS_DURATION, DEFAULT_CONTROLS_HIDE_TIME);
}

} else /* Popup-Player */ {
if (player.isInsideClosingRadius(event)) {
player.closePopup();
} else if (!player.isPopupClosing()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.schabi.newpipe.settings

import android.content.SharedPreferences
import android.util.Log
import org.schabi.newpipe.streams.io.SharpOutputStream
import org.schabi.newpipe.streams.io.StoredFileHelper
import org.schabi.newpipe.util.ZipHelper
Expand All @@ -13,6 +14,9 @@ import java.io.ObjectOutputStream
import java.util.zip.ZipOutputStream

class ContentSettingsManager(private val fileLocator: NewPipeFileLocator) {
companion object {
const val TAG = "ContentSetManager"
}

/**
* Exports given [SharedPreferences] to the file in given outputPath.
Expand All @@ -31,7 +35,7 @@ class ContentSettingsManager(private val fileLocator: NewPipeFileLocator) {
output.flush()
}
} catch (e: IOException) {
e.printStackTrace()
Log.e(TAG, "Unable to exportDatabase", e)
}

ZipHelper.addFileToZip(outZip, fileLocator.settings.path, "newpipe.settings")
Expand Down Expand Up @@ -101,9 +105,9 @@ class ContentSettingsManager(private val fileLocator: NewPipeFileLocator) {
preferenceEditor.commit()
}
} catch (e: IOException) {
e.printStackTrace()
Log.e(TAG, "Unable to loadSharedPreferences", e)
} catch (e: ClassNotFoundException) {
e.printStackTrace()
Log.e(TAG, "Unable to loadSharedPreferences", e)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;

import static org.schabi.newpipe.MainActivity.DEBUG;
import android.util.Log;


/**
Expand All @@ -21,6 +20,7 @@
*/
public class TLSSocketFactoryCompat extends SSLSocketFactory {

private static final String TAG = "TLSSocketFactoryCom";

private static TLSSocketFactoryCompat instance = null;

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


public TLSSocketFactoryCompat(final TrustManager[] tm)
throws KeyManagementException, NoSuchAlgorithmException {
final SSLContext context = SSLContext.getInstance("TLS");
context.init(null, tm, new java.security.SecureRandom());
internalSSLSocketFactory = context.getSocketFactory();
}

public static TLSSocketFactoryCompat getInstance()
throws NoSuchAlgorithmException, KeyManagementException {
if (instance != null) {
Expand All @@ -53,9 +45,7 @@ public static void setAsDefault() {
try {
HttpsURLConnection.setDefaultSSLSocketFactory(getInstance());
} catch (NoSuchAlgorithmException | KeyManagementException e) {
if (DEBUG) {
e.printStackTrace();
}
Log.e(TAG, "Unable to setAsDefault", e);
}
}

Expand Down

0 comments on commit 6cd25d7

Please sign in to comment.