From 46b054b9f831a003513b7ef49d39860c35471397 Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 14 Feb 2016 10:16:44 +0100 Subject: [PATCH] Prevent double name lookups --- .../eu/faircode/netguard/AdapterAccess.java | 10 +++-- .../java/eu/faircode/netguard/AdapterLog.java | 39 +++++++++++-------- 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/eu/faircode/netguard/AdapterAccess.java b/app/src/main/java/eu/faircode/netguard/AdapterAccess.java index cc9f60aa..4129a0e2 100644 --- a/app/src/main/java/eu/faircode/netguard/AdapterAccess.java +++ b/app/src/main/java/eu/faircode/netguard/AdapterAccess.java @@ -117,9 +117,13 @@ public class AdapterAccess extends CursorAdapter { Util.getProtocolName(protocol, version, true) + " " + daddr + (dport > 0 ? "/" + dport : "")); - if (Util.isNumericAddress(daddr)) { - tvDest.setTag(id); + if (Util.isNumericAddress(daddr) && tvDest.getTag() == null) new AsyncTask() { + @Override + protected void onPreExecute() { + tvDest.setTag(id); + } + @Override protected String doInBackground(String... args) { try { @@ -135,9 +139,9 @@ public class AdapterAccess extends CursorAdapter { tvDest.setText( Util.getProtocolName(protocol, version, true) + " " + addr + (dport > 0 ? "/" + dport : "")); + tvDest.setTag(null); } }.execute(daddr); - } if (allowed < 0) tvDest.setTextColor(colorText); diff --git a/app/src/main/java/eu/faircode/netguard/AdapterLog.java b/app/src/main/java/eu/faircode/netguard/AdapterLog.java index 8d4c56ac..197d2b16 100644 --- a/app/src/main/java/eu/faircode/netguard/AdapterLog.java +++ b/app/src/main/java/eu/faircode/netguard/AdapterLog.java @@ -220,24 +220,31 @@ public class AdapterLog extends CursorAdapter { if (resolve && !isKnownAddress(daddr)) if (dname == null) { - tvDaddr.setText(daddr); - tvDaddr.setTag(id); - new AsyncTask() { - @Override - protected String doInBackground(String... args) { - try { - return InetAddress.getByName(args[0]).getHostName(); - } catch (UnknownHostException ignored) { - return args[0]; + if (tvDaddr.getTag() == null) { + tvDaddr.setText(daddr); + new AsyncTask() { + @Override + protected void onPreExecute() { + tvDaddr.setTag(id); } - } - @Override - protected void onPostExecute(String name) { - if ((Long) tvDaddr.getTag() == id) - tvDaddr.setText(name); - } - }.execute(daddr); + @Override + protected String doInBackground(String... args) { + try { + return InetAddress.getByName(args[0]).getHostName(); + } catch (UnknownHostException ignored) { + return args[0]; + } + } + + @Override + protected void onPostExecute(String name) { + if ((Long) tvDaddr.getTag() == id) + tvDaddr.setText(name); + tvDaddr.setTag(null); + } + }.execute(daddr); + } } else tvDaddr.setText(dname); else