Merge pull request #7412 from litetex/code-cleanup

Some code cleanup(s)
This commit is contained in:
Stypox 2021-11-23 08:59:34 +01:00 committed by GitHub
commit 6cd25d7e55
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 39 additions and 59 deletions

View file

@ -29,6 +29,7 @@ import android.graphics.drawable.Drawable
import android.graphics.drawable.LayerDrawable import android.graphics.drawable.LayerDrawable
import android.os.Bundle import android.os.Bundle
import android.os.Parcelable import android.os.Parcelable
import android.util.Log
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.Menu import android.view.Menu
import android.view.MenuInflater import android.view.MenuInflater
@ -504,7 +505,7 @@ class FeedFragment : BaseStateFragment<FeedState>() {
errors.subList(i + 1, errors.size) 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() return // this will be called on the remaining errors by handleFeedNotAvailable()
} }

View file

@ -693,7 +693,7 @@ public final class Player implements
}, },
error -> { error -> {
if (DEBUG) { if (DEBUG) {
error.printStackTrace(); Log.w(TAG, "Failed to start playback", error);
} }
// In case any error we can start playback without history // In case any error we can start playback without history
initPlayback(newQueue, repeatMode, playbackSpeed, playbackPitch, initPlayback(newQueue, repeatMode, playbackSpeed, playbackPitch,
@ -4187,8 +4187,7 @@ public final class Player implements
} catch (@NonNull final IndexOutOfBoundsException e) { } catch (@NonNull final IndexOutOfBoundsException e) {
// Why would this even happen =(... but lets log it anyway, better safe than sorry // Why would this even happen =(... but lets log it anyway, better safe than sorry
if (DEBUG) { if (DEBUG) {
Log.d(TAG, "player.isCurrentWindowDynamic() failed: " + e.getMessage()); Log.d(TAG, "player.isCurrentWindowDynamic() failed: ", e);
e.printStackTrace();
} }
return false; return false;
} }

View file

@ -69,26 +69,18 @@ public class PlayerGestureListener
if (DEBUG) { if (DEBUG) {
Log.d(TAG, "onSingleTap called with playerType = [" + player.getPlayerType() + "]"); Log.d(TAG, "onSingleTap called with playerType = [" + player.getPlayerType() + "]");
} }
if (playerType == MainPlayer.PlayerType.POPUP) {
if (player.isControlsVisible()) { if (player.isControlsVisible()) {
player.hideControls(100, 100); player.hideControls(150, 0);
} else { return;
player.getPlayPauseButton().requestFocus(); }
player.showControlsThenHide(); // -- Controls are not visible --
}
} else /* playerType == MainPlayer.PlayerType.VIDEO */ { // When player is completed show controls and don't hide them later
if (player.getCurrentState() == Player.STATE_COMPLETED) {
if (player.isControlsVisible()) { player.showControls(0);
player.hideControls(150, 0); } else {
} else { player.showControlsThenHide();
if (player.getCurrentState() == Player.STATE_COMPLETED) {
player.showControls(0);
} else {
player.showControlsThenHide();
}
}
} }
} }
@ -103,6 +95,8 @@ public class PlayerGestureListener
+ player.getPlayerType() + "], portion = [" + portion + "]"); + player.getPlayerType() + "], portion = [" + portion + "]");
} }
if (playerType == MainPlayer.PlayerType.VIDEO) { if (playerType == MainPlayer.PlayerType.VIDEO) {
// -- Brightness and Volume control --
final boolean isBrightnessGestureEnabled = final boolean isBrightnessGestureEnabled =
PlayerHelper.isBrightnessGestureEnabled(service); PlayerHelper.isBrightnessGestureEnabled(service);
final boolean isVolumeGestureEnabled = PlayerHelper.isVolumeGestureEnabled(service); final boolean isVolumeGestureEnabled = PlayerHelper.isVolumeGestureEnabled(service);
@ -121,15 +115,14 @@ public class PlayerGestureListener
} }
} else /* MainPlayer.PlayerType.POPUP */ { } else /* MainPlayer.PlayerType.POPUP */ {
// -- Determine if the ClosingOverlayView (red X) has to be shown or hidden --
final View closingOverlayView = player.getClosingOverlayView(); final View closingOverlayView = player.getClosingOverlayView();
if (player.isInsideClosingRadius(movingEvent)) { final boolean showClosingOverlayView = player.isInsideClosingRadius(movingEvent);
if (closingOverlayView.getVisibility() == View.GONE) { // Check if an view is in expected state and if not animate it into the correct state
animate(closingOverlayView, true, 200); final int expectedVisibility = showClosingOverlayView ? View.VISIBLE : View.GONE;
} if (closingOverlayView.getVisibility() != expectedVisibility) {
} else { animate(closingOverlayView, showClosingOverlayView, 200);
if (closingOverlayView.getVisibility() == View.VISIBLE) {
animate(closingOverlayView, false, 200);
}
} }
} }
} }
@ -210,11 +203,12 @@ public class PlayerGestureListener
Log.d(TAG, "onScrollEnd called with playerType = [" Log.d(TAG, "onScrollEnd called with playerType = ["
+ player.getPlayerType() + "]"); + 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) { if (player.getVolumeRelativeLayout().getVisibility() == View.VISIBLE) {
animate(player.getVolumeRelativeLayout(), false, 200, SCALE_AND_ALPHA, animate(player.getVolumeRelativeLayout(), false, 200, SCALE_AND_ALPHA,
200); 200);
@ -223,15 +217,7 @@ public class PlayerGestureListener
animate(player.getBrightnessRelativeLayout(), false, 200, SCALE_AND_ALPHA, animate(player.getBrightnessRelativeLayout(), false, 200, SCALE_AND_ALPHA,
200); 200);
} }
} else /* Popup-Player */ {
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);
}
if (player.isInsideClosingRadius(event)) { if (player.isInsideClosingRadius(event)) {
player.closePopup(); player.closePopup();
} else if (!player.isPopupClosing()) { } else if (!player.isPopupClosing()) {

View file

@ -1,6 +1,7 @@
package org.schabi.newpipe.settings package org.schabi.newpipe.settings
import android.content.SharedPreferences import android.content.SharedPreferences
import android.util.Log
import org.schabi.newpipe.streams.io.SharpOutputStream import org.schabi.newpipe.streams.io.SharpOutputStream
import org.schabi.newpipe.streams.io.StoredFileHelper import org.schabi.newpipe.streams.io.StoredFileHelper
import org.schabi.newpipe.util.ZipHelper import org.schabi.newpipe.util.ZipHelper
@ -13,6 +14,9 @@ import java.io.ObjectOutputStream
import java.util.zip.ZipOutputStream import java.util.zip.ZipOutputStream
class ContentSettingsManager(private val fileLocator: NewPipeFileLocator) { class ContentSettingsManager(private val fileLocator: NewPipeFileLocator) {
companion object {
const val TAG = "ContentSetManager"
}
/** /**
* Exports given [SharedPreferences] to the file in given outputPath. * Exports given [SharedPreferences] to the file in given outputPath.
@ -31,7 +35,7 @@ class ContentSettingsManager(private val fileLocator: NewPipeFileLocator) {
output.flush() output.flush()
} }
} catch (e: IOException) { } catch (e: IOException) {
e.printStackTrace() Log.e(TAG, "Unable to exportDatabase", e)
} }
ZipHelper.addFileToZip(outZip, fileLocator.settings.path, "newpipe.settings") ZipHelper.addFileToZip(outZip, fileLocator.settings.path, "newpipe.settings")
@ -101,9 +105,9 @@ class ContentSettingsManager(private val fileLocator: NewPipeFileLocator) {
preferenceEditor.commit() preferenceEditor.commit()
} }
} catch (e: IOException) { } catch (e: IOException) {
e.printStackTrace() Log.e(TAG, "Unable to loadSharedPreferences", e)
} catch (e: ClassNotFoundException) { } catch (e: ClassNotFoundException) {
e.printStackTrace() Log.e(TAG, "Unable to loadSharedPreferences", e)
} }
} }
} }

View file

@ -10,9 +10,8 @@ import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext; import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocket; import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory; import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import static org.schabi.newpipe.MainActivity.DEBUG; import android.util.Log;
/** /**
@ -21,6 +20,7 @@ import static org.schabi.newpipe.MainActivity.DEBUG;
*/ */
public class TLSSocketFactoryCompat extends SSLSocketFactory { public class TLSSocketFactoryCompat extends SSLSocketFactory {
private static final String TAG = "TLSSocketFactoryCom";
private static TLSSocketFactoryCompat instance = null; private static TLSSocketFactoryCompat instance = null;
@ -32,14 +32,6 @@ public class TLSSocketFactoryCompat extends SSLSocketFactory {
internalSSLSocketFactory = context.getSocketFactory(); 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() public static TLSSocketFactoryCompat getInstance()
throws NoSuchAlgorithmException, KeyManagementException { throws NoSuchAlgorithmException, KeyManagementException {
if (instance != null) { if (instance != null) {
@ -53,9 +45,7 @@ public class TLSSocketFactoryCompat extends SSLSocketFactory {
try { try {
HttpsURLConnection.setDefaultSSLSocketFactory(getInstance()); HttpsURLConnection.setDefaultSSLSocketFactory(getInstance());
} catch (NoSuchAlgorithmException | KeyManagementException e) { } catch (NoSuchAlgorithmException | KeyManagementException e) {
if (DEBUG) { Log.e(TAG, "Unable to setAsDefault", e);
e.printStackTrace();
}
} }
} }