Skip to content

Commit e2bce99

Browse files
committed
searchfilters: dynamically generate UIs and evaluate selected sort and content filters
SearchFilterLogic.java: ======================= This class handles all the user interaction with the content and sort filters of NewPipeExtractor. The class works standalone to just get the default selected filters eg. during init phase. See in SearchFragment#initializeFilterData() BaseSearchFilterUiGenerator.java: ================================= It extends SearchFilterLogic and is used as a base class to implement the UI interface for content and sort filter dialogs eg. SearchFilterDialogGenerator or SearchFilterOptionMenuAlikeDialogGenerator.
1 parent 1d8850d commit e2bce99

2 files changed

Lines changed: 914 additions & 0 deletions

File tree

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// Created by evermind-zz 2022, licensed GNU GPL version 3 or later
2+
3+
package org.schabi.newpipe.fragments.list.search.filter;
4+
5+
import android.content.Context;
6+
import android.util.TypedValue;
7+
8+
import org.schabi.newpipe.R;
9+
10+
import androidx.annotation.NonNull;
11+
12+
import static org.schabi.newpipe.fragments.list.search.filter.SearchFilterLogic.ICreateUiForFiltersWorker;
13+
import static org.schabi.newpipe.fragments.list.search.filter.SearchFilterLogic.IUiItemWrapper;
14+
15+
/**
16+
* The base class to implement the search filter UI for content
17+
* and sort filter dialogs eg. {@link SearchFilterDialogGenerator}
18+
* or {@link SearchFilterOptionMenuAlikeDialogGenerator}.
19+
*/
20+
public abstract class BaseSearchFilterUiGenerator {
21+
protected final ICreateUiForFiltersWorker contentFilterWorker;
22+
protected final ICreateUiForFiltersWorker sortFilterWorker;
23+
protected final Context context;
24+
protected final SearchFilterLogic logic;
25+
26+
protected BaseSearchFilterUiGenerator(
27+
@NonNull final SearchFilterLogic logic,
28+
@NonNull final Context context) {
29+
this.context = context;
30+
this.logic = logic;
31+
this.contentFilterWorker = createContentFilterWorker();
32+
this.sortFilterWorker = createSortFilterWorker();
33+
}
34+
35+
/**
36+
* {@link ICreateUiForFiltersWorker}.
37+
*
38+
* @return the class that implements the UI for the content filters.
39+
*/
40+
protected abstract ICreateUiForFiltersWorker createContentFilterWorker();
41+
42+
/**
43+
* {@link ICreateUiForFiltersWorker}.
44+
*
45+
* @return the class that implements the UI for the sort filters.
46+
*/
47+
protected abstract ICreateUiForFiltersWorker createSortFilterWorker();
48+
49+
protected int getSeparatorLineColorFromTheme() {
50+
final TypedValue value = new TypedValue();
51+
context.getTheme().resolveAttribute(R.attr.colorAccent, value, true);
52+
return value.data;
53+
}
54+
55+
/**
56+
* Create the complete UI for the search filter dialog and make sure the initial
57+
* visibility of the UI elements is done.
58+
*/
59+
public void createSearchUI() {
60+
logic.initContentFiltersUi(contentFilterWorker);
61+
logic.initSortFiltersUi(sortFilterWorker);
62+
doMeasurementsIfNeeded();
63+
// make sure that only sort filters relevant to the selected content filter are shown
64+
logic.showSortFilterContainerUI();
65+
}
66+
67+
protected void doMeasurementsIfNeeded() {
68+
// nothing to measure here, if you want to measure something override this method
69+
}
70+
71+
/**
72+
* Helper interface used as 'function pointer'.
73+
*/
74+
protected interface UiWrapperMapDelegate {
75+
void put(int identifier, IUiItemWrapper menuItemUiWrapper);
76+
}
77+
78+
/**
79+
* Helper interface used as 'function pointer'.
80+
*/
81+
protected interface UiSelectorDelegate {
82+
void selectFilter(int identifier);
83+
}
84+
}

0 commit comments

Comments
 (0)