Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some code cleanup(s) #7412

Merged
merged 11 commits into from
Nov 23, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import android.content.Intent
import android.content.SharedPreferences
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 @@ -464,7 +465,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 @@ -695,7 +695,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 @@ -4184,8 +4184,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,20 @@ 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();
litetex marked this conversation as resolved.
Show resolved Hide resolved
player.showControlsThenHide();
}
if (player.isControlsVisible()) {

} else /* playerType == MainPlayer.PlayerType.VIDEO */ {

litetex marked this conversation as resolved.
Show resolved Hide resolved
if (player.isControlsVisible()) {
player.hideControls(150, 0);
} else {
if (player.getCurrentState() == Player.STATE_COMPLETED) {
player.showControls(0);
} else {
player.showControlsThenHide();
}
}
player.hideControls(150, 0);
return;
}
// -- Controls are not visible --

// 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 +97,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 +117,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 +205,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 +219,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