blob: b9e2d4155b09ab1c52480599a7685f2b9729e41f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
package com.android.launcher3.icons;
import java.util.ArrayList;
import java.util.List;
class IconsSearchUtils {
static void filter(String query, List<String> matchingIcons, List<String> allIcons,
IconPickerActivity.GridAdapter mGridAdapter) {
//new array list that will hold the filtered data
List<String> resultsFromAllIcons = new ArrayList<>();
List<String> resultsFromMatchingIcons = new ArrayList<>();
boolean noMatch = matchingIcons.isEmpty();
if (query.isEmpty()) {
resultsFromAllIcons.clear();
resultsFromAllIcons.add(null);
resultsFromAllIcons.addAll(allIcons);
resultsFromMatchingIcons.clear();
if (!noMatch) {
resultsFromMatchingIcons.add(null);
resultsFromMatchingIcons.addAll(matchingIcons);
}
mGridAdapter.filterList(resultsFromAllIcons, resultsFromMatchingIcons);
} else {
resultsFromAllIcons.clear();
resultsFromMatchingIcons.clear();
if (noMatch) {
getFilteredResults(allIcons, resultsFromAllIcons, query);
} else {
resultsFromAllIcons.clear();
resultsFromMatchingIcons.clear();
getFilteredResults(allIcons, resultsFromAllIcons, query);
getFilteredResults(matchingIcons, resultsFromMatchingIcons, query);
}
//calling a method of the adapter class and passing the filtered list
mGridAdapter.filterList(resultsFromAllIcons, resultsFromMatchingIcons);
}
}
private static void getFilteredResults(List<String> originalList, List<String> filteredResults,
String query) {
for (String item : originalList) {
if (item.contains(query)) filteredResults.add(item);
}
}
}
|