Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import static org.schabi.newpipe.player.helper.PlayerHelper.MinimizeMode.MINIMIZE_ON_EXIT_MODE_BACKGROUND;
import static org.schabi.newpipe.player.helper.PlayerHelper.MinimizeMode.MINIMIZE_ON_EXIT_MODE_NONE;
import static org.schabi.newpipe.player.helper.PlayerHelper.MinimizeMode.MINIMIZE_ON_EXIT_MODE_POPUP;
import static java.lang.annotation.RetentionPolicy.SOURCE;

import android.annotation.SuppressLint;
import android.content.Context;
Expand All @@ -15,7 +14,6 @@
import android.provider.Settings;
import android.view.accessibility.CaptioningManager;

import androidx.annotation.IntDef;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
Expand Down Expand Up @@ -43,7 +41,6 @@
import org.schabi.newpipe.util.ListHelper;
import org.schabi.newpipe.util.Localization;

import java.lang.annotation.Retention;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.NumberFormat;
Expand All @@ -59,22 +56,16 @@
public final class PlayerHelper {
private static final FormattersProvider FORMATTERS_PROVIDER = new FormattersProvider();

@Retention(SOURCE)
@IntDef({AUTOPLAY_TYPE_ALWAYS, AUTOPLAY_TYPE_WIFI,
AUTOPLAY_TYPE_NEVER})
public @interface AutoplayType {
int AUTOPLAY_TYPE_ALWAYS = 0;
int AUTOPLAY_TYPE_WIFI = 1;
int AUTOPLAY_TYPE_NEVER = 2;
public enum AutoplayType {
AUTOPLAY_TYPE_ALWAYS,
AUTOPLAY_TYPE_WIFI,
AUTOPLAY_TYPE_NEVER
}

@Retention(SOURCE)
@IntDef({MINIMIZE_ON_EXIT_MODE_NONE, MINIMIZE_ON_EXIT_MODE_BACKGROUND,
MINIMIZE_ON_EXIT_MODE_POPUP})
public @interface MinimizeMode {
int MINIMIZE_ON_EXIT_MODE_NONE = 0;
int MINIMIZE_ON_EXIT_MODE_BACKGROUND = 1;
int MINIMIZE_ON_EXIT_MODE_POPUP = 2;
public enum MinimizeMode {
MINIMIZE_ON_EXIT_MODE_NONE,
MINIMIZE_ON_EXIT_MODE_BACKGROUND,
MINIMIZE_ON_EXIT_MODE_POPUP
}

private PlayerHelper() {
Expand Down Expand Up @@ -236,8 +227,7 @@ public static boolean isClearingQueueConfirmationRequired(@NonNull final Context
.getBoolean(context.getString(R.string.clear_queue_confirmation_key), false);
}

@MinimizeMode
public static int getMinimizeOnExitAction(@NonNull final Context context) {
public static MinimizeMode getMinimizeOnExitAction(@NonNull final Context context) {
final String action = getPreferences(context)
.getString(context.getString(R.string.minimize_on_exit_key), "");
if (action.equals(context.getString(R.string.minimize_on_exit_popup_key))) {
Expand All @@ -249,8 +239,8 @@ public static int getMinimizeOnExitAction(@NonNull final Context context) {
}
}

@AutoplayType
public static int getAutoplayType(@NonNull final Context context) {

public static AutoplayType getAutoplayType(@NonNull final Context context) {
final String type = getPreferences(context).getString(
context.getString(R.string.autoplay_key), "");
if (type.equals(context.getString(R.string.autoplay_always_key))) {
Expand All @@ -263,15 +253,11 @@ public static int getAutoplayType(@NonNull final Context context) {
}

public static boolean isAutoplayAllowedByUser(@NonNull final Context context) {
switch (PlayerHelper.getAutoplayType(context)) {
case PlayerHelper.AutoplayType.AUTOPLAY_TYPE_NEVER:
return false;
case PlayerHelper.AutoplayType.AUTOPLAY_TYPE_WIFI:
return !ListHelper.isMeteredNetwork(context);
case PlayerHelper.AutoplayType.AUTOPLAY_TYPE_ALWAYS:
default:
return true;
}
return switch (PlayerHelper.getAutoplayType(context)) {
case AUTOPLAY_TYPE_NEVER -> false;
case AUTOPLAY_TYPE_WIFI -> !ListHelper.isMeteredNetwork(context);
case AUTOPLAY_TYPE_ALWAYS -> true;
};
}

@NonNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import android.view.View;
import android.widget.ImageView;

import androidx.annotation.IntDef;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.graphics.BitmapCompat;
Expand All @@ -16,10 +15,8 @@
import org.schabi.newpipe.R;
import org.schabi.newpipe.util.DeviceUtils;

import java.lang.annotation.Retention;
import java.util.function.IntSupplier;

import static java.lang.annotation.RetentionPolicy.SOURCE;
import static org.schabi.newpipe.player.seekbarpreview.SeekbarPreviewThumbnailHelper.SeekbarPreviewThumbnailType.HIGH_QUALITY;
import static org.schabi.newpipe.player.seekbarpreview.SeekbarPreviewThumbnailHelper.SeekbarPreviewThumbnailType.LOW_QUALITY;
import static org.schabi.newpipe.player.seekbarpreview.SeekbarPreviewThumbnailHelper.SeekbarPreviewThumbnailType.NONE;
Expand All @@ -38,21 +35,19 @@ private SeekbarPreviewThumbnailHelper() {
// No impl pls
}

@Retention(SOURCE)
@IntDef({HIGH_QUALITY, LOW_QUALITY,
NONE})
public @interface SeekbarPreviewThumbnailType {
int HIGH_QUALITY = 0;
int LOW_QUALITY = 1;
int NONE = 2;

public enum SeekbarPreviewThumbnailType {
HIGH_QUALITY,
LOW_QUALITY,
NONE,
}

////////////////////////////////////////////////////////////////////////////
// Settings Resolution
///////////////////////////////////////////////////////////////////////////

@SeekbarPreviewThumbnailType
public static int getSeekbarPreviewThumbnailType(@NonNull final Context context) {
public static SeekbarPreviewThumbnailType getSeekbarPreviewThumbnailType(
@NonNull final Context context) {
final String type = PreferenceManager.getDefaultSharedPreferences(context).getString(
context.getString(R.string.seekbar_preview_thumbnail_key), "");
if (type.equals(context.getString(R.string.seekbar_preview_thumbnail_none))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class SeekbarPreviewThumbnailHolder {
private UUID currentUpdateRequestIdentifier = UUID.randomUUID();

public void resetFrom(@NonNull final Context context, final List<Frameset> framesets) {
final int seekbarPreviewType = getSeekbarPreviewThumbnailType(context);
final var seekbarPreviewType = getSeekbarPreviewThumbnailType(context);

final UUID updateRequestIdentifier = UUID.randomUUID();
this.currentUpdateRequestIdentifier = updateRequestIdentifier;
Expand All @@ -59,7 +59,8 @@ public void resetFrom(@NonNull final Context context, final List<Frameset> frame
executorService.shutdown();
}

private void resetFromAsync(final int seekbarPreviewType, final List<Frameset> framesets,
private void resetFromAsync(final SeekbarPreviewThumbnailType seekbarPreviewType,
final List<Frameset> framesets,
final UUID updateRequestIdentifier) {
Log.d(TAG, "Clearing seekbarPreviewData");
synchronized (seekbarPreviewData) {
Expand Down Expand Up @@ -90,7 +91,7 @@ private void resetFromAsync(final int seekbarPreviewType, final List<Frameset> f
}

private Frameset getFrameSetForType(final List<Frameset> framesets,
final int seekbarPreviewType) {
final SeekbarPreviewThumbnailType seekbarPreviewType) {
if (seekbarPreviewType == SeekbarPreviewThumbnailType.HIGH_QUALITY) {
Log.d(TAG, "Strategy for seekbarPreviewData: high quality");
return framesets.stream()
Expand Down