Skip to content

Commit 2e8e203

Browse files
authored
Merge pull request #12963 from dustdfg/misc_refactor
Misc small refactors (mostly replacing old switch syntax with new)
2 parents cd056a7 + 127064d commit 2e8e203

File tree

4 files changed

+69
-134
lines changed

4 files changed

+69
-134
lines changed

app/src/main/java/org/schabi/newpipe/RouterActivity.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -361,15 +361,9 @@ protected void onSuccess() {
361361
// Default / Ask always
362362
final List<AdapterChoiceItem> availableChoices = choiceChecker.getAvailableChoices();
363363
switch (availableChoices.size()) {
364-
case 1:
365-
handleChoice(availableChoices.get(0).key);
366-
break;
367-
case 0:
368-
handleChoice(getString(R.string.show_info_key));
369-
break;
370-
default:
371-
showDialog(availableChoices);
372-
break;
364+
case 1 -> handleChoice(availableChoices.get(0).key);
365+
case 0 -> handleChoice(getString(R.string.show_info_key));
366+
default -> showDialog(availableChoices);
373367
}
374368
}
375369

app/src/main/java/org/schabi/newpipe/util/ChannelTabHelper.java

Lines changed: 30 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -48,68 +48,44 @@ public static boolean isStreamsTab(final ListLinkHandler tab) {
4848

4949
@StringRes
5050
private static int getShowTabKey(final String tab) {
51-
switch (tab) {
52-
case ChannelTabs.VIDEOS:
53-
return R.string.show_channel_tabs_videos;
54-
case ChannelTabs.TRACKS:
55-
return R.string.show_channel_tabs_tracks;
56-
case ChannelTabs.SHORTS:
57-
return R.string.show_channel_tabs_shorts;
58-
case ChannelTabs.LIVESTREAMS:
59-
return R.string.show_channel_tabs_livestreams;
60-
case ChannelTabs.CHANNELS:
61-
return R.string.show_channel_tabs_channels;
62-
case ChannelTabs.PLAYLISTS:
63-
return R.string.show_channel_tabs_playlists;
64-
case ChannelTabs.ALBUMS:
65-
return R.string.show_channel_tabs_albums;
66-
case ChannelTabs.LIKES:
67-
return R.string.show_channel_tabs_likes;
68-
default:
69-
return -1;
70-
}
51+
return switch (tab) {
52+
case ChannelTabs.VIDEOS -> R.string.show_channel_tabs_videos;
53+
case ChannelTabs.TRACKS -> R.string.show_channel_tabs_tracks;
54+
case ChannelTabs.SHORTS -> R.string.show_channel_tabs_shorts;
55+
case ChannelTabs.LIVESTREAMS -> R.string.show_channel_tabs_livestreams;
56+
case ChannelTabs.CHANNELS -> R.string.show_channel_tabs_channels;
57+
case ChannelTabs.PLAYLISTS -> R.string.show_channel_tabs_playlists;
58+
case ChannelTabs.ALBUMS -> R.string.show_channel_tabs_albums;
59+
case ChannelTabs.LIKES -> R.string.show_channel_tabs_likes;
60+
default -> -1;
61+
};
7162
}
7263

7364
@StringRes
7465
private static int getFetchFeedTabKey(final String tab) {
75-
switch (tab) {
76-
case ChannelTabs.VIDEOS:
77-
return R.string.fetch_channel_tabs_videos;
78-
case ChannelTabs.TRACKS:
79-
return R.string.fetch_channel_tabs_tracks;
80-
case ChannelTabs.SHORTS:
81-
return R.string.fetch_channel_tabs_shorts;
82-
case ChannelTabs.LIVESTREAMS:
83-
return R.string.fetch_channel_tabs_livestreams;
84-
case ChannelTabs.LIKES:
85-
return R.string.fetch_channel_tabs_likes;
86-
default:
87-
return -1;
88-
}
66+
return switch (tab) {
67+
case ChannelTabs.VIDEOS -> R.string.fetch_channel_tabs_videos;
68+
case ChannelTabs.TRACKS -> R.string.fetch_channel_tabs_tracks;
69+
case ChannelTabs.SHORTS -> R.string.fetch_channel_tabs_shorts;
70+
case ChannelTabs.LIVESTREAMS -> R.string.fetch_channel_tabs_livestreams;
71+
case ChannelTabs.LIKES -> R.string.fetch_channel_tabs_likes;
72+
default -> -1;
73+
};
8974
}
9075

9176
@StringRes
9277
public static int getTranslationKey(final String tab) {
93-
switch (tab) {
94-
case ChannelTabs.VIDEOS:
95-
return R.string.channel_tab_videos;
96-
case ChannelTabs.TRACKS:
97-
return R.string.channel_tab_tracks;
98-
case ChannelTabs.SHORTS:
99-
return R.string.channel_tab_shorts;
100-
case ChannelTabs.LIVESTREAMS:
101-
return R.string.channel_tab_livestreams;
102-
case ChannelTabs.CHANNELS:
103-
return R.string.channel_tab_channels;
104-
case ChannelTabs.PLAYLISTS:
105-
return R.string.channel_tab_playlists;
106-
case ChannelTabs.ALBUMS:
107-
return R.string.channel_tab_albums;
108-
case ChannelTabs.LIKES:
109-
return R.string.channel_tab_likes;
110-
default:
111-
return R.string.unknown_content;
112-
}
78+
return switch (tab) {
79+
case ChannelTabs.VIDEOS -> R.string.channel_tab_videos;
80+
case ChannelTabs.TRACKS -> R.string.channel_tab_tracks;
81+
case ChannelTabs.SHORTS -> R.string.channel_tab_shorts;
82+
case ChannelTabs.LIVESTREAMS -> R.string.channel_tab_livestreams;
83+
case ChannelTabs.CHANNELS -> R.string.channel_tab_channels;
84+
case ChannelTabs.PLAYLISTS -> R.string.channel_tab_playlists;
85+
case ChannelTabs.ALBUMS -> R.string.channel_tab_albums;
86+
case ChannelTabs.LIKES -> R.string.channel_tab_likes;
87+
default -> R.string.unknown_content;
88+
};
11389
}
11490

11591
public static boolean showChannelTab(final Context context,

app/src/main/java/org/schabi/newpipe/util/SavedState.kt

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,12 @@ import kotlinx.parcelize.Parcelize
55

66
/**
77
* Information about the saved state on the disk.
8+
* Path to the saved file.
9+
*
10+
* @property prefixFileSaved Prefix of the saved file
11+
* @property pathFileSaved Path to the saved file
812
*/
913
@Parcelize
10-
class SavedState(
11-
/**
12-
* Get the prefix of the saved file.
13-
*
14-
* @return the file prefix
15-
*/
16-
val prefixFileSaved: String,
17-
/**
18-
* Get the path to the saved file.
19-
*
20-
* @return the path to the saved file
21-
*/
22-
val pathFileSaved: String
23-
) : Parcelable {
14+
class SavedState(val prefixFileSaved: String, val pathFileSaved: String) : Parcelable {
2415
override fun toString() = "$prefixFileSaved > $pathFileSaved"
2516
}

app/src/main/java/org/schabi/newpipe/util/ServiceHelper.java

Lines changed: 31 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -32,52 +32,31 @@ private ServiceHelper() { }
3232

3333
@DrawableRes
3434
public static int getIcon(final int serviceId) {
35-
switch (serviceId) {
36-
case 0:
37-
return R.drawable.ic_smart_display;
38-
case 1:
39-
return R.drawable.ic_cloud;
40-
case 2:
41-
return R.drawable.ic_placeholder_media_ccc;
42-
case 3:
43-
return R.drawable.ic_placeholder_peertube;
44-
case 4:
45-
return R.drawable.ic_placeholder_bandcamp;
46-
default:
47-
return R.drawable.ic_circle;
48-
}
35+
return switch (serviceId) {
36+
case 0 -> R.drawable.ic_smart_display;
37+
case 1 -> R.drawable.ic_cloud;
38+
case 2 -> R.drawable.ic_placeholder_media_ccc;
39+
case 3 -> R.drawable.ic_placeholder_peertube;
40+
case 4 -> R.drawable.ic_placeholder_bandcamp;
41+
default -> R.drawable.ic_circle;
42+
};
4943
}
5044

5145
public static String getTranslatedFilterString(final String filter, final Context c) {
52-
switch (filter) {
53-
case "all":
54-
return c.getString(R.string.all);
55-
case "videos":
56-
case "sepia_videos":
57-
case "music_videos":
58-
return c.getString(R.string.videos_string);
59-
case "channels":
60-
return c.getString(R.string.channels);
61-
case "playlists":
62-
case "music_playlists":
63-
return c.getString(R.string.playlists);
64-
case "tracks":
65-
return c.getString(R.string.tracks);
66-
case "users":
67-
return c.getString(R.string.users);
68-
case "conferences":
69-
return c.getString(R.string.conferences);
70-
case "events":
71-
return c.getString(R.string.events);
72-
case "music_songs":
73-
return c.getString(R.string.songs);
74-
case "music_albums":
75-
return c.getString(R.string.albums);
76-
case "music_artists":
77-
return c.getString(R.string.artists);
78-
default:
79-
return filter;
80-
}
46+
return switch (filter) {
47+
case "all" -> c.getString(R.string.all);
48+
case "videos", "sepia_videos", "music_videos" -> c.getString(R.string.videos_string);
49+
case "channels" -> c.getString(R.string.channels);
50+
case "playlists", "music_playlists" -> c.getString(R.string.playlists);
51+
case "tracks" -> c.getString(R.string.tracks);
52+
case "users" -> c.getString(R.string.users);
53+
case "conferences" -> c.getString(R.string.conferences);
54+
case "events" -> c.getString(R.string.events);
55+
case "music_songs" -> c.getString(R.string.songs);
56+
case "music_albums" -> c.getString(R.string.albums);
57+
case "music_artists" -> c.getString(R.string.artists);
58+
default -> filter;
59+
};
8160
}
8261

8362
/**
@@ -88,14 +67,11 @@ public static String getTranslatedFilterString(final String filter, final Contex
8867
*/
8968
@StringRes
9069
public static int getImportInstructions(final int serviceId) {
91-
switch (serviceId) {
92-
case 0:
93-
return R.string.import_youtube_instructions;
94-
case 1:
95-
return R.string.import_soundcloud_instructions;
96-
default:
97-
return -1;
98-
}
70+
return switch (serviceId) {
71+
case 0 -> R.string.import_youtube_instructions;
72+
case 1 -> R.string.import_soundcloud_instructions;
73+
default -> -1;
74+
};
9975
}
10076

10177
/**
@@ -107,12 +83,10 @@ public static int getImportInstructions(final int serviceId) {
10783
*/
10884
@StringRes
10985
public static int getImportInstructionsHint(final int serviceId) {
110-
switch (serviceId) {
111-
case 1:
112-
return R.string.import_soundcloud_instructions_hint;
113-
default:
114-
return -1;
115-
}
86+
return switch (serviceId) {
87+
case 1 -> R.string.import_soundcloud_instructions_hint;
88+
default -> -1;
89+
};
11690
}
11791

11892
public static int getSelectedServiceId(final Context context) {

0 commit comments

Comments
 (0)