Use toArray() with zero-length arrays.

This commit is contained in:
Isira Seneviratne 2022-07-30 00:51:15 +05:30
parent 4ed7229861
commit b49b8f325d
7 changed files with 16 additions and 29 deletions

View file

@ -14,7 +14,6 @@ import org.schabi.newpipe.util.Localization;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.SortedSet;
import java.util.TreeSet;
@ -115,7 +114,7 @@ public final class NotificationConstants {
};
public static final Integer[] SLOT_COMPACT_DEFAULTS = {0, 1, 2};
public static final List<Integer> SLOT_COMPACT_DEFAULTS = List.of(0, 1, 2);
public static final int[] SLOT_COMPACT_PREF_KEYS = {
R.string.notification_slot_compact_0_key,
@ -181,7 +180,7 @@ public final class NotificationConstants {
if (compactSlot == Integer.MAX_VALUE) {
// settings not yet populated, return default values
return new ArrayList<>(Arrays.asList(SLOT_COMPACT_DEFAULTS));
return SLOT_COMPACT_DEFAULTS;
}
// a negative value (-1) is set when the user does not want a particular compact slot

View file

@ -99,10 +99,7 @@ public final class NotificationUtil {
// build the compact slot indices array (need code to convert from Integer... because Java)
final List<Integer> compactSlotList = NotificationConstants.getCompactSlotsFromPreferences(
player.getContext(), player.getPrefs(), nonNothingSlotCount);
final int[] compactSlots = new int[compactSlotList.size()];
for (int i = 0; i < compactSlotList.size(); i++) {
compactSlots[i] = compactSlotList.get(i);
}
final int[] compactSlots = compactSlotList.stream().mapToInt(i -> i).toArray();
builder.setStyle(new androidx.media.app.NotificationCompat.MediaStyle()
.setMediaSession(player.getMediaSessionManager().getSessionToken())