Skip to content

Commit

Permalink
ServiceHelper: convert switches to switch expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
Profpatsch committed Jan 8, 2024
1 parent a9d1848 commit 27ff20d
Showing 1 changed file with 30 additions and 56 deletions.
86 changes: 30 additions & 56 deletions app/src/main/java/org/schabi/newpipe/util/ServiceHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,52 +31,31 @@ private ServiceHelper() { }

@DrawableRes
public static int getIcon(final int serviceId) {
switch (serviceId) {
case 0:
return R.drawable.ic_smart_display;
case 1:
return R.drawable.ic_cloud;
case 2:
return R.drawable.ic_placeholder_media_ccc;
case 3:
return R.drawable.ic_placeholder_peertube;
case 4:
return R.drawable.ic_placeholder_bandcamp;
default:
return R.drawable.ic_circle;
}
return switch (serviceId) {
case 0 -> R.drawable.ic_smart_display;
case 1 -> R.drawable.ic_cloud;
case 2 -> R.drawable.ic_placeholder_media_ccc;
case 3 -> R.drawable.ic_placeholder_peertube;
case 4 -> R.drawable.ic_placeholder_bandcamp;
default -> R.drawable.ic_circle;
};
}

public static String getTranslatedFilterString(final String filter, final Context c) {
switch (filter) {
case "all":
return c.getString(R.string.all);
case "videos":
case "sepia_videos":
case "music_videos":
return c.getString(R.string.videos_string);
case "channels":
return c.getString(R.string.channels);
case "playlists":
case "music_playlists":
return c.getString(R.string.playlists);
case "tracks":
return c.getString(R.string.tracks);
case "users":
return c.getString(R.string.users);
case "conferences":
return c.getString(R.string.conferences);
case "events":
return c.getString(R.string.events);
case "music_songs":
return c.getString(R.string.songs);
case "music_albums":
return c.getString(R.string.albums);
case "music_artists":
return c.getString(R.string.artists);
default:
return filter;
}
return switch (filter) {
case "all" -> c.getString(R.string.all);
case "videos", "sepia_videos", "music_videos" -> c.getString(R.string.videos_string);
case "channels" -> c.getString(R.string.channels);
case "playlists", "music_playlists" -> c.getString(R.string.playlists);
case "tracks" -> c.getString(R.string.tracks);
case "users" -> c.getString(R.string.users);
case "conferences" -> c.getString(R.string.conferences);
case "events" -> c.getString(R.string.events);
case "music_songs" -> c.getString(R.string.songs);
case "music_albums" -> c.getString(R.string.albums);
case "music_artists" -> c.getString(R.string.artists);
default -> filter;
};
}

/**
Expand All @@ -87,14 +66,11 @@ public static String getTranslatedFilterString(final String filter, final Contex
*/
@StringRes
public static int getImportInstructions(final int serviceId) {
switch (serviceId) {
case 0:
return R.string.import_youtube_instructions;
case 1:
return R.string.import_soundcloud_instructions;
default:
return -1;
}
return switch (serviceId) {
case 0 -> R.string.import_youtube_instructions;
case 1 -> R.string.import_soundcloud_instructions;
default -> -1;
};
}

/**
Expand All @@ -106,12 +82,10 @@ public static int getImportInstructions(final int serviceId) {
*/
@StringRes
public static int getImportInstructionsHint(final int serviceId) {
switch (serviceId) {
case 1:
return R.string.import_soundcloud_instructions_hint;
default:
return -1;
if (serviceId == 1) {
return R.string.import_soundcloud_instructions_hint;
}
return -1;
}

public static int getSelectedServiceIdOrFallback(final Context context) {
Expand Down

0 comments on commit 27ff20d

Please sign in to comment.