From 94511671cfb89a2a9067f638897c47e003d05fa7 Mon Sep 17 00:00:00 2001 From: evermind Date: Mon, 31 Oct 2022 23:12:16 +0100 Subject: [PATCH] searchfilters: rework getTranslatedFilterString() method to use NewPipeExtractor's LibraryStringIds class --- .../schabi/newpipe/util/ServiceHelper.java | 227 ++++++++++++++---- app/src/main/res/values-de/strings.xml | 62 ++++- app/src/main/res/values/strings.xml | 62 +++++ 3 files changed, 304 insertions(+), 47 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/util/ServiceHelper.java b/app/src/main/java/org/schabi/newpipe/util/ServiceHelper.java index c712157b35b..2ad02fda0a5 100644 --- a/app/src/main/java/org/schabi/newpipe/util/ServiceHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/ServiceHelper.java @@ -1,16 +1,8 @@ package org.schabi.newpipe.util; -import static org.schabi.newpipe.extractor.ServiceList.SoundCloud; - import android.content.Context; import android.content.SharedPreferences; -import androidx.annotation.DrawableRes; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.annotation.StringRes; -import androidx.preference.PreferenceManager; - import com.grack.nanojson.JsonObject; import com.grack.nanojson.JsonParser; import com.grack.nanojson.JsonParserException; @@ -20,15 +12,182 @@ import org.schabi.newpipe.extractor.ServiceList; import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.exceptions.ExtractionException; +import org.schabi.newpipe.extractor.search.filter.LibraryStringIds; import org.schabi.newpipe.extractor.services.peertube.PeertubeInstance; +import java.util.EnumMap; +import java.util.Map; +import java.util.Objects; import java.util.Optional; import java.util.concurrent.TimeUnit; +import androidx.annotation.DrawableRes; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.annotation.StringRes; +import androidx.preference.PreferenceManager; + +import static org.schabi.newpipe.extractor.ServiceList.SoundCloud; + public final class ServiceHelper { private static final StreamingService DEFAULT_FALLBACK_SERVICE = ServiceList.YouTube; + /** + * Map all available {@link LibraryStringIds} ids to resource ids available in strings.xml. + */ + private static final Map LIBRARY_STRING_ID_TO_RES_ID_MAP = + new EnumMap<>(LibraryStringIds.class); + + static { + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_10_30_MIN, + R.string.search_filters_10_30_min); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_2_10_MIN, + R.string.search_filters_2_10_min); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_360, + R.string.search_filters_360); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_3D, + R.string.search_filters_3d); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_4_20_MIN, + R.string.search_filters_4_20_min); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_4K, + R.string.search_filters_4k); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_ADDED, + R.string.search_filters_added); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_ALBUMS, + R.string.albums); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_ANY_TIME, + R.string.search_filters_any_time); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_ALL, + R.string.all); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_ARTISTS_AND_LABELS, + R.string.search_filters_artists_and_labels); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_ASCENDING, + R.string.search_filters_ascending); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_CCOMMONS, + R.string.search_filters_ccommons); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_CHANNELS, + R.string.channels); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_CONFERENCES, + R.string.conferences); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_CREATION_DATE, + R.string.search_filters_creation_date); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_DATE, + R.string.search_filters_date); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_DURATION, + R.string.search_filters_duration); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_EVENTS, + R.string.events); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_FEATURES, + R.string.search_filters_features); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_GREATER_30_MIN, + R.string.search_filters_greater_30_min); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_HD, + R.string.search_filters_hd); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_HDR, + R.string.search_filters_hdr); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_KIND, + R.string.search_filters_kind); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_LAST_30_DAYS, + R.string.search_filters_last_30_days); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_LAST_7_DAYS, + R.string.search_filters_last_7_days); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_LAST_HOUR, + R.string.search_filters_last_hour); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_LAST_YEAR, + R.string.search_filters_last_year); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_LENGTH, + R.string.search_filters_length); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_LESS_2_MIN, + R.string.search_filters_less_2_min); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_LICENSE, + R.string.search_filters_license); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_LIKES, + R.string.detail_likes_img_view_description); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_LIVE, + R.string.duration_live); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_LOCATION, + R.string.search_filters_location); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_LONG_GREATER_10_MIN, + R.string.search_filters_long_greater_10_min); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_MEDIUM_4_10_MIN, + R.string.search_filters_medium_4_10_min); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_THIS_MONTH, + R.string.search_filters_this_month); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_ARTISTS, + R.string.artists); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_SONGS, + R.string.songs); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_NAME, + R.string.name); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_NO, + R.string.search_filters_no); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_OVER_20_MIN, + R.string.search_filters_over_20_min); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_PAST_DAY, + R.string.search_filters_past_day); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_PAST_HOUR, + R.string.search_filters_past_hour); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_PAST_MONTH, + R.string.search_filters_past_month); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_PAST_WEEK, + R.string.search_filters_past_week); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_PAST_YEAR, + R.string.search_filters_past_year); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_PLAYLISTS, + R.string.playlists); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_PUBLISH_DATE, + R.string.search_filters_publish_date); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_PUBLISHED, + R.string.search_filters_published); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_PURCHASED, + R.string.search_filters_published); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_RATING, + R.string.search_filters_rating); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_RELEVANCE, + R.string.search_filters_relevance); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_SENSITIVE, + R.string.search_filters_sensitive); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_SEPIASEARCH, + R.string.search_filters_sepiasearch); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_SHORT_LESS_4_MIN, + R.string.search_filters_short_less_4_min); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_SORT_BY, + R.string.search_filters_sort_by); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_SORT_ORDER, + R.string.search_filters_sort_order); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_SUBTITLES, + R.string.search_filters_subtitles); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_TO_MODIFY_COMMERCIALLY, + R.string.search_filters_to_modify_commercially); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_TODAY, + R.string.search_filters_today); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_TRACKS, + R.string.tracks); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_UNDER_4_MIN, + R.string.search_filters_under_4_min); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_UPLOAD_DATE, + R.string.search_filters_upload_date); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_USERS, + R.string.users); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_VIDEOS, + R.string.videos_string); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_VIEWS, + R.string.search_filters_views); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_VOD_VIDEOS, + R.string.search_filters_vod_videos); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_VR180, + R.string.search_filters_vr180); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_THIS_WEEK, + R.string.search_filters_this_week); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_THIS_YEAR, + R.string.search_filters_this_year); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_YES, + R.string.search_filters_yes); + LIBRARY_STRING_ID_TO_RES_ID_MAP.put(LibraryStringIds.SEARCH_FILTERS_YOUTUBE_MUSIC, + R.string.search_filters_youtube_music); + } - private ServiceHelper() { } + private ServiceHelper() { + } @DrawableRes public static int getIcon(final int serviceId) { @@ -48,38 +207,6 @@ public static int getIcon(final int serviceId) { } } - 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; - } - } - /** * Get a resource string with instructions for importing subscriptions for each service. * @@ -107,12 +234,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 getSelectedServiceId(final Context context) { @@ -210,4 +335,14 @@ public static void initServices(final Context context) { initService(context, s.getServiceId()); } } + + public static String getTranslatedFilterString(@NonNull final LibraryStringIds stringId, + @NonNull final Context context) { + if (LIBRARY_STRING_ID_TO_RES_ID_MAP.containsKey(stringId)) { + return context.getString( + Objects.requireNonNull(LIBRARY_STRING_ID_TO_RES_ID_MAP.get(stringId))); + } else { + return stringId.toString(); + } + } } diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 5260287c1bc..b85fde66307 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -806,4 +806,64 @@ Wiedergabeliste teilen Teile die Wiedergabeliste mit Details wie dem Namen der Wiedergabeliste und den Videotiteln oder als einfache Liste von Video-URLs - %1$s: %2$s - \ No newline at end of file + Sortierfilter + Inhaltsfilter + 10–30 min + 2–10 min + 360° + 3D + 4–20 min + 4K + Hinzugefügt + Künstler & Labels + Jederzeit + Aufsteigend + Creative Commons + Erstellungsdatum + Datum + Dauer + Eigenschaften + > 30 min + HD + HDR + Art + Letzte 30 Tage + Letzte 7 Tage + Letzte Stunde + Letztes Jahr + Länge + < 2 min + Lizenz + Standort + Lang (> 10 min) + Mittel (4–10 min) + Nein + Über 20 min + Vorheriger Tag + Vorige Stunde + Vergangener Monat + Vergangene Woche + Vergangenes Jahr + Erscheinungsdatum + Veröffentlicht + Gekauft + Bewertung + Relevanz + Sensibler Inhalt + SepiaSuche + Kurz (< 4 min) + Sortiert nach + Sortierung + Untertitel + Gewerblich nutzbar + Heute + Unter 4 min + Hochladedatum + Aufrufe + VOD-Videos + VR180 + Dieser Monat + Diese Woche + Dieses Jahr + Ja + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 281df95a4b2..e1fd0ea5671 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -845,4 +845,66 @@ Show more Show less + + + 10–30 min + 2–10 min + 360° + 3D + 4–20 min + 4K + Added + artists & labels + Any time + Ascending + Creative Commons + Creation date + Date + Duration + Features + > 30 min + HD + HDR + Kind + Last 30 days + Last 7 days + Last hour + last year + Length + < 2 min + License + Location + Long (> 10 min) + Medium (4–10 min) + No + Over 20 min + Past day + Past hour + Past month + Past week + Past year + Publish date + Published + Purchased + Rating + Relevance + Sensitive + SepiaSearch + Short (< 4 min) + Sort by + Sort order + Subtitles + To modify commercially + Today + Under 4 min + Upload Date + Views + VOD videos + VR180 + This month + This week + This year + Yes + YouTube Music +