-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
searchfilters: integrate 3rd UI SearchFragment/SearchFragmentLegacy
- Loading branch information
1 parent
5c6201c
commit 1c7ca57
Showing
4 changed files
with
113 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragmentLegacy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// Created by evermind-zz 2022, licensed GNU GPL version 3 or later | ||
|
||
package org.schabi.newpipe.fragments.list.search; | ||
|
||
import android.os.Bundle; | ||
import android.view.Menu; | ||
import android.view.MenuInflater; | ||
import android.view.MenuItem; | ||
import android.view.View; | ||
|
||
import org.schabi.newpipe.R; | ||
import org.schabi.newpipe.extractor.NewPipe; | ||
import org.schabi.newpipe.extractor.StreamingService; | ||
import org.schabi.newpipe.extractor.exceptions.ExtractionException; | ||
import org.schabi.newpipe.fragments.list.search.filter.SearchFilterUIOptionMenu; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.appcompat.widget.Toolbar; | ||
import androidx.core.content.ContextCompat; | ||
import icepick.State; | ||
|
||
/** | ||
* UI that hosts the options menu based filter 'dialog'. | ||
* | ||
* Called ..Legacy because of this was the way NewPipe had implemented the search filter dialog. | ||
* The new UI was implemented using a {@link androidx.fragment.app.DialogFragment} | ||
* {@link SearchFragment} | ||
*/ | ||
public class SearchFragmentLegacy extends SearchFragment { | ||
|
||
private SearchFilterUIOptionMenu searchFilterUi; | ||
|
||
@State | ||
protected int countOnPrepareOptionsMenuCalls = 0; | ||
|
||
@Override | ||
protected void initializeFilterData() { | ||
try { | ||
final StreamingService service = NewPipe.getService(serviceId); | ||
|
||
searchFilterUi = new SearchFilterUIOptionMenu(service, this, getContext()); | ||
searchFilterUi.restorePreviouslySelectedFilters( | ||
userSelectedContentFilterList, | ||
userSelectedSortFilterList); | ||
|
||
userSelectedContentFilterList = searchFilterUi.getSelectedContentFilters(); | ||
userSelectedSortFilterList = searchFilterUi.getSelectedSortFilters(); | ||
selectedContentFilter = searchFilterUi.getSelectedContentFilterItems(); | ||
selectedSortFilter = searchFilterUi.getSelectedSortFiltersItems(); | ||
} catch (final ExtractionException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
public void onSaveInstanceState(@NonNull final Bundle bundle) { | ||
// get data to save its state via Icepick | ||
userSelectedContentFilterList = searchFilterUi.getSelectedContentFilters(); | ||
userSelectedSortFilterList = searchFilterUi.getSelectedSortFilters(); | ||
|
||
super.onSaveInstanceState(bundle); | ||
} | ||
|
||
@Override | ||
protected void createMenu(@NonNull final Menu menu, | ||
@NonNull final MenuInflater inflater) { | ||
searchFilterUi.createSearchUI(menu); | ||
} | ||
|
||
public boolean onOptionsItemSelected(@NonNull final MenuItem item) { | ||
return searchFilterUi.onOptionsItemSelected(item); | ||
} | ||
|
||
@Override | ||
protected void initViews(final View rootView, | ||
final Bundle savedInstanceState) { | ||
super.initViews(rootView, savedInstanceState); | ||
final Toolbar toolbar = (Toolbar) searchToolbarContainer.getParent(); | ||
toolbar.setOverflowIcon(ContextCompat.getDrawable(requireContext(), | ||
R.drawable.ic_sort)); | ||
} | ||
|
||
@Override | ||
public void onPrepareOptionsMenu(@NonNull @Nonnull final Menu menu) { | ||
super.onPrepareOptionsMenu(menu); | ||
// workaround: we want to hide the keyboard in case we open the options | ||
// menu. As somehow this method gets triggered twice but only the 2nd | ||
// time is relevant as the options menu is selected by the user. | ||
if (++countOnPrepareOptionsMenuCalls > 1) { | ||
hideKeyboardSearch(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters