Skip to content

Commit

Permalink
searchfilters: convert to using LibraryStringIds to identify strings
Browse files Browse the repository at this point in the history
  • Loading branch information
evermind-zz committed Nov 4, 2022
1 parent 4c08dcf commit bb97de7
Show file tree
Hide file tree
Showing 10 changed files with 289 additions and 212 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ public final class FilterGroup {
private final int identifier;

/**
* The name of the filter group that the user will see
* The name id of the filter group.
* <p>
* The id has to be translated to an actual string that the user will see in the UI.
*/
private final String groupName;
private final LibraryStringIds groupNameId;

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

private FilterGroup(final int identifier,
final String groupName,
final LibraryStringIds groupNameId,
final boolean onlyOneCheckable,
final int defaultSelectedFilterId,
final FilterItem[] filterItems,
final FilterContainer allSortFilters) {
this.identifier = identifier;
this.groupName = groupName;
this.groupNameId = groupNameId;
this.onlyOneCheckable = onlyOneCheckable;
this.defaultSelectedFilterId = defaultSelectedFilterId;
this.filterItems = filterItems;
Expand All @@ -79,10 +81,10 @@ public int getIdentifier() {
}

/**
* {@link #groupName}
* {@link #groupNameId}
*/
public String getName() {
return groupName;
public LibraryStringIds getNameId() {
return groupNameId;
}

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

if (filterItems.containsKey(item.getIdentifier())) {
final FilterItem storedItem = filterItems.get(item.getIdentifier());
throw new InvalidFilterIdException("Filter ID "
+ item.getIdentifier() + " for \"" + item.getName()
+ "\" already taken from \"" + storedItem.getName() + "\"");
+ item.getIdentifier() + " for \"" + item.getNameId()
+ "\" already taken from \"" + storedItem.getNameId() + "\"");
}
}

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

public FilterGroup createFilterGroup(final int identifier,
final String groupName,
final LibraryStringIds groupNameId,
final boolean onlyOneCheckable,
final int defaultSelectedFilterId,
final FilterItem[] filterItems,
final FilterContainer allSortFilters) {
return new FilterGroup(identifier, groupName, onlyOneCheckable,
return new FilterGroup(identifier, groupNameId, onlyOneCheckable,
defaultSelectedFilterId, filterItems, allSortFilters);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
public class FilterItem {

/**
* The name of the filter option, that will be visible to the user.
* The name id of the filter group.
*
* The id has to be translated to an actual string that the user will see in the UI.
*/
private final String name;
private final LibraryStringIds nameId;

/**
* A sequential unique number identifier.
Expand All @@ -28,9 +30,9 @@ public class FilterItem {
*/
private final int identifier;

public FilterItem(final int identifier, final String name) {
public FilterItem(final int identifier, final LibraryStringIds nameId) {
this.identifier = identifier;
this.name = name;
this.nameId = nameId;
}

/**
Expand All @@ -41,19 +43,19 @@ public int getIdentifier() {
}

/**
* @return {@link #name}
* @return {@link #nameId}
*/
public String getName() {
return this.name;
public LibraryStringIds getNameId() {
return this.nameId;
}

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

public DividerItem(final String name) {
super(FilterContainer.ITEM_IDENTIFIER_UNKNOWN, name);
public DividerItem(final LibraryStringIds nameId) {
super(FilterContainer.ITEM_IDENTIFIER_UNKNOWN, nameId);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import org.schabi.newpipe.extractor.search.filter.BaseSearchFilters;
import org.schabi.newpipe.extractor.search.filter.FilterItem;
import org.schabi.newpipe.extractor.search.filter.LibraryStringIds;

public final class BandcampFilters extends BaseSearchFilters {

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

private static final String ALL = "all";
private static final String ARTISTS = "artists & labels";
private static final String ALBUMS = "albums";
private static final String TRACKS = "tracks";
// private static final String FANS = "fans";

@Override
public String evaluateSelectedContentFilters() {
if (selectedSortFilter != null) {
Expand All @@ -42,13 +37,17 @@ public String evaluateSelectedContentFilters() {
protected void init() {
/* content filters */
groupsFactory.addFilterItem(new BandcampContentFilterItem(
ID_CF_MAIN_ALL, ALL, ""));
ID_CF_MAIN_ALL,
LibraryStringIds.SEARCH_FILTERS_ALL, ""));
groupsFactory.addFilterItem(new BandcampContentFilterItem(
ID_CF_MAIN_ARTISTS, ARTISTS, "item_type=b"));
ID_CF_MAIN_ARTISTS,
LibraryStringIds.SEARCH_FILTERS_ARTISTS_AND_LABELS, "item_type=b"));
groupsFactory.addFilterItem(new BandcampContentFilterItem(
ID_CF_MAIN_ALBUMS, ALBUMS, "item_type=a"));
ID_CF_MAIN_ALBUMS,
LibraryStringIds.SEARCH_FILTERS_ALBUMS, "item_type=a"));
groupsFactory.addFilterItem(new BandcampContentFilterItem(
ID_CF_MAIN_TRACKS, TRACKS, "item_type=t"));
ID_CF_MAIN_TRACKS,
LibraryStringIds.SEARCH_FILTERS_TRACKS, "item_type=t"));
// FIXME no FANS extractor in BandcampSearchExtractor -> no content filter here
// groupsFactory.addFilterItem(new BandcampContentFilterItem(
// ID_CF_MAIN_FANS, FANS, "item_type=f"));
Expand All @@ -66,9 +65,9 @@ protected void init() {
public static class BandcampContentFilterItem extends FilterItem {
private final String query;

public BandcampContentFilterItem(final int identifier, final String name,
public BandcampContentFilterItem(final int identifier, final LibraryStringIds nameId,
final String query) {
super(identifier, name);
super(identifier, nameId);
this.query = query;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import org.schabi.newpipe.extractor.search.filter.BaseSearchFilters;
import org.schabi.newpipe.extractor.search.filter.FilterItem;
import org.schabi.newpipe.extractor.search.filter.LibraryStringIds;

public final class MediaCCCFilters extends BaseSearchFilters {

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

public static final String ALL = "all";
public static final String CONFERENCES = "conferences";
public static final String EVENTS = "events";

@Override
protected void init() {
/* content filters */
groupsFactory.addFilterItem(new FilterItem(
ID_CF_MAIN_ALL, ALL));
ID_CF_MAIN_ALL,
LibraryStringIds.SEARCH_FILTERS_ALL));
groupsFactory.addFilterItem(new FilterItem(
ID_CF_MAIN_CONFERENCES, CONFERENCES));
ID_CF_MAIN_CONFERENCES,
LibraryStringIds.SEARCH_FILTERS_CONFERENCES));
groupsFactory.addFilterItem(new FilterItem(
ID_CF_MAIN_EVENTS, EVENTS));
ID_CF_MAIN_EVENTS,
LibraryStringIds.SEARCH_FILTERS_EVENTS));

addContentFilterGroup(groupsFactory.createFilterGroup(ID_CF_MAIN_GRP, null, true,
ID_CF_MAIN_ALL, new FilterItem[]{
Expand Down
Loading

0 comments on commit bb97de7

Please sign in to comment.