Code rework

This commit is contained in:
litetex 2021-12-27 18:57:17 +01:00
parent 0f45c69388
commit d59314801c
2 changed files with 24 additions and 13 deletions

View File

@ -5,6 +5,7 @@ import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.XmlRes;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
@ -111,7 +112,7 @@ public class PreferenceParser {
private PreferenceSearchItem parseSearchResult( private PreferenceSearchItem parseSearchResult(
final XmlPullParser xpp, final XmlPullParser xpp,
final String breadcrumbs, final String breadcrumbs,
final int searchIndexItemResId @XmlRes final int searchIndexItemResId
) { ) {
final String key = readString(getAttribute(xpp, "key")); final String key = readString(getAttribute(xpp, "key"));
final String[] entries = readStringArray(getAttribute(xpp, "entries")); final String[] entries = readStringArray(getAttribute(xpp, "entries"));
@ -130,7 +131,6 @@ public class PreferenceParser {
entries, entries,
entryValues), entryValues),
TextUtils.join(",", entries), TextUtils.join(",", entries),
readString(getAttribute(xpp, NS_SEARCH, "keywords")),
breadcrumbs, breadcrumbs,
searchIndexItemResId searchIndexItemResId
); );

View File

@ -1,6 +1,7 @@
package org.schabi.newpipe.settings.preferencesearch; package org.schabi.newpipe.settings.preferencesearch;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.XmlRes;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@ -10,18 +11,35 @@ import java.util.Objects;
* Represents a preference-item inside the search. * Represents a preference-item inside the search.
*/ */
public class PreferenceSearchItem { public class PreferenceSearchItem {
/**
* Key of the setting/preference. E.g. used inside {@link android.content.SharedPreferences}.
*/
@NonNull @NonNull
private final String key; private final String key;
/**
* Title of the setting, e.g. 'Default resolution' or 'Show higher resolutions'.
*/
@NonNull @NonNull
private final String title; private final String title;
/**
* Summary of the setting, e.g. '480p' or 'Only some devices can play 2k/4k'.
*/
@NonNull @NonNull
private final String summary; private final String summary;
/**
* Possible entries of the setting, e.g. 480p,720p,...
*/
@NonNull @NonNull
private final String entries; private final String entries;
@NonNull /**
private final String keywords; * Breadcrumbs - a hint where the setting is located e.g. 'Video and Audio > Player'
*/
@NonNull @NonNull
private final String breadcrumbs; private final String breadcrumbs;
/**
* The xml-resource where this item was found/built from.
*/
@XmlRes
private final int searchIndexItemResId; private final int searchIndexItemResId;
public PreferenceSearchItem( public PreferenceSearchItem(
@ -29,15 +47,13 @@ public class PreferenceSearchItem {
@NonNull final String title, @NonNull final String title,
@NonNull final String summary, @NonNull final String summary,
@NonNull final String entries, @NonNull final String entries,
@NonNull final String keywords,
@NonNull final String breadcrumbs, @NonNull final String breadcrumbs,
final int searchIndexItemResId @XmlRes final int searchIndexItemResId
) { ) {
this.key = Objects.requireNonNull(key); this.key = Objects.requireNonNull(key);
this.title = Objects.requireNonNull(title); this.title = Objects.requireNonNull(title);
this.summary = Objects.requireNonNull(summary); this.summary = Objects.requireNonNull(summary);
this.entries = Objects.requireNonNull(entries); this.entries = Objects.requireNonNull(entries);
this.keywords = Objects.requireNonNull(keywords);
this.breadcrumbs = Objects.requireNonNull(breadcrumbs); this.breadcrumbs = Objects.requireNonNull(breadcrumbs);
this.searchIndexItemResId = searchIndexItemResId; this.searchIndexItemResId = searchIndexItemResId;
} }
@ -62,10 +78,6 @@ public class PreferenceSearchItem {
return breadcrumbs; return breadcrumbs;
} }
public String getKeywords() {
return keywords;
}
public int getSearchIndexItemResId() { public int getSearchIndexItemResId() {
return searchIndexItemResId; return searchIndexItemResId;
} }
@ -79,8 +91,7 @@ public class PreferenceSearchItem {
getTitle(), getTitle(),
getSummary(), getSummary(),
getEntries(), getEntries(),
getBreadcrumbs(), getBreadcrumbs());
getKeywords());
} }