mirror of https://github.com/M66B/NetGuard.git
Better logic, better layout
This commit is contained in:
parent
94ec8a5266
commit
c80fe4d2ea
|
@ -43,15 +43,17 @@ public class AccessAdapter extends CursorAdapter {
|
|||
// Get views
|
||||
TextView tvTime = (TextView) view.findViewById(R.id.tvTime);
|
||||
CheckBox cbIp = (CheckBox) view.findViewById(R.id.cbIp);
|
||||
TextView tvDest = (TextView) view.findViewById(R.id.tvDest);
|
||||
TextView tvPort = (TextView) view.findViewById(R.id.tvPort);
|
||||
final TextView tvDest = (TextView) view.findViewById(R.id.tvDest);
|
||||
|
||||
// Set values
|
||||
tvTime.setText(new SimpleDateFormat("HH:mm:ss").format(time));
|
||||
cbIp.setChecked(allowed != 0);
|
||||
tvDest.setText(dest);
|
||||
tvPort.setText(dport > 0 ? Integer.toString(dport) : "");
|
||||
|
||||
Util.resolveName(dest, tvDest);
|
||||
Util.resolveName(dest, new Util.resolveListener() {
|
||||
@Override
|
||||
public void onResolved(String name, boolean resolved) {
|
||||
tvDest.setText(name + (dport > 0 ? ":" + dport : ""));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,8 @@ import android.content.Context;
|
|||
import android.util.AttributeSet;
|
||||
import android.widget.ListView;
|
||||
|
||||
// This requires list view items with equal heights
|
||||
|
||||
public class ExpandedListView extends ListView {
|
||||
public ExpandedListView(Context context) {
|
||||
super(context);
|
||||
|
|
|
@ -171,7 +171,12 @@ public class LogAdapter extends CursorAdapter {
|
|||
tvSAddr.setText(getKnownAddress(saddr));
|
||||
|
||||
if (resolve && !isKnownAddress(daddr))
|
||||
Util.resolveName(daddr, tvDaddr);
|
||||
Util.resolveName(daddr, new Util.resolveListener() {
|
||||
@Override
|
||||
public void onResolved(String name, boolean resolved) {
|
||||
tvDaddr.setText(name);
|
||||
}
|
||||
});
|
||||
else
|
||||
tvDaddr.setText(getKnownAddress(daddr));
|
||||
|
||||
|
|
|
@ -355,12 +355,16 @@ public class Util {
|
|||
|
||||
private static Map<String, String> mapIPHost = new HashMap<String, String>();
|
||||
|
||||
public static void resolveName(String name, final TextView tv) {
|
||||
public interface resolveListener {
|
||||
void onResolved(String name, boolean resolved);
|
||||
}
|
||||
|
||||
public static void resolveName(String name, final resolveListener listener) {
|
||||
synchronized (mapIPHost) {
|
||||
if (mapIPHost.containsKey(name))
|
||||
tv.setText(mapIPHost.get(name));
|
||||
listener.onResolved(mapIPHost.get(name), true);
|
||||
else {
|
||||
tv.setText(name);
|
||||
listener.onResolved(name, false);
|
||||
|
||||
new AsyncTask<String, Object, String>() {
|
||||
@Override
|
||||
|
@ -379,7 +383,7 @@ public class Util {
|
|||
if (!mapIPHost.containsKey(host))
|
||||
mapIPHost.put(host, host);
|
||||
}
|
||||
tv.setText(host);
|
||||
listener.onResolved(host, true);
|
||||
}
|
||||
}.execute(name);
|
||||
}
|
||||
|
|
|
@ -23,31 +23,15 @@
|
|||
android:scaleX="0.8"
|
||||
android:scaleY="0.8" />
|
||||
|
||||
<LinearLayout
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvDest"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_weight="1">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvDest"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="@android:style/TextAppearance.Material.Small"
|
||||
android:textSize="12sp" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text=":"
|
||||
android:textAppearance="@android:style/TextAppearance.Material.Small"
|
||||
android:textSize="12sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvPort"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="@android:style/TextAppearance.Material.Small"
|
||||
android:textSize="12sp" />
|
||||
</LinearLayout>
|
||||
android:layout_weight="1"
|
||||
android:ellipsize="end"
|
||||
android:singleLine="true"
|
||||
android:textAppearance="@android:style/TextAppearance.Material.Small"
|
||||
android:textSize="12sp" />
|
||||
</LinearLayout>
|
||||
|
|
Loading…
Reference in New Issue