do some performance optimizations on jid host suggestions. fixes #3174
This commit is contained in:
parent
e0266d0efb
commit
63f203c1d1
|
@ -7,7 +7,6 @@ import android.widget.Filter;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
public class KnownHostsAdapter extends ArrayAdapter<String> {
|
public class KnownHostsAdapter extends ArrayAdapter<String> {
|
||||||
|
@ -16,22 +15,22 @@ public class KnownHostsAdapter extends ArrayAdapter<String> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected FilterResults performFiltering(CharSequence constraint) {
|
protected FilterResults performFiltering(CharSequence constraint) {
|
||||||
if (constraint != null) {
|
final ArrayList<String> suggestions = new ArrayList<>();
|
||||||
ArrayList<String> suggestions = new ArrayList<>();
|
final String[] split = constraint == null ? new String[0] : constraint.toString().split("@");
|
||||||
final String[] split = constraint.toString().split("@");
|
|
||||||
if (split.length == 1) {
|
if (split.length == 1) {
|
||||||
|
final String local = split[0].toLowerCase(Locale.ENGLISH);
|
||||||
for (String domain : domains) {
|
for (String domain : domains) {
|
||||||
suggestions.add(split[0].toLowerCase(Locale
|
suggestions.add(local + "@" + domain);
|
||||||
.getDefault()) + "@" + domain);
|
|
||||||
}
|
}
|
||||||
} else if (split.length == 2) {
|
} else if (split.length == 2) {
|
||||||
|
final String localPart = split[0].toLowerCase(Locale.ENGLISH);
|
||||||
|
final String domainPart = split[1].toLowerCase(Locale.ENGLISH);
|
||||||
|
if (domains.contains(domainPart)) {
|
||||||
|
return new FilterResults();
|
||||||
|
}
|
||||||
for (String domain : domains) {
|
for (String domain : domains) {
|
||||||
if (domain.contentEquals(split[1])) {
|
if (domain.contains(domainPart)) {
|
||||||
suggestions.clear();
|
suggestions.add(localPart + "@" + domain);
|
||||||
break;
|
|
||||||
} else if (domain.contains(split[1])) {
|
|
||||||
suggestions.add(split[0].toLowerCase(Locale
|
|
||||||
.getDefault()) + "@" + domain);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -41,9 +40,6 @@ public class KnownHostsAdapter extends ArrayAdapter<String> {
|
||||||
filterResults.values = suggestions;
|
filterResults.values = suggestions;
|
||||||
filterResults.count = suggestions.size();
|
filterResults.count = suggestions.size();
|
||||||
return filterResults;
|
return filterResults;
|
||||||
} else {
|
|
||||||
return new FilterResults();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -51,9 +47,7 @@ public class KnownHostsAdapter extends ArrayAdapter<String> {
|
||||||
ArrayList filteredList = (ArrayList) results.values;
|
ArrayList filteredList = (ArrayList) results.values;
|
||||||
if (results.count > 0) {
|
if (results.count > 0) {
|
||||||
clear();
|
clear();
|
||||||
for (Object c : filteredList) {
|
addAll(filteredList);
|
||||||
add((String) c);
|
|
||||||
}
|
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue