mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-04-21 06:19:12 +00:00
Merge pull request #1263 from alexbakker/icon-suggestion-prio
Prioritize normal icon issuer matches over inverse matches
This commit is contained in:
commit
d16d56c4b0
2 changed files with 38 additions and 18 deletions
|
@ -18,7 +18,6 @@ import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class IconPack {
|
public class IconPack {
|
||||||
private UUID _uuid;
|
private UUID _uuid;
|
||||||
|
@ -59,9 +58,21 @@ public class IconPack {
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
return _icons.stream()
|
List<Icon> icons = new ArrayList<>();
|
||||||
.filter(i -> i.isSuggestedFor(issuer))
|
for (Icon icon : _icons) {
|
||||||
.collect(Collectors.toList());
|
MatchType matchType = icon.getMatchFor(issuer);
|
||||||
|
if (matchType != null) {
|
||||||
|
// Inverse matches (entry issuer contains icon name) are less likely
|
||||||
|
// to be good, so position them at the end of the list.
|
||||||
|
if (matchType.equals(MatchType.NORMAL)) {
|
||||||
|
icons.add(0, icon);
|
||||||
|
} else if (matchType.equals(MatchType.INVERSE)) {
|
||||||
|
icons.add(icon);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return icons;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
@ -162,15 +173,24 @@ public class IconPack {
|
||||||
return _category;
|
return _category;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getIssuers() {
|
private MatchType getMatchFor(String issuer) {
|
||||||
return Collections.unmodifiableList(_issuers);
|
String lowerEntryIssuer = issuer.toLowerCase();
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isSuggestedFor(String issuer) {
|
boolean inverseMatch = false;
|
||||||
String lowerIssuer = issuer.toLowerCase();
|
for (String is : _issuers) {
|
||||||
return getIssuers().stream()
|
String lowerIconIssuer = is.toLowerCase();
|
||||||
.map(String::toLowerCase)
|
if (lowerIconIssuer.contains(lowerEntryIssuer)) {
|
||||||
.anyMatch(is -> is.contains(lowerIssuer) || lowerIssuer.contains(is));
|
return MatchType.NORMAL;
|
||||||
|
}
|
||||||
|
if (lowerEntryIssuer.contains(lowerIconIssuer)) {
|
||||||
|
inverseMatch = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (inverseMatch) {
|
||||||
|
return MatchType.INVERSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Icon fromJson(JSONObject obj) throws JSONException {
|
public static Icon fromJson(JSONObject obj) throws JSONException {
|
||||||
|
@ -188,4 +208,9 @@ public class IconPack {
|
||||||
return new Icon(filename, name, category, issuers);
|
return new Icon(filename, name, category, issuers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private enum MatchType {
|
||||||
|
NORMAL,
|
||||||
|
INVERSE
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,6 @@ import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class IconAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
public class IconAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||||
private final Context _context;
|
private final Context _context;
|
||||||
|
@ -96,11 +95,7 @@ public class IconAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||||
if (_query == null) {
|
if (_query == null) {
|
||||||
loadIcons(_pack, false);
|
loadIcons(_pack, false);
|
||||||
} else {
|
} else {
|
||||||
_icons = _pack.getIcons().stream()
|
_icons = _pack.getSuggestedIcons(query);
|
||||||
.filter(i -> i.isSuggestedFor(query))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
Collections.sort(_icons, Comparator.comparing(IconPack.Icon::getName));
|
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue