|
| 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.view.ViewGroup; |
| 7 | +import android.widget.GridLayout; |
| 8 | +import android.widget.TextView; |
| 9 | + |
| 10 | +import com.google.android.material.chip.ChipGroup; |
| 11 | + |
| 12 | +import org.schabi.newpipe.extractor.search.filter.FilterGroup; |
| 13 | +import org.schabi.newpipe.util.DeviceUtils; |
| 14 | + |
| 15 | +import androidx.annotation.NonNull; |
| 16 | + |
| 17 | +public class SearchFilterChipDialogGenerator extends SearchFilterDialogGenerator { |
| 18 | + |
| 19 | + public SearchFilterChipDialogGenerator( |
| 20 | + @NonNull final SearchFilterLogic logic, |
| 21 | + @NonNull final ViewGroup root, |
| 22 | + @NonNull final Context context) { |
| 23 | + super(logic, root, context); |
| 24 | + } |
| 25 | + |
| 26 | + @Override |
| 27 | + protected void createFilterGroup(@NonNull final FilterGroup filterGroup, |
| 28 | + @NonNull final UiWrapperMapDelegate wrapperDelegate, |
| 29 | + @NonNull final UiSelectorDelegate selectorDelegate) { |
| 30 | + final boolean doSpanDataOverMultipleCells = true; |
| 31 | + final UiItemWrapperViews viewsWrapper = new UiItemWrapperViews( |
| 32 | + filterGroup.getIdentifier()); |
| 33 | + |
| 34 | + if (filterGroup.getNameId() != null) { |
| 35 | + final GridLayout.LayoutParams layoutParams = |
| 36 | + clipFreeRightColumnLayoutParams(doSpanDataOverMultipleCells); |
| 37 | + final TextView filterLabel = createFilterLabel(filterGroup, layoutParams); |
| 38 | + globalLayout.addView(filterLabel); |
| 39 | + viewsWrapper.add(filterLabel); |
| 40 | + } |
| 41 | + |
| 42 | + final ChipGroup chipGroup = new ChipGroup(context); |
| 43 | + chipGroup.setLayoutParams( |
| 44 | + setDefaultMarginInDp(clipFreeRightColumnLayoutParams(doSpanDataOverMultipleCells), |
| 45 | + 8, 2, 4, 2)); |
| 46 | + chipGroup.setSingleLine(false); |
| 47 | + chipGroup.setSingleSelection(filterGroup.isOnlyOneCheckable()); |
| 48 | + |
| 49 | + createUiChipElementsForFilterGroupItems( |
| 50 | + filterGroup, wrapperDelegate, selectorDelegate, chipGroup); |
| 51 | + |
| 52 | + |
| 53 | + wrapperDelegate.put(filterGroup.getIdentifier(), viewsWrapper); |
| 54 | + globalLayout.addView(chipGroup); |
| 55 | + viewsWrapper.add(chipGroup); |
| 56 | + } |
| 57 | + |
| 58 | + private ViewGroup.MarginLayoutParams setDefaultMarginInDp( |
| 59 | + @NonNull final ViewGroup.MarginLayoutParams layoutParams, |
| 60 | + final int left, final int top, final int right, final int bottom) { |
| 61 | + layoutParams.setMargins( |
| 62 | + DeviceUtils.dpToPx(left, context), |
| 63 | + DeviceUtils.dpToPx(top, context), |
| 64 | + DeviceUtils.dpToPx(right, context), |
| 65 | + DeviceUtils.dpToPx(bottom, context) |
| 66 | + ); |
| 67 | + return layoutParams; |
| 68 | + } |
| 69 | + |
| 70 | +} |
0 commit comments