Skip to content

Commit bb97de7

Browse files
committed
searchfilters: convert to using LibraryStringIds to identify strings
1 parent 4c08dcf commit bb97de7

File tree

10 files changed

+289
-212
lines changed

10 files changed

+289
-212
lines changed

extractor/src/main/java/org/schabi/newpipe/extractor/search/filter/FilterGroup.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ public final class FilterGroup {
1919
private final int identifier;
2020

2121
/**
22-
* The name of the filter group that the user will see
22+
* The name id of the filter group.
23+
* <p>
24+
* The id has to be translated to an actual string that the user will see in the UI.
2325
*/
24-
private final String groupName;
26+
private final LibraryStringIds groupNameId;
2527

2628
/**
2729
* Specify whether only one item can be selected in this group at a time.
@@ -47,13 +49,13 @@ public final class FilterGroup {
4749
private final FilterContainer allSortFilters;
4850

4951
private FilterGroup(final int identifier,
50-
final String groupName,
52+
final LibraryStringIds groupNameId,
5153
final boolean onlyOneCheckable,
5254
final int defaultSelectedFilterId,
5355
final FilterItem[] filterItems,
5456
final FilterContainer allSortFilters) {
5557
this.identifier = identifier;
56-
this.groupName = groupName;
58+
this.groupNameId = groupNameId;
5759
this.onlyOneCheckable = onlyOneCheckable;
5860
this.defaultSelectedFilterId = defaultSelectedFilterId;
5961
this.filterItems = filterItems;
@@ -79,10 +81,10 @@ public int getIdentifier() {
7981
}
8082

8183
/**
82-
* {@link #groupName}
84+
* {@link #groupNameId}
8385
*/
84-
public String getName() {
85-
return groupName;
86+
public LibraryStringIds getNameId() {
87+
return groupNameId;
8688
}
8789

8890
/**
@@ -132,14 +134,14 @@ void uniqueIdChecker(final Map<Integer, FilterItem> filterItems,
132134
&& !(item instanceof FilterItem.DividerItem)) {
133135
throw new InvalidFilterIdException("Filter ID "
134136
+ item.getIdentifier() + " aka FilterContainer.ITEM_IDENTIFIER_UNKNOWN"
135-
+ " for \"" + item.getName() + "\" not allowed");
137+
+ " for \"" + item.getNameId() + "\" not allowed");
136138
}
137139

138140
if (filterItems.containsKey(item.getIdentifier())) {
139141
final FilterItem storedItem = filterItems.get(item.getIdentifier());
140142
throw new InvalidFilterIdException("Filter ID "
141-
+ item.getIdentifier() + " for \"" + item.getName()
142-
+ "\" already taken from \"" + storedItem.getName() + "\"");
143+
+ item.getIdentifier() + " for \"" + item.getNameId()
144+
+ "\" already taken from \"" + storedItem.getNameId() + "\"");
143145
}
144146
}
145147

@@ -158,12 +160,12 @@ public int addFilterItem(final FilterItem filter) {
158160
}
159161

160162
public FilterGroup createFilterGroup(final int identifier,
161-
final String groupName,
163+
final LibraryStringIds groupNameId,
162164
final boolean onlyOneCheckable,
163165
final int defaultSelectedFilterId,
164166
final FilterItem[] filterItems,
165167
final FilterContainer allSortFilters) {
166-
return new FilterGroup(identifier, groupName, onlyOneCheckable,
168+
return new FilterGroup(identifier, groupNameId, onlyOneCheckable,
167169
defaultSelectedFilterId, filterItems, allSortFilters);
168170
}
169171

extractor/src/main/java/org/schabi/newpipe/extractor/search/filter/FilterItem.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313
public class FilterItem {
1414

1515
/**
16-
* The name of the filter option, that will be visible to the user.
16+
* The name id of the filter group.
17+
*
18+
* The id has to be translated to an actual string that the user will see in the UI.
1719
*/
18-
private final String name;
20+
private final LibraryStringIds nameId;
1921

2022
/**
2123
* A sequential unique number identifier.
@@ -28,9 +30,9 @@ public class FilterItem {
2830
*/
2931
private final int identifier;
3032

31-
public FilterItem(final int identifier, final String name) {
33+
public FilterItem(final int identifier, final LibraryStringIds nameId) {
3234
this.identifier = identifier;
33-
this.name = name;
35+
this.nameId = nameId;
3436
}
3537

3638
/**
@@ -41,19 +43,19 @@ public int getIdentifier() {
4143
}
4244

4345
/**
44-
* @return {@link #name}
46+
* @return {@link #nameId}
4547
*/
46-
public String getName() {
47-
return this.name;
48+
public LibraryStringIds getNameId() {
49+
return this.nameId;
4850
}
4951

5052
/**
5153
* This class is used to have a sub title divider between regular {@link FilterItem}s.
5254
*/
5355
public static class DividerItem extends FilterItem {
5456

55-
public DividerItem(final String name) {
56-
super(FilterContainer.ITEM_IDENTIFIER_UNKNOWN, name);
57+
public DividerItem(final LibraryStringIds nameId) {
58+
super(FilterContainer.ITEM_IDENTIFIER_UNKNOWN, nameId);
5759
}
5860
}
5961
}

extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/search/filter/BandcampFilters.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import org.schabi.newpipe.extractor.search.filter.BaseSearchFilters;
66
import org.schabi.newpipe.extractor.search.filter.FilterItem;
7+
import org.schabi.newpipe.extractor.search.filter.LibraryStringIds;
78

89
public final class BandcampFilters extends BaseSearchFilters {
910

@@ -14,12 +15,6 @@ public final class BandcampFilters extends BaseSearchFilters {
1415
public static final int ID_CF_MAIN_TRACKS = 4;
1516
// public static final int ID_CF_MAIN_FANS = 5;
1617

17-
private static final String ALL = "all";
18-
private static final String ARTISTS = "artists & labels";
19-
private static final String ALBUMS = "albums";
20-
private static final String TRACKS = "tracks";
21-
// private static final String FANS = "fans";
22-
2318
@Override
2419
public String evaluateSelectedContentFilters() {
2520
if (selectedSortFilter != null) {
@@ -42,13 +37,17 @@ public String evaluateSelectedContentFilters() {
4237
protected void init() {
4338
/* content filters */
4439
groupsFactory.addFilterItem(new BandcampContentFilterItem(
45-
ID_CF_MAIN_ALL, ALL, ""));
40+
ID_CF_MAIN_ALL,
41+
LibraryStringIds.SEARCH_FILTERS_ALL, ""));
4642
groupsFactory.addFilterItem(new BandcampContentFilterItem(
47-
ID_CF_MAIN_ARTISTS, ARTISTS, "item_type=b"));
43+
ID_CF_MAIN_ARTISTS,
44+
LibraryStringIds.SEARCH_FILTERS_ARTISTS_AND_LABELS, "item_type=b"));
4845
groupsFactory.addFilterItem(new BandcampContentFilterItem(
49-
ID_CF_MAIN_ALBUMS, ALBUMS, "item_type=a"));
46+
ID_CF_MAIN_ALBUMS,
47+
LibraryStringIds.SEARCH_FILTERS_ALBUMS, "item_type=a"));
5048
groupsFactory.addFilterItem(new BandcampContentFilterItem(
51-
ID_CF_MAIN_TRACKS, TRACKS, "item_type=t"));
49+
ID_CF_MAIN_TRACKS,
50+
LibraryStringIds.SEARCH_FILTERS_TRACKS, "item_type=t"));
5251
// FIXME no FANS extractor in BandcampSearchExtractor -> no content filter here
5352
// groupsFactory.addFilterItem(new BandcampContentFilterItem(
5453
// ID_CF_MAIN_FANS, FANS, "item_type=f"));
@@ -66,9 +65,9 @@ protected void init() {
6665
public static class BandcampContentFilterItem extends FilterItem {
6766
private final String query;
6867

69-
public BandcampContentFilterItem(final int identifier, final String name,
68+
public BandcampContentFilterItem(final int identifier, final LibraryStringIds nameId,
7069
final String query) {
71-
super(identifier, name);
70+
super(identifier, nameId);
7271
this.query = query;
7372
}
7473
}

extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/search/filter/MediaCCCFilters.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import org.schabi.newpipe.extractor.search.filter.BaseSearchFilters;
66
import org.schabi.newpipe.extractor.search.filter.FilterItem;
7+
import org.schabi.newpipe.extractor.search.filter.LibraryStringIds;
78

89
public final class MediaCCCFilters extends BaseSearchFilters {
910

@@ -12,19 +13,18 @@ public final class MediaCCCFilters extends BaseSearchFilters {
1213
public static final int ID_CF_MAIN_CONFERENCES = 2;
1314
public static final int ID_CF_MAIN_EVENTS = 3;
1415

15-
public static final String ALL = "all";
16-
public static final String CONFERENCES = "conferences";
17-
public static final String EVENTS = "events";
18-
1916
@Override
2017
protected void init() {
2118
/* content filters */
2219
groupsFactory.addFilterItem(new FilterItem(
23-
ID_CF_MAIN_ALL, ALL));
20+
ID_CF_MAIN_ALL,
21+
LibraryStringIds.SEARCH_FILTERS_ALL));
2422
groupsFactory.addFilterItem(new FilterItem(
25-
ID_CF_MAIN_CONFERENCES, CONFERENCES));
23+
ID_CF_MAIN_CONFERENCES,
24+
LibraryStringIds.SEARCH_FILTERS_CONFERENCES));
2625
groupsFactory.addFilterItem(new FilterItem(
27-
ID_CF_MAIN_EVENTS, EVENTS));
26+
ID_CF_MAIN_EVENTS,
27+
LibraryStringIds.SEARCH_FILTERS_EVENTS));
2828

2929
addContentFilterGroup(groupsFactory.createFilterGroup(ID_CF_MAIN_GRP, null, true,
3030
ID_CF_MAIN_ALL, new FilterItem[]{

0 commit comments

Comments
 (0)