|
| 1 | +package org.schabi.newpipe.settings.preferencesearch; |
| 2 | + |
| 3 | +import androidx.annotation.NonNull; |
| 4 | +import androidx.annotation.XmlRes; |
| 5 | + |
| 6 | +import java.util.List; |
| 7 | +import java.util.Objects; |
| 8 | + |
| 9 | +/** |
| 10 | + * Represents a preference-item inside the search. |
| 11 | + */ |
| 12 | +public class PreferenceSearchItem { |
| 13 | + /** |
| 14 | + * Key of the setting/preference. E.g. used inside {@link android.content.SharedPreferences}. |
| 15 | + */ |
| 16 | + @NonNull |
| 17 | + private final String key; |
| 18 | + /** |
| 19 | + * Title of the setting, e.g. 'Default resolution' or 'Show higher resolutions'. |
| 20 | + */ |
| 21 | + @NonNull |
| 22 | + private final String title; |
| 23 | + /** |
| 24 | + * Summary of the setting, e.g. '480p' or 'Only some devices can play 2.5k/4k'. |
| 25 | + */ |
| 26 | + @NonNull |
| 27 | + private final String summary; |
| 28 | + /** |
| 29 | + * Possible entries of the setting, e.g. 480p,720p,... |
| 30 | + */ |
| 31 | + @NonNull |
| 32 | + private final String entries; |
| 33 | + /** |
| 34 | + * Breadcrumbs - a hint where the setting is located e.g. 'Video and Audio > Player' |
| 35 | + */ |
| 36 | + @NonNull |
| 37 | + private final String breadcrumbs; |
| 38 | + /** |
| 39 | + * The xml-resource where this item was found/built from. |
| 40 | + */ |
| 41 | + @XmlRes |
| 42 | + private final int searchIndexItemResId; |
| 43 | + |
| 44 | + public PreferenceSearchItem( |
| 45 | + @NonNull final String key, |
| 46 | + @NonNull final String title, |
| 47 | + @NonNull final String summary, |
| 48 | + @NonNull final String entries, |
| 49 | + @NonNull final String breadcrumbs, |
| 50 | + @XmlRes final int searchIndexItemResId |
| 51 | + ) { |
| 52 | + this.key = Objects.requireNonNull(key); |
| 53 | + this.title = Objects.requireNonNull(title); |
| 54 | + this.summary = Objects.requireNonNull(summary); |
| 55 | + this.entries = Objects.requireNonNull(entries); |
| 56 | + this.breadcrumbs = Objects.requireNonNull(breadcrumbs); |
| 57 | + this.searchIndexItemResId = searchIndexItemResId; |
| 58 | + } |
| 59 | + |
| 60 | + @NonNull |
| 61 | + public String getKey() { |
| 62 | + return key; |
| 63 | + } |
| 64 | + |
| 65 | + @NonNull |
| 66 | + public String getTitle() { |
| 67 | + return title; |
| 68 | + } |
| 69 | + |
| 70 | + @NonNull |
| 71 | + public String getSummary() { |
| 72 | + return summary; |
| 73 | + } |
| 74 | + |
| 75 | + @NonNull |
| 76 | + public String getEntries() { |
| 77 | + return entries; |
| 78 | + } |
| 79 | + |
| 80 | + @NonNull |
| 81 | + public String getBreadcrumbs() { |
| 82 | + return breadcrumbs; |
| 83 | + } |
| 84 | + |
| 85 | + public int getSearchIndexItemResId() { |
| 86 | + return searchIndexItemResId; |
| 87 | + } |
| 88 | + |
| 89 | + boolean hasData() { |
| 90 | + return !key.isEmpty() && !title.isEmpty(); |
| 91 | + } |
| 92 | + |
| 93 | + public List<String> getAllRelevantSearchFields() { |
| 94 | + return List.of(getTitle(), getSummary(), getEntries(), getBreadcrumbs()); |
| 95 | + } |
| 96 | + |
| 97 | + @NonNull |
| 98 | + @Override |
| 99 | + public String toString() { |
| 100 | + return "PreferenceItem: " + title + " " + summary + " " + key; |
| 101 | + } |
| 102 | +} |
0 commit comments