Narrow Android autofill chooser results
This commit is contained in:
@@ -2,6 +2,7 @@ package org.julianfamily.keepassgo;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
@@ -45,7 +46,25 @@ final class AutofillTargetMatcher {
|
||||
resolved.add(direct);
|
||||
return resolved;
|
||||
}
|
||||
return new ArrayList<>(entries);
|
||||
NormalizedTarget target = normalize(rawTarget);
|
||||
List<Entry> exactHost = new ArrayList<>();
|
||||
List<Entry> parentHost = new ArrayList<>();
|
||||
for (Entry entry : entries) {
|
||||
if (entryMatchesHost(entry, target.host)) {
|
||||
exactHost.add(entry);
|
||||
continue;
|
||||
}
|
||||
if (entryMatchesParentHost(entry, target.host)) {
|
||||
parentHost.add(entry);
|
||||
}
|
||||
}
|
||||
if (!exactHost.isEmpty()) {
|
||||
return sortEntries(exactHost);
|
||||
}
|
||||
if (!parentHost.isEmpty()) {
|
||||
return sortEntries(parentHost);
|
||||
}
|
||||
return sortEntries(entries);
|
||||
}
|
||||
|
||||
static NormalizedTarget normalize(String raw) {
|
||||
@@ -186,6 +205,15 @@ final class AutofillTargetMatcher {
|
||||
return new MatchQuality(false, bestPrefixLen);
|
||||
}
|
||||
|
||||
private static List<Entry> sortEntries(List<Entry> entries) {
|
||||
List<Entry> sorted = new ArrayList<>(entries);
|
||||
sorted.sort(Comparator
|
||||
.comparing((Entry entry) -> entry.title.toLowerCase(Locale.US))
|
||||
.thenComparing(entry -> String.join("/", entry.path).toLowerCase(Locale.US))
|
||||
.thenComparing(entry -> entry.id));
|
||||
return sorted;
|
||||
}
|
||||
|
||||
static final class NormalizedTarget {
|
||||
final String host;
|
||||
final String path;
|
||||
|
||||
Reference in New Issue
Block a user