Merge pull request #12963 from dustdfg/misc_refactor
Misc small refactors (mostly replacing old switch syntax with new)
This commit is contained in:
commit
2e8e203276
@ -361,15 +361,9 @@ public class RouterActivity extends AppCompatActivity {
|
||||
// Default / Ask always
|
||||
final List<AdapterChoiceItem> availableChoices = choiceChecker.getAvailableChoices();
|
||||
switch (availableChoices.size()) {
|
||||
case 1:
|
||||
handleChoice(availableChoices.get(0).key);
|
||||
break;
|
||||
case 0:
|
||||
handleChoice(getString(R.string.show_info_key));
|
||||
break;
|
||||
default:
|
||||
showDialog(availableChoices);
|
||||
break;
|
||||
case 1 -> handleChoice(availableChoices.get(0).key);
|
||||
case 0 -> handleChoice(getString(R.string.show_info_key));
|
||||
default -> showDialog(availableChoices);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -48,68 +48,44 @@ public final class ChannelTabHelper {
|
||||
|
||||
@StringRes
|
||||
private static int getShowTabKey(final String tab) {
|
||||
switch (tab) {
|
||||
case ChannelTabs.VIDEOS:
|
||||
return R.string.show_channel_tabs_videos;
|
||||
case ChannelTabs.TRACKS:
|
||||
return R.string.show_channel_tabs_tracks;
|
||||
case ChannelTabs.SHORTS:
|
||||
return R.string.show_channel_tabs_shorts;
|
||||
case ChannelTabs.LIVESTREAMS:
|
||||
return R.string.show_channel_tabs_livestreams;
|
||||
case ChannelTabs.CHANNELS:
|
||||
return R.string.show_channel_tabs_channels;
|
||||
case ChannelTabs.PLAYLISTS:
|
||||
return R.string.show_channel_tabs_playlists;
|
||||
case ChannelTabs.ALBUMS:
|
||||
return R.string.show_channel_tabs_albums;
|
||||
case ChannelTabs.LIKES:
|
||||
return R.string.show_channel_tabs_likes;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
return switch (tab) {
|
||||
case ChannelTabs.VIDEOS -> R.string.show_channel_tabs_videos;
|
||||
case ChannelTabs.TRACKS -> R.string.show_channel_tabs_tracks;
|
||||
case ChannelTabs.SHORTS -> R.string.show_channel_tabs_shorts;
|
||||
case ChannelTabs.LIVESTREAMS -> R.string.show_channel_tabs_livestreams;
|
||||
case ChannelTabs.CHANNELS -> R.string.show_channel_tabs_channels;
|
||||
case ChannelTabs.PLAYLISTS -> R.string.show_channel_tabs_playlists;
|
||||
case ChannelTabs.ALBUMS -> R.string.show_channel_tabs_albums;
|
||||
case ChannelTabs.LIKES -> R.string.show_channel_tabs_likes;
|
||||
default -> -1;
|
||||
};
|
||||
}
|
||||
|
||||
@StringRes
|
||||
private static int getFetchFeedTabKey(final String tab) {
|
||||
switch (tab) {
|
||||
case ChannelTabs.VIDEOS:
|
||||
return R.string.fetch_channel_tabs_videos;
|
||||
case ChannelTabs.TRACKS:
|
||||
return R.string.fetch_channel_tabs_tracks;
|
||||
case ChannelTabs.SHORTS:
|
||||
return R.string.fetch_channel_tabs_shorts;
|
||||
case ChannelTabs.LIVESTREAMS:
|
||||
return R.string.fetch_channel_tabs_livestreams;
|
||||
case ChannelTabs.LIKES:
|
||||
return R.string.fetch_channel_tabs_likes;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
return switch (tab) {
|
||||
case ChannelTabs.VIDEOS -> R.string.fetch_channel_tabs_videos;
|
||||
case ChannelTabs.TRACKS -> R.string.fetch_channel_tabs_tracks;
|
||||
case ChannelTabs.SHORTS -> R.string.fetch_channel_tabs_shorts;
|
||||
case ChannelTabs.LIVESTREAMS -> R.string.fetch_channel_tabs_livestreams;
|
||||
case ChannelTabs.LIKES -> R.string.fetch_channel_tabs_likes;
|
||||
default -> -1;
|
||||
};
|
||||
}
|
||||
|
||||
@StringRes
|
||||
public static int getTranslationKey(final String tab) {
|
||||
switch (tab) {
|
||||
case ChannelTabs.VIDEOS:
|
||||
return R.string.channel_tab_videos;
|
||||
case ChannelTabs.TRACKS:
|
||||
return R.string.channel_tab_tracks;
|
||||
case ChannelTabs.SHORTS:
|
||||
return R.string.channel_tab_shorts;
|
||||
case ChannelTabs.LIVESTREAMS:
|
||||
return R.string.channel_tab_livestreams;
|
||||
case ChannelTabs.CHANNELS:
|
||||
return R.string.channel_tab_channels;
|
||||
case ChannelTabs.PLAYLISTS:
|
||||
return R.string.channel_tab_playlists;
|
||||
case ChannelTabs.ALBUMS:
|
||||
return R.string.channel_tab_albums;
|
||||
case ChannelTabs.LIKES:
|
||||
return R.string.channel_tab_likes;
|
||||
default:
|
||||
return R.string.unknown_content;
|
||||
}
|
||||
return switch (tab) {
|
||||
case ChannelTabs.VIDEOS -> R.string.channel_tab_videos;
|
||||
case ChannelTabs.TRACKS -> R.string.channel_tab_tracks;
|
||||
case ChannelTabs.SHORTS -> R.string.channel_tab_shorts;
|
||||
case ChannelTabs.LIVESTREAMS -> R.string.channel_tab_livestreams;
|
||||
case ChannelTabs.CHANNELS -> R.string.channel_tab_channels;
|
||||
case ChannelTabs.PLAYLISTS -> R.string.channel_tab_playlists;
|
||||
case ChannelTabs.ALBUMS -> R.string.channel_tab_albums;
|
||||
case ChannelTabs.LIKES -> R.string.channel_tab_likes;
|
||||
default -> R.string.unknown_content;
|
||||
};
|
||||
}
|
||||
|
||||
public static boolean showChannelTab(final Context context,
|
||||
|
||||
@ -5,21 +5,12 @@ import kotlinx.parcelize.Parcelize
|
||||
|
||||
/**
|
||||
* Information about the saved state on the disk.
|
||||
* Path to the saved file.
|
||||
*
|
||||
* @property prefixFileSaved Prefix of the saved file
|
||||
* @property pathFileSaved Path to the saved file
|
||||
*/
|
||||
@Parcelize
|
||||
class SavedState(
|
||||
/**
|
||||
* Get the prefix of the saved file.
|
||||
*
|
||||
* @return the file prefix
|
||||
*/
|
||||
val prefixFileSaved: String,
|
||||
/**
|
||||
* Get the path to the saved file.
|
||||
*
|
||||
* @return the path to the saved file
|
||||
*/
|
||||
val pathFileSaved: String
|
||||
) : Parcelable {
|
||||
class SavedState(val prefixFileSaved: String, val pathFileSaved: String) : Parcelable {
|
||||
override fun toString() = "$prefixFileSaved > $pathFileSaved"
|
||||
}
|
||||
|
||||
@ -32,52 +32,31 @@ public final class 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;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
@ -88,14 +67,11 @@ public final class ServiceHelper {
|
||||
*/
|
||||
@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;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
@ -107,12 +83,10 @@ public final class ServiceHelper {
|
||||
*/
|
||||
@StringRes
|
||||
public static int getImportInstructionsHint(final int serviceId) {
|
||||
switch (serviceId) {
|
||||
case 1:
|
||||
return R.string.import_soundcloud_instructions_hint;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
return switch (serviceId) {
|
||||
case 1 -> R.string.import_soundcloud_instructions_hint;
|
||||
default -> -1;
|
||||
};
|
||||
}
|
||||
|
||||
public static int getSelectedServiceId(final Context context) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user