Skip to content

Commit 90e4346

Browse files
committed
searchfilters: fixup 4th dialog to draw a separator line between FilterGroup without a label
1 parent 161eb16 commit 90e4346

3 files changed

Lines changed: 38 additions & 3 deletions

File tree

app/src/main/java/org/schabi/newpipe/fragments/list/search/filter/BaseSearchFilterUiDialogGenerator.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,17 @@ protected ICreateUiForFiltersWorker createSortFilterWorker() {
4242
return new BaseCreateSearchFilterUI.CreateSortFilterUI(this, context, logic);
4343
}
4444

45+
/**
46+
* Create a View that acts as a separator between two other {@link View}-Elements.
47+
*
48+
* @param layoutParams this layout will be modified to have the height of 1 -> to have a
49+
* the actual separator line.
50+
* @return the created {@link SeparatorLineView}
51+
*/
4552
@NonNull
46-
protected View createSeparatorLine(@NonNull final ViewGroup.LayoutParams layoutParams) {
47-
final View separatorLine = new View(context);
53+
protected SeparatorLineView createSeparatorLine(
54+
@NonNull final ViewGroup.LayoutParams layoutParams) {
55+
final SeparatorLineView separatorLine = new SeparatorLineView(context);
4856
separatorLine.setBackgroundColor(getSeparatorLineColorFromTheme());
4957
layoutParams.height = 1; // always set the separator to the height of 1
5058
separatorLine.setLayoutParams(layoutParams);
@@ -60,4 +68,17 @@ protected TextView createTitleText(@NonNull final String name,
6068
title.setLayoutParams(layoutParams);
6169
return title;
6270
}
71+
72+
/**
73+
* A special view to separate two other {@link View}s.
74+
* <p>
75+
* class only needed to distinct this special view from other View based views.
76+
* (eg. instanceof)
77+
*/
78+
protected static final class SeparatorLineView extends View {
79+
80+
private SeparatorLineView(@NonNull final Context context) {
81+
super(context);
82+
}
83+
}
6384
}

app/src/main/java/org/schabi/newpipe/fragments/list/search/filter/SearchFilterChipDialogGenerator.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package org.schabi.newpipe.fragments.list.search.filter;
44

55
import android.content.Context;
6+
import android.view.View;
67
import android.view.ViewGroup;
78
import android.widget.GridLayout;
89
import android.widget.TextView;
@@ -37,6 +38,10 @@ protected void createFilterGroup(@NonNull final FilterGroup filterGroup,
3738
final TextView filterLabel = createFilterLabel(filterGroup, layoutParams);
3839
globalLayout.addView(filterLabel);
3940
viewsWrapper.add(filterLabel);
41+
} else if (doWeNeedASeparatorView()) {
42+
final SeparatorLineView separatorLineView = createSeparatorLine();
43+
globalLayout.addView(separatorLineView);
44+
viewsWrapper.add(separatorLineView);
4045
}
4146

4247
final ChipGroup chipGroup = new ChipGroup(context);
@@ -55,6 +60,15 @@ protected void createFilterGroup(@NonNull final FilterGroup filterGroup,
5560
viewsWrapper.add(chipGroup);
5661
}
5762

63+
private boolean doWeNeedASeparatorView() {
64+
// if 0 than there is nothing to separate
65+
if (globalLayout.getChildCount() == 0) {
66+
return false;
67+
}
68+
final View lastView = globalLayout.getChildAt(globalLayout.getChildCount() - 1);
69+
return !(lastView instanceof SeparatorLineView);
70+
}
71+
5872
private ViewGroup.MarginLayoutParams setDefaultMarginInDp(
5973
@NonNull final ViewGroup.MarginLayoutParams layoutParams,
6074
final int left, final int top, final int right, final int bottom) {

app/src/main/java/org/schabi/newpipe/fragments/list/search/filter/SearchFilterDialogGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ private TextView createDividerLabel(
239239
}
240240

241241
@NonNull
242-
private View createSeparatorLine() {
242+
protected SeparatorLineView createSeparatorLine() {
243243
return createSeparatorLine(clipFreeRightColumnLayoutParams(true));
244244
}
245245

0 commit comments

Comments
 (0)