|
| 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.app.Dialog; |
| 6 | +import android.os.Bundle; |
| 7 | +import android.view.Gravity; |
| 8 | +import android.view.LayoutInflater; |
| 9 | +import android.view.View; |
| 10 | +import android.view.ViewGroup; |
| 11 | +import android.view.Window; |
| 12 | +import android.view.WindowManager; |
| 13 | + |
| 14 | +import org.schabi.newpipe.databinding.SearchFilterOptionMenuAlikeDialogFragmentBinding; |
| 15 | +import org.schabi.newpipe.extractor.StreamingService; |
| 16 | + |
| 17 | +import java.util.ArrayList; |
| 18 | + |
| 19 | +import androidx.annotation.NonNull; |
| 20 | +import androidx.appcompat.widget.Toolbar; |
| 21 | +import androidx.fragment.app.DialogFragment; |
| 22 | + |
| 23 | +/** |
| 24 | + * A search filter dialog that looks like a action menu aka. 'action menu style'. |
| 25 | + */ |
| 26 | +public class SearchFilterOptionMenuAlikeDialogFragment extends BaseSearchFilterDialogFragment { |
| 27 | + |
| 28 | + private SearchFilterOptionMenuAlikeDialogFragmentBinding binding; |
| 29 | + |
| 30 | + public static DialogFragment newInstance( |
| 31 | + final int serviceId, |
| 32 | + final ArrayList<Integer> userSelectedContentFilter, |
| 33 | + final ArrayList<Integer> userSelectedSortFilter) { |
| 34 | + return initDialogArguments( |
| 35 | + new SearchFilterOptionMenuAlikeDialogFragment(), |
| 36 | + serviceId, |
| 37 | + userSelectedContentFilter, |
| 38 | + userSelectedSortFilter); |
| 39 | + } |
| 40 | + |
| 41 | + @Override |
| 42 | + protected BaseSearchFilterUiGenerator createSearchFilterDialogGenerator( |
| 43 | + final StreamingService service, |
| 44 | + final SearchFilterLogic.Callback callback) { |
| 45 | + return new SearchFilterOptionMenuAlikeDialogGenerator(service, |
| 46 | + binding.verticalScroll, requireContext(), callback); |
| 47 | + } |
| 48 | + |
| 49 | + @Override |
| 50 | + protected Toolbar getToolbar() { |
| 51 | + return binding.toolbarLayout.toolbar; |
| 52 | + } |
| 53 | + |
| 54 | + @Override |
| 55 | + protected View getRootView(final LayoutInflater inflater, |
| 56 | + final ViewGroup container) { |
| 57 | + binding = SearchFilterOptionMenuAlikeDialogFragmentBinding |
| 58 | + .inflate(inflater, container, false); |
| 59 | + return binding.getRoot(); |
| 60 | + } |
| 61 | + |
| 62 | + @Override |
| 63 | + public void onViewCreated(@NonNull final View view, final Bundle savedInstanceState) { |
| 64 | + super.onViewCreated(view, savedInstanceState); |
| 65 | + // place the dialog in the 'action menu position' |
| 66 | + setDialogGravity(Gravity.END | Gravity.TOP); |
| 67 | + } |
| 68 | + |
| 69 | + private void setDialogGravity(final int gravity) { |
| 70 | + final Dialog dialog = getDialog(); |
| 71 | + if (dialog != null) { |
| 72 | + final Window window = dialog.getWindow(); |
| 73 | + if (window != null) { |
| 74 | + final WindowManager.LayoutParams layoutParams = window.getAttributes(); |
| 75 | + layoutParams.width = ViewGroup.LayoutParams.WRAP_CONTENT; |
| 76 | + layoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT; |
| 77 | + layoutParams.horizontalMargin = 0; |
| 78 | + layoutParams.gravity = gravity; |
| 79 | + layoutParams.dimAmount = 0; |
| 80 | + layoutParams.flags &= ~WindowManager.LayoutParams.FLAG_DIM_BEHIND; |
| 81 | + window.setAttributes(layoutParams); |
| 82 | + } |
| 83 | + } |
| 84 | + } |
| 85 | + |
| 86 | + protected void initToolbar(final Toolbar toolbar) { |
| 87 | + super.initToolbar(toolbar); |
| 88 | + // no room for a title |
| 89 | + toolbar.setTitle(""); |
| 90 | + } |
| 91 | +} |
0 commit comments