Skip to content

Commit 868be7a

Browse files
committed
searchfilters: replace Map<Integer, Integer> with SparseIntArray
1 parent 0dc3f10 commit 868be7a

2 files changed

Lines changed: 11 additions & 8 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import android.annotation.SuppressLint;
66
import android.content.Context;
7+
import android.util.SparseIntArray;
78
import android.view.Gravity;
89
import android.view.View;
910
import android.view.ViewGroup;
@@ -28,7 +29,7 @@ public class SearchFilterDialogSpinnerAdapter extends BaseAdapter {
2829
private final FilterGroup group;
2930
private final BaseSearchFilterUiGenerator.UiWrapperMapDelegate wrapperDelegate;
3031
private final Spinner spinner;
31-
private final Map<Integer, Integer> id2PosMap = new HashMap<>();
32+
private final SparseIntArray id2PosMap = new SparseIntArray();
3233
private final Map<Integer, UiItemWrapperSpinner>
3334
viewWrapperMap = new HashMap<>();
3435

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
package org.schabi.newpipe.fragments.list.search.filter;
44

5+
import android.util.SparseIntArray;
6+
57
import org.schabi.newpipe.extractor.linkhandler.SearchQueryHandlerFactory;
68
import org.schabi.newpipe.extractor.search.filter.FilterContainer;
79
import org.schabi.newpipe.extractor.search.filter.FilterGroup;
@@ -638,7 +640,7 @@ void selectedFilters(List<FilterItem> userSelectedContentFilter,
638640
*/
639641
private static class ExclusiveGroups {
640642

641-
final Map<Integer, Integer> actualSelectedFilterIdInExclusiveGroupMap = new HashMap<>();
643+
final SparseIntArray actualSelectedFilterIdInExclusiveGroupMap = new SparseIntArray();
642644
/**
643645
* To quickly determine if a content filter group supports
644646
* only one item selected (exclusiveness), we need a set that resembles that.
@@ -648,7 +650,7 @@ private static class ExclusiveGroups {
648650
* To quickly determine if a content filter id belongs to an exclusive group.
649651
* This maps works in conjunction with {@link #exclusiveGroupsIdSet}
650652
*/
651-
private final Map<Integer, Integer> filterIdToGroupIdMap = new HashMap<>();
653+
private final SparseIntArray filterIdToGroupIdMap = new SparseIntArray();
652654

653655
/**
654656
* Clear {@link #exclusiveGroupsIdSet} and {@link #filterIdToGroupIdMap}.
@@ -666,7 +668,7 @@ public void clear() {
666668
* @return true if valid
667669
*/
668670
public boolean filterIdToGroupIdMapContainsId(final int filterId) {
669-
return filterIdToGroupIdMap.containsKey(filterId);
671+
return filterIdToGroupIdMap.indexOfKey(filterId) >= 0;
670672
}
671673

672674
public boolean isFilterIdPartOfAnExclusiveGroup(final int filterId) {
@@ -744,10 +746,10 @@ private int ifInExclusiveGroupRemovePreviouslySelectedId(final int filterId) {
744746
int previousFilterId = ITEM_IDENTIFIER_UNKNOWN;
745747
final int filterGroupId = filterIdToGroupIdMap.get(filterId);
746748

747-
if (exclusiveGroupsIdSet.contains(filterGroupId)
748-
&& actualSelectedFilterIdInExclusiveGroupMap.containsKey(filterGroupId)) {
749-
previousFilterId = actualSelectedFilterIdInExclusiveGroupMap.get(filterGroupId);
750-
actualSelectedFilterIdInExclusiveGroupMap.remove(filterGroupId);
749+
final int index = actualSelectedFilterIdInExclusiveGroupMap.indexOfKey(filterGroupId);
750+
if (exclusiveGroupsIdSet.contains(filterGroupId) && index >= 0) {
751+
previousFilterId = actualSelectedFilterIdInExclusiveGroupMap.valueAt(index);
752+
actualSelectedFilterIdInExclusiveGroupMap.removeAt(index);
751753
}
752754
return previousFilterId;
753755
}

0 commit comments

Comments
 (0)