diff options
author | Christian Schneppe <christian@pix-art.de> | 2018-09-14 23:04:20 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2018-09-14 23:04:20 +0200 |
commit | 06d8d58ce7d77ef772460cfe66b154e926cd9528 (patch) | |
tree | 38ff0f869258ccde1b3015f0e715b6c76b0d3104 /src/main/java/de/pixart | |
parent | 51887fe4971405e3cabcb985629296d3329480d9 (diff) |
do some performance optimizations on jid host suggestions
Diffstat (limited to 'src/main/java/de/pixart')
-rw-r--r-- | src/main/java/de/pixart/messenger/ui/adapter/KnownHostsAdapter.java | 184 |
1 files changed, 22 insertions, 162 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/adapter/KnownHostsAdapter.java b/src/main/java/de/pixart/messenger/ui/adapter/KnownHostsAdapter.java index 9f4a52d95..2e0bfccc6 100644 --- a/src/main/java/de/pixart/messenger/ui/adapter/KnownHostsAdapter.java +++ b/src/main/java/de/pixart/messenger/ui/adapter/KnownHostsAdapter.java @@ -7,8 +7,6 @@ import android.widget.Filter; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; import java.util.Locale; public class KnownHostsAdapter extends ArrayAdapter<String> { @@ -17,34 +15,31 @@ public class KnownHostsAdapter extends ArrayAdapter<String> { @Override protected FilterResults performFiltering(CharSequence constraint) { - if (constraint != null) { - ArrayList<String> suggestions = new ArrayList<>(); - final String[] split = constraint.toString().split("@"); - if (split.length == 1) { - for (String domain : domains) { - suggestions.add(split[0].toLowerCase(Locale - .getDefault()) + "@" + domain); - } - } else if (split.length == 2) { - for (String domain : domains) { - if (domain.contentEquals(split[1])) { - suggestions.clear(); - break; - } else if (domain.contains(split[1])) { - suggestions.add(split[0].toLowerCase(Locale - .getDefault()) + "@" + domain); - } - } - } else { + final ArrayList<String> suggestions = new ArrayList<>(); + final String[] split = constraint == null ? new String[0] : constraint.toString().split("@"); + if (split.length == 1) { + final String local = split[0].toLowerCase(Locale.ENGLISH); + for (String domain : domains) { + suggestions.add(local + "@" + domain); + } + } 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(); } - FilterResults filterResults = new FilterResults(); - filterResults.values = suggestions; - filterResults.count = suggestions.size(); - return filterResults; + for (String domain : domains) { + if (domain.contains(domainPart)) { + suggestions.add(localPart + "@" + domain); + } + } } else { return new FilterResults(); } + FilterResults filterResults = new FilterResults(); + filterResults.values = suggestions; + filterResults.count = suggestions.size(); + return filterResults; } @Override @@ -52,9 +47,7 @@ public class KnownHostsAdapter extends ArrayAdapter<String> { ArrayList filteredList = (ArrayList) results.values; if (results.count > 0) { clear(); - for (Object c : filteredList) { - add((String) c); - } + addAll(filteredList); notifyDataSetChanged(); } } @@ -62,140 +55,7 @@ public class KnownHostsAdapter extends ArrayAdapter<String> { public KnownHostsAdapter(Context context, int viewResourceId, Collection<String> mKnownHosts) { super(context, viewResourceId, new ArrayList<>()); - - if (mKnownHosts == null) { - domains = new ArrayList<>(); - } else { - domains = new ArrayList<>(mKnownHosts); - } - - HashSet<String> hashSet = new HashSet<>(); - - // get servers from https://conversations.im/compliance/ - new Thread(() -> { - domains.add("pix-art.de"); - domains.add("conversations.im"); - domains.add("jabber.cat"); - domains.add("jabjab.de"); - domains.add("im.koderoot.net"); - domains.add("riotcat.org"); - domains.add("magicbroccoli.de"); - domains.add("kode.im"); - domains.add("jabber-germany.de"); - domains.add("simplewire.de"); - domains.add("suchat.org"); - domains.add("jabber.at"); - domains.add("trashserver.net"); - domains.add("wiuwiu.de"); - domains.add("5222.de"); - domains.add("dismail.de"); - domains.add("chat.sum7.eu"); - domains.add("xmpp.zone"); - domains.add("libranet.de"); - domains.add("laborversuch.de"); - domains.add("creep.im"); - domains.add("jabber.systemausfall.org"); - domains.add("jabber.hot-chilli.net"); - domains.add("jabber.fr"); - domains.add("jabber.de"); - domains.add("draugr.de"); - domains.add("elaon.de"); - domains.add("high-way.me"); - domains.add("jabber.rwth-aachen.de"); - domains.add("deshalbfrei.org"); - domains.add("mail.de"); - domains.add("bommboo.de"); - domains.add("jabber.systemli.org"); - domains.add("jabb.im"); - domains.add("mailbox.org"); - domains.add("hot-chilli.net"); - domains.add("jabberpl.org"); - domains.add("chinwag.im"); - domains.add("tchncs.de"); - domains.add("zsim.de"); - domains.add("patchcord.be"); - domains.add("gajim.org"); - domains.add("talker.to"); - domains.add("pimux.de"); - domains.add("jabber.home.vdlinde.org"); - domains.add("im.apinc.org"); - domains.add("chatme.im"); - domains.add("fusselkater.org"); - domains.add("datenknoten.me"); - domains.add("fysh.in"); - domains.add("jabber.chaos-darmstadt.de"); - domains.add("yax.im"); - domains.add("neko.im"); - domains.add("jabberzac.org"); - domains.add("xmpp.is"); - domains.add("home.zom.im"); - domains.add("jabber.ccc.de"); - domains.add("jwchat.org"); - domains.add("kdetalk.net"); - domains.add("kde.org"); - domains.add("riseup.net"); - domains.add("ruhr-uni-bochum.de"); - domains.add("njs.netlab.cz"); - domains.add("schokokeks.org"); - domains.add("jabber.cz"); - domains.add("ubuntu-jabber.de"); - domains.add("xabber.de"); - domains.add("ubuntu-jabber.net"); - domains.add("jabber.ru"); - domains.add("darknet.nz"); - domains.add("movim.eu"); - domains.add("404.city"); - domains.add("igniterealtime.org"); - domains.add("kapsi.fi"); - domains.add("jabbel.net"); - domains.add("joindiaspora.com"); - domains.add("alpha-labs.net"); - domains.add("xmppnet.de"); - domains.add("hoth.one"); - domains.add("blah.im"); - domains.add("xmpp.jp"); - domains.add("jabber.uni-mainz.de"); - domains.add("richim.org"); - domains.add("tigase.im"); - domains.add("jappix.com"); - domains.add("member.fsf.org"); - domains.add("jabber.rueckgr.at"); - domains.add("swissjabber.ch"); - domains.add("twattle.net"); - domains.add("jabber.calyxinstitute.org"); - domains.add("sapo.pt"); - domains.add("uprod.biz"); - domains.add("krautspace.de"); - domains.add("kraut.space"); - domains.add("null.pm"); - domains.add("anonymitaet-im-inter.net"); - domains.add("0nl1ne.at"); - domains.add("linuxlovers.at"); - domains.add("jabber.org"); - domains.add("jabber.no-sense.net"); - domains.add("swissjabber.eu"); - domains.add("swissjabber.org"); - domains.add("swissjabber.de"); - domains.add("swissjabber.li"); - domains.add("jabber.no"); - domains.add("cypherpunks.it"); - domains.add("adastra.re"); - domains.add("jabber-br.org"); - domains.add("einfachjabber.de"); - domains.add("jabber.smash-net.org"); - domains.add("freifunk.im"); - domains.add("openmailbox.org"); - domains.add("jabber.otr.im"); - domains.add("evil.im"); - domains.add("xmpp.slack.com"); - domains.add("chat.hipchat.com"); - domains.add("googlemail.com"); - - hashSet.addAll(domains); - domains.clear(); - domains.addAll(hashSet); - Collections.sort(domains, String::compareToIgnoreCase); - }).start(); + domains = new ArrayList<>(mKnownHosts); } public KnownHostsAdapter(Context context, int viewResourceId) { |