Skip to content

Commit 9e540db

Browse files
author
Yevhen Babiichuk (DustDFG)
committed
Convert AutoplayType to normal enum
1 parent 30f77e8 commit 9e540db

1 file changed

Lines changed: 11 additions & 21 deletions

File tree

app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import static org.schabi.newpipe.player.helper.PlayerHelper.MinimizeMode.MINIMIZE_ON_EXIT_MODE_BACKGROUND;
77
import static org.schabi.newpipe.player.helper.PlayerHelper.MinimizeMode.MINIMIZE_ON_EXIT_MODE_NONE;
88
import static org.schabi.newpipe.player.helper.PlayerHelper.MinimizeMode.MINIMIZE_ON_EXIT_MODE_POPUP;
9-
import static java.lang.annotation.RetentionPolicy.SOURCE;
109

1110
import android.annotation.SuppressLint;
1211
import android.content.Context;
@@ -15,7 +14,6 @@
1514
import android.provider.Settings;
1615
import android.view.accessibility.CaptioningManager;
1716

18-
import androidx.annotation.IntDef;
1917
import androidx.annotation.NonNull;
2018
import androidx.annotation.Nullable;
2119
import androidx.core.content.ContextCompat;
@@ -43,7 +41,6 @@
4341
import org.schabi.newpipe.util.ListHelper;
4442
import org.schabi.newpipe.util.Localization;
4543

46-
import java.lang.annotation.Retention;
4744
import java.text.DecimalFormat;
4845
import java.text.DecimalFormatSymbols;
4946
import java.text.NumberFormat;
@@ -59,13 +56,10 @@
5956
public final class PlayerHelper {
6057
private static final FormattersProvider FORMATTERS_PROVIDER = new FormattersProvider();
6158

62-
@Retention(SOURCE)
63-
@IntDef({AUTOPLAY_TYPE_ALWAYS, AUTOPLAY_TYPE_WIFI,
64-
AUTOPLAY_TYPE_NEVER})
65-
public @interface AutoplayType {
66-
int AUTOPLAY_TYPE_ALWAYS = 0;
67-
int AUTOPLAY_TYPE_WIFI = 1;
68-
int AUTOPLAY_TYPE_NEVER = 2;
59+
public enum AutoplayType {
60+
AUTOPLAY_TYPE_ALWAYS,
61+
AUTOPLAY_TYPE_WIFI,
62+
AUTOPLAY_TYPE_NEVER
6963
}
7064

7165
public enum MinimizeMode {
@@ -245,8 +239,8 @@ public static MinimizeMode getMinimizeOnExitAction(@NonNull final Context contex
245239
}
246240
}
247241

248-
@AutoplayType
249-
public static int getAutoplayType(@NonNull final Context context) {
242+
243+
public static AutoplayType getAutoplayType(@NonNull final Context context) {
250244
final String type = getPreferences(context).getString(
251245
context.getString(R.string.autoplay_key), "");
252246
if (type.equals(context.getString(R.string.autoplay_always_key))) {
@@ -259,15 +253,11 @@ public static int getAutoplayType(@NonNull final Context context) {
259253
}
260254

261255
public static boolean isAutoplayAllowedByUser(@NonNull final Context context) {
262-
switch (PlayerHelper.getAutoplayType(context)) {
263-
case PlayerHelper.AutoplayType.AUTOPLAY_TYPE_NEVER:
264-
return false;
265-
case PlayerHelper.AutoplayType.AUTOPLAY_TYPE_WIFI:
266-
return !ListHelper.isMeteredNetwork(context);
267-
case PlayerHelper.AutoplayType.AUTOPLAY_TYPE_ALWAYS:
268-
default:
269-
return true;
270-
}
256+
return switch (PlayerHelper.getAutoplayType(context)) {
257+
case AUTOPLAY_TYPE_NEVER -> false;
258+
case AUTOPLAY_TYPE_WIFI -> !ListHelper.isMeteredNetwork(context);
259+
case AUTOPLAY_TYPE_ALWAYS -> true;
260+
};
271261
}
272262

273263
@NonNull

0 commit comments

Comments
 (0)