22
33package org .schabi .newpipe .fragments .list .search .filter ;
44
5+ import android .util .SparseIntArray ;
6+
57import org .schabi .newpipe .extractor .linkhandler .SearchQueryHandlerFactory ;
68import org .schabi .newpipe .extractor .search .filter .FilterContainer ;
79import 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