Show link host name

pull/157/head
M66B 6 years ago
parent 9341b166ba
commit 28fd55a639

@ -3387,6 +3387,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
final CheckBox cbSecure = view.findViewById(R.id.cbSecure); final CheckBox cbSecure = view.findViewById(R.id.cbSecure);
CheckBox cbSanitize = view.findViewById(R.id.cbSanitize); CheckBox cbSanitize = view.findViewById(R.id.cbSanitize);
final TextView tvOwner = view.findViewById(R.id.tvOwner); final TextView tvOwner = view.findViewById(R.id.tvOwner);
final TextView tvHost = view.findViewById(R.id.tvHost);
final Group grpOwner = view.findViewById(R.id.grpOwner); final Group grpOwner = view.findViewById(R.id.grpOwner);
tvTitle.setText(title); tvTitle.setText(title);
@ -3463,7 +3464,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putParcelable("uri", uri); args.putParcelable("uri", uri);
new SimpleTask<String>() { new SimpleTask<String[]>() {
@Override @Override
protected void onPreExecute(Bundle args) { protected void onPreExecute(Bundle args) {
tvOwner.setText("…"); tvOwner.setText("…");
@ -3471,13 +3472,16 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
} }
@Override @Override
protected String onExecute(Context context, Bundle args) throws Throwable { protected String[] onExecute(Context context, Bundle args) throws Throwable {
Uri uri = args.getParcelable("uri"); Uri uri = args.getParcelable("uri");
return IPInfo.getOrganization(uri); return IPInfo.getOrganization(uri);
} }
@Override @Override
protected void onExecuted(Bundle args, String organization) { protected void onExecuted(Bundle args, String[] data) {
String host = data[0];
String organization = data[1];
tvHost.setText(host);
tvOwner.setText(organization == null ? "?" : organization); tvOwner.setText(organization == null ? "?" : organization);
} }

@ -37,7 +37,7 @@ import javax.net.ssl.HttpsURLConnection;
public class IPInfo { public class IPInfo {
private static Map<String, String> hostOrganization = new HashMap<>(); private static Map<String, String> hostOrganization = new HashMap<>();
static String getOrganization(Uri uri) throws IOException, ParseException { static String[] getOrganization(Uri uri) throws IOException, ParseException {
if ("mailto".equals(uri.getScheme())) { if ("mailto".equals(uri.getScheme())) {
MailTo email = MailTo.parse(uri.toString()); MailTo email = MailTo.parse(uri.toString());
String to = email.getTo(); String to = email.getTo();
@ -53,10 +53,10 @@ public class IPInfo {
} }
} }
private static String getOrganization(String host) throws IOException { private static String[] getOrganization(String host) throws IOException {
synchronized (hostOrganization) { synchronized (hostOrganization) {
if (hostOrganization.containsKey(host)) if (hostOrganization.containsKey(host))
return hostOrganization.get(host); return new String[]{host, hostOrganization.get(host)};
} }
InetAddress address = InetAddress.getByName(host); InetAddress address = InetAddress.getByName(host);
URL url = new URL("https://ipinfo.io/" + address.getHostAddress() + "/org"); URL url = new URL("https://ipinfo.io/" + address.getHostAddress() + "/org");
@ -72,7 +72,7 @@ public class IPInfo {
synchronized (hostOrganization) { synchronized (hostOrganization) {
hostOrganization.put(host, organization); hostOrganization.put(host, organization);
} }
return organization; return new String[]{host, organization};
} }
} }
} }

@ -73,6 +73,16 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbSanitize" /> app:layout_constraintTop_toBottomOf="@id/cbSanitize" />
<TextView
android:id="@+id/tvHost"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="example.org"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="?android:textColorPrimary"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvOwnerTitle" />
<TextView <TextView
android:id="@+id/tvOwner" android:id="@+id/tvOwner"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -80,12 +90,13 @@
android:labelFor="@+id/etLink" android:labelFor="@+id/etLink"
android:text="Cloudflare" android:text="Cloudflare"
android:textAppearance="@style/TextAppearance.AppCompat.Medium" android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textColor="?android:textColorPrimary"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvOwnerTitle" /> app:layout_constraintTop_toBottomOf="@id/tvHost" />
<androidx.constraintlayout.widget.Group <androidx.constraintlayout.widget.Group
android:id="@+id/grpOwner" android:id="@+id/grpOwner"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="0dp" android:layout_height="0dp"
app:constraint_referenced_ids="tvOwnerTitle,tvOwner" /> app:constraint_referenced_ids="tvOwnerTitle,tvHost,tvOwner" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
Loading…
Cancel
Save