From 1f8767074efe80a4f117c2f2ff05da49d6cb58b7 Mon Sep 17 00:00:00 2001 From: evermind Date: Thu, 8 Dec 2022 23:53:40 +0100 Subject: [PATCH] Revert "searchfilters: 2nd Ui: Action menu feel alike dialog" This reverts commit a5a588d169c90a15ece6cab1dfdbaad67f052a9f. --- ...chFilterOptionMenuAlikeDialogFragment.java | 88 ----- ...hFilterOptionMenuAlikeDialogGenerator.java | 356 ------------------ ...lter_option_menu_alike_dialog_fragment.xml | 22 -- 3 files changed, 466 deletions(-) delete mode 100644 app/src/main/java/org/schabi/newpipe/fragments/list/search/filter/SearchFilterOptionMenuAlikeDialogFragment.java delete mode 100644 app/src/main/java/org/schabi/newpipe/fragments/list/search/filter/SearchFilterOptionMenuAlikeDialogGenerator.java delete mode 100644 app/src/main/res/layout/search_filter_option_menu_alike_dialog_fragment.xml diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/search/filter/SearchFilterOptionMenuAlikeDialogFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/search/filter/SearchFilterOptionMenuAlikeDialogFragment.java deleted file mode 100644 index ad3a4f123..000000000 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/search/filter/SearchFilterOptionMenuAlikeDialogFragment.java +++ /dev/null @@ -1,88 +0,0 @@ -// Created by evermind-zz 2022, licensed GNU GPL version 3 or later - -package org.schabi.newpipe.fragments.list.search.filter; - -import android.app.Dialog; -import android.os.Bundle; -import android.view.Gravity; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.view.Window; -import android.view.WindowManager; - -import org.schabi.newpipe.databinding.SearchFilterOptionMenuAlikeDialogFragmentBinding; -import org.schabi.newpipe.extractor.StreamingService; - -import java.util.ArrayList; - -import androidx.annotation.NonNull; -import androidx.appcompat.widget.Toolbar; -import androidx.fragment.app.DialogFragment; - -public class SearchFilterOptionMenuAlikeDialogFragment extends BaseSearchFilterDialogFragment { - - private SearchFilterOptionMenuAlikeDialogFragmentBinding binding; - - public static DialogFragment newInstance( - final int serviceId, - final ArrayList userSelectedContentFilter, - final ArrayList userSelectedSortFilter) { - return initDialogArguments( - new SearchFilterOptionMenuAlikeDialogFragment(), - serviceId, - userSelectedContentFilter, - userSelectedSortFilter); - } - - @Override - protected BaseSearchFilterUiGenerator createSearchFilterDialogGenerator( - final StreamingService service, - final SearchFilterLogic.Callback callback) { - return new SearchFilterOptionMenuAlikeDialogGenerator(service, - binding.verticalScroll, getContext(), callback); - } - - @Override - protected Toolbar getToolbar() { - return binding.toolbarLayout.toolbar; - } - - @Override - protected View getRootView(final LayoutInflater inflater, - final ViewGroup container) { - binding = SearchFilterOptionMenuAlikeDialogFragmentBinding - .inflate(inflater, container, false); - return binding.getRoot(); - } - - @Override - public void onViewCreated(@NonNull final View view, final Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - // place the dialog in the 'action menu position' - setDialogGravity(Gravity.END | Gravity.TOP); - } - - private void setDialogGravity(final int gravity) { - final Dialog dialog = getDialog(); - if (dialog != null) { - final Window window = dialog.getWindow(); - if (window != null) { - final WindowManager.LayoutParams layoutParams = window.getAttributes(); - layoutParams.width = ViewGroup.LayoutParams.WRAP_CONTENT; - layoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT; - layoutParams.horizontalMargin = 0; - layoutParams.gravity = gravity; - layoutParams.dimAmount = 0; - layoutParams.flags &= ~WindowManager.LayoutParams.FLAG_DIM_BEHIND; - window.setAttributes(layoutParams); - } - } - } - - protected void initToolbar(final Toolbar toolbar) { - super.initToolbar(toolbar); - // no room for a title - toolbar.setTitle(""); - } -} diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/search/filter/SearchFilterOptionMenuAlikeDialogGenerator.java b/app/src/main/java/org/schabi/newpipe/fragments/list/search/filter/SearchFilterOptionMenuAlikeDialogGenerator.java deleted file mode 100644 index 810541775..000000000 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/search/filter/SearchFilterOptionMenuAlikeDialogGenerator.java +++ /dev/null @@ -1,356 +0,0 @@ -// Created by evermind-zz 2022, licensed GNU GPL version 3 or later - -package org.schabi.newpipe.fragments.list.search.filter; - -import android.content.Context; -import android.view.Gravity; -import android.view.View; -import android.view.ViewGroup; -import android.widget.CheckBox; -import android.widget.LinearLayout; -import android.widget.RadioButton; -import android.widget.RadioGroup; -import android.widget.TextView; - -import org.schabi.newpipe.extractor.StreamingService; -import org.schabi.newpipe.extractor.search.filter.FilterGroup; -import org.schabi.newpipe.extractor.search.filter.FilterItem; -import org.schabi.newpipe.util.ServiceHelper; - -import java.util.List; - -import androidx.annotation.NonNull; - -import static android.util.TypedValue.COMPLEX_UNIT_DIP; - -public class SearchFilterOptionMenuAlikeDialogGenerator extends BaseSearchFilterUiDialogGenerator { - private static final Integer NO_RESIZE_VIEW_TAG = 1; - private static final float FONT_SIZE_SELECTABLE_VIEW_ITEMS_IN_DIP = 18f; - private static final float VIEW_ITEMS_MIN_WIDTH_IN_DIP = 168f; - private final LinearLayout globalLayout; - - public SearchFilterOptionMenuAlikeDialogGenerator(final StreamingService service, - final ViewGroup root, - final Context context, - final Callback callback) { - super(service.getSearchQHFactory(), callback, context); - this.globalLayout = createGlobalLayout(); - root.addView(globalLayout); - } - - @Override - public void createSearchUI() { - initContentFiltersUi(contentFilterWorker); - initSortFiltersUi(sortFilterWorker); - measureWidthOfChildrenAndResizeToWidest(); - // make sure that only sort filters relevant to selected content filter are shown - showSortFilterContainerUI(); - } - - /** - * Resize all width of {@link #globalLayout} children without tag {@link #NO_RESIZE_VIEW_TAG}. - *

- * Initially this method was only used to resize the {@link #createSeparatorLine()} width - * but as also children view elements are set to the widest child. - *

- * Reasons: - * 1. Separator lines should be as wide as the widest UI element but this - * can only be determined on runtime - * 2. Other view elements more specific checkable/selectable should also - * expand their width over the complete dialog width to be easier to select - */ - private void measureWidthOfChildrenAndResizeToWidest() { - showAllAvailableSortFilters(); - - // initialize width with a passable default width - int widestViewInPx = (int) dipToPixels(context, VIEW_ITEMS_MIN_WIDTH_IN_DIP); - final int noOfChildren = globalLayout.getChildCount(); - - for (int x = 0; x < noOfChildren; x++) { - final View childView = globalLayout.getChildAt(x); - childView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); - final int width = childView.getMeasuredWidth(); - if (width > widestViewInPx) { - widestViewInPx = width; - } - } - - for (int x = 0; x < noOfChildren; x++) { - final View childView = globalLayout.getChildAt(x); - - if (childView.getTag() != NO_RESIZE_VIEW_TAG) { - final ViewGroup.LayoutParams layoutParams = childView.getLayoutParams(); - layoutParams.width = widestViewInPx; - childView.setLayoutParams(layoutParams); - } - } - } - - @Override - protected void createTitle(final String name, - final List titleViewElements) { - final TextView titleView = createTitleText(name); - titleView.setTag(NO_RESIZE_VIEW_TAG); - final View separatorLine = createSeparatorLine(); - final View separatorLine2 = createSeparatorLine(); - final View separatorLine3 = createSeparatorLine(); - - globalLayout.addView(separatorLine); - globalLayout.addView(separatorLine2); - globalLayout.addView(titleView); - globalLayout.addView(separatorLine3); - - titleViewElements.add(titleView); - titleViewElements.add(separatorLine); - titleViewElements.add(separatorLine2); - titleViewElements.add(separatorLine3); - } - - @Override - protected void createFilterGroup(final FilterGroup filterGroup, - final UiWrapperMapDelegate wrapperDelegate, - final UiSelectorDelegate selectorDelegate) { - final UiItemWrapperViews viewsWrapper = new UiItemWrapperViews( - filterGroup.getIdentifier(), filterGroup.getIdentifier()); - - final View separatorLine = createSeparatorLine(); - globalLayout.addView(separatorLine); - viewsWrapper.add(separatorLine); - - if (filterGroup.getName() != null) { - final TextView filterLabel = - createFilterGroupLabel(filterGroup, getLayoutParamsLabelLeft()); - globalLayout.addView(filterLabel); - viewsWrapper.add(filterLabel); - } - - if (filterGroup.isOnlyOneCheckable()) { - - final RadioGroup radioGroup = new RadioGroup(context); - radioGroup.setLayoutParams(getLayoutParamsViews()); - - createUiElementsForSingleSelectableItemsFilterGroup( - filterGroup, wrapperDelegate, selectorDelegate, radioGroup); - - globalLayout.addView(radioGroup); - viewsWrapper.add(radioGroup); - - } else { // multiple items in FilterGroup selectable - createUiElementsForMultipleSelectableItemsFilterGroup( - filterGroup, wrapperDelegate, selectorDelegate); - } - - wrapperDelegate.put(filterGroup.getIdentifier(), viewsWrapper); - } - - private void createUiElementsForSingleSelectableItemsFilterGroup( - final FilterGroup filterGroup, - final UiWrapperMapDelegate wrapperDelegate, - final UiSelectorDelegate selectorDelegate, - final RadioGroup radioGroup) { - for (final FilterItem item : filterGroup.getFilterItems()) { - - final View view; - if (item instanceof FilterItem.DividerItem) { - view = createDividerTextView(item, getLayoutParamsViews()); - } else { - view = createViewItemRadio(item, getLayoutParamsViews()); - - wrapperDelegate.put(item.getIdentifier(), - new UiItemWrapperCheckBoxAndRadioButton( - item, view, filterGroup.getIdentifier(), radioGroup)); - - final View.OnClickListener listener = v -> { - if (v != null) { - selectorDelegate.selectFilter(v.getId()); - } - }; - view.setOnClickListener(listener); - viewListeners.put(view, listener); - } - radioGroup.addView(view); - } - } - - private void createUiElementsForMultipleSelectableItemsFilterGroup( - final FilterGroup filterGroup, - final UiWrapperMapDelegate wrapperDelegate, - final UiSelectorDelegate selectorDelegate) { - for (final FilterItem item : filterGroup.getFilterItems()) { - final View view; - if (item instanceof FilterItem.DividerItem) { - view = createDividerTextView(item, getLayoutParamsViews()); - } else { - final CheckBox checkBox = createCheckBox(item, getLayoutParamsViews()); - - wrapperDelegate.put(item.getIdentifier(), - new UiItemWrapperCheckBoxAndRadioButton( - item, checkBox, filterGroup.getIdentifier(), null)); - - final View.OnClickListener listener = v -> { - if (v != null) { - selectorDelegate.selectFilter(v.getId()); - } - }; - checkBox.setOnClickListener(listener); - viewListeners.put(checkBox, listener); - - view = checkBox; - } - globalLayout.addView(view); - } - } - - private LinearLayout createGlobalLayout() { - final LinearLayout linearLayout = new LinearLayout(context); - - linearLayout.setOrientation(LinearLayout.VERTICAL); - - final LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(1, 1); - layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT; - layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT; - layoutParams.setMargins( - (int) dipToPixels(context, 2), - (int) dipToPixels(context, 2), - (int) dipToPixels(context, 2), - (int) dipToPixels(context, 2)); - linearLayout.setLayoutParams(layoutParams); - - return linearLayout; - } - - private LinearLayout.LayoutParams getLayoutForSeparatorLine() { - final LinearLayout.LayoutParams layoutParams = getLayoutParamsLabelLeft(); - layoutParams.width = 0; - layoutParams.gravity = Gravity.CENTER_HORIZONTAL; - return layoutParams; - } - - private View createSeparatorLine() { - return createSeparatorLine(getLayoutForSeparatorLine()); - } - - private TextView createTitleText(final String name) { - final LinearLayout.LayoutParams layoutParams = getLayoutParamsLabelLeft(); - layoutParams.gravity = Gravity.CENTER_HORIZONTAL; - final TextView title = createTitleText(name, layoutParams); - setPadding(title, 5); - return title; - } - - private View setPadding(final View view, final int sizeInDip) { - final int sizeInPx = (int) dipToPixels(context, sizeInDip); - view.setPadding( - sizeInPx, - sizeInPx, - sizeInPx, - sizeInPx); - return view; - } - - private TextView createFilterGroupLabel(final FilterGroup filterGroup, - final ViewGroup.LayoutParams layoutParams) { - final TextView filterLabel = new TextView(context); - filterLabel.setId(filterGroup.getIdentifier()); - filterLabel.setText(ServiceHelper - .getTranslatedFilterString(filterGroup.getName(), context)); - filterLabel.setGravity(Gravity.TOP); - // resizing not needed as view is not selectable - filterLabel.setTag(NO_RESIZE_VIEW_TAG); - filterLabel.setLayoutParams(layoutParams); - return filterLabel; - } - - private CheckBox createCheckBox(final FilterItem item, - final ViewGroup.LayoutParams layoutParams) { - final CheckBox checkBox = new CheckBox(context); - checkBox.setLayoutParams(layoutParams); - checkBox.setText(ServiceHelper.getTranslatedFilterString( - item.getName(), context)); - checkBox.setId(item.getIdentifier()); - checkBox.setTextSize(COMPLEX_UNIT_DIP, FONT_SIZE_SELECTABLE_VIEW_ITEMS_IN_DIP); - return checkBox; - } - - private TextView createDividerTextView(final FilterItem item, - final ViewGroup.LayoutParams layoutParams) { - final TextView view = new TextView(context); - view.setEnabled(true); - final String menuDividerTitle = - ServiceHelper.getTranslatedFilterString(item.getName(), context); - view.setText(menuDividerTitle); - view.setGravity(Gravity.TOP); - view.setLayoutParams(layoutParams); - return view; - } - - private RadioButton createViewItemRadio(final FilterItem item, - final ViewGroup.LayoutParams layoutParams) { - final RadioButton view = new RadioButton(context); - view.setId(item.getIdentifier()); - view.setText(ServiceHelper.getTranslatedFilterString(item.getName(), context)); - view.setLayoutParams(layoutParams); - view.setTextSize(COMPLEX_UNIT_DIP, FONT_SIZE_SELECTABLE_VIEW_ITEMS_IN_DIP); - return view; - } - - @NonNull - private LinearLayout.LayoutParams getLayoutParamsViews() { - final LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.MATCH_PARENT); - layoutParams.setMargins( - (int) dipToPixels(context, 4), - (int) dipToPixels(context, 8), - (int) dipToPixels(context, 4), - (int) dipToPixels(context, 8)); - return layoutParams; - } - - @NonNull - private LinearLayout.LayoutParams getLayoutParamsLabelLeft() { - final LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( - ViewGroup.LayoutParams.WRAP_CONTENT, - ViewGroup.LayoutParams.WRAP_CONTENT); - layoutParams.setMargins( - (int) dipToPixels(context, 2), - (int) dipToPixels(context, 2), - (int) dipToPixels(context, 2), - (int) dipToPixels(context, 2)); - return layoutParams; - } - - private static final class UiItemWrapperCheckBoxAndRadioButton - extends BaseUiItemWrapper { - - private final View group; - - private UiItemWrapperCheckBoxAndRadioButton(final FilterItem item, final View view, - final int groupId, final View group) { - super(item, groupId, view); - this.group = group; - } - - @Override - public boolean isChecked() { - if (view instanceof RadioButton) { - return ((RadioButton) view).isChecked(); - } else if (view instanceof CheckBox) { - return ((CheckBox) view).isChecked(); - } else { - return view.isSelected(); - } - } - - @Override - public void setChecked(final boolean checked) { - if (checked && group instanceof RadioGroup) { - ((RadioGroup) group).check(view.getId()); - } else if (view instanceof CheckBox) { - ((CheckBox) view).setChecked(checked); - } else { - view.setSelected(checked); - } - } - } -} diff --git a/app/src/main/res/layout/search_filter_option_menu_alike_dialog_fragment.xml b/app/src/main/res/layout/search_filter_option_menu_alike_dialog_fragment.xml deleted file mode 100644 index 22a260b59..000000000 --- a/app/src/main/res/layout/search_filter_option_menu_alike_dialog_fragment.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - -