From 45de9fc8f2dd57ca1d36e6d48c02899203e2cd4a Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 27 Apr 2024 17:04:32 +0700 Subject: [PATCH] simplify switch case flow foe Utility --- .../java/us/shandian/giga/util/Utility.java | 55 ++++++------------- 1 file changed, 17 insertions(+), 38 deletions(-) diff --git a/app/src/main/java/us/shandian/giga/util/Utility.java b/app/src/main/java/us/shandian/giga/util/Utility.java index c75269757..f724c35e1 100644 --- a/app/src/main/java/us/shandian/giga/util/Utility.java +++ b/app/src/main/java/us/shandian/giga/util/Utility.java @@ -153,56 +153,35 @@ public class Utility { @ColorInt public static int getBackgroundForFileType(Context ctx, FileType type) { - int colorRes; - switch (type) { - case MUSIC: - colorRes = R.color.audio_left_to_load_color; - break; - case VIDEO: - colorRes = R.color.video_left_to_load_color; - break; - case SUBTITLE: - colorRes = R.color.subtitle_left_to_load_color; - break; - default: - colorRes = R.color.gray; - } + int colorRes = switch (type) { + case MUSIC -> R.color.audio_left_to_load_color; + case VIDEO -> R.color.video_left_to_load_color; + case SUBTITLE -> R.color.subtitle_left_to_load_color; + default -> R.color.gray; + }; return ContextCompat.getColor(ctx, colorRes); } @ColorInt public static int getForegroundForFileType(Context ctx, FileType type) { - int colorRes; - switch (type) { - case MUSIC: - colorRes = R.color.audio_already_load_color; - break; - case VIDEO: - colorRes = R.color.video_already_load_color; - break; - case SUBTITLE: - colorRes = R.color.subtitle_already_load_color; - break; - default: - colorRes = R.color.gray; - break; - } + int colorRes = switch (type) { + case MUSIC -> R.color.audio_already_load_color; + case VIDEO -> R.color.video_already_load_color; + case SUBTITLE -> R.color.subtitle_already_load_color; + default -> R.color.gray; + }; return ContextCompat.getColor(ctx, colorRes); } @DrawableRes public static int getIconForFileType(FileType type) { - switch (type) { - case MUSIC: - return R.drawable.ic_headset; - default: - case VIDEO: - return R.drawable.ic_movie; - case SUBTITLE: - return R.drawable.ic_subtitles; - } + return switch (type) { + case MUSIC -> R.drawable.ic_headset; + default -> R.drawable.ic_movie; + case SUBTITLE -> R.drawable.ic_subtitles; + }; } public static String checksum(final StoredFileHelper source, final int algorithmId)