Show open link title

This commit is contained in:
M66B 2019-05-18 09:54:01 +02:00
parent eb872b73e2
commit 336dd61470
2 changed files with 29 additions and 6 deletions

View File

@ -1640,7 +1640,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
if ("cid".equals(uri.getScheme()) || "data".equals(uri.getScheme()))
return false;
onOpenLink(uri);
onOpenLink(uri, null);
return true;
}
});
@ -1912,7 +1912,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
if (image.length > 0 && image[0].getSource() != null) {
Uri uri = Uri.parse(image[0].getSource());
if ("http".equals(uri.getScheme()) || "https".equals(uri.getScheme())) {
onOpenLink(uri);
onOpenLink(uri, null);
return true;
}
}
@ -1924,7 +1924,15 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
Uri uri = Uri.parse(url);
if (uri.getScheme() == null)
uri = Uri.parse("https://" + url);
onOpenLink(uri);
int start = buffer.getSpanStart(link[0]);
int end = buffer.getSpanEnd(link[0]);
String title = (start < 0 || end < 0 || end <= start
? null : buffer.subSequence(start, end).toString());
if (url.equals(title))
title = null;
onOpenLink(uri, title);
return true;
}
@ -1945,7 +1953,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
}
}
private void onOpenLink(final Uri uri) {
private void onOpenLink(final Uri uri, String title) {
Log.i("Opening uri=" + uri);
if (BuildConfig.APPLICATION_ID.equals(uri.getHost()) && "/activate/".equals(uri.getPath())) {
@ -1994,11 +2002,15 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
_uri = uri;
View view = LayoutInflater.from(context).inflate(R.layout.dialog_open_link, null);
TextView tvTitle = view.findViewById(R.id.tvTitle);
final EditText etLink = view.findViewById(R.id.etLink);
TextView tvInsecure = view.findViewById(R.id.tvInsecure);
final TextView tvOwner = view.findViewById(R.id.tvOwner);
Group grpOwner = view.findViewById(R.id.grpOwner);
tvTitle.setText(title);
tvTitle.setVisibility(TextUtils.isEmpty(title) ? View.GONE : View.VISIBLE);
etLink.setText(_uri.toString());
tvInsecure.setVisibility("http".equals(_uri.getScheme()) ? View.VISIBLE : View.GONE);
grpOwner.setVisibility(paranoid ? View.VISIBLE : View.GONE);

View File

@ -6,7 +6,7 @@
android:padding="12dp">
<TextView
android:id="@+id/tvOpenLink"
android:id="@+id/tvCaption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:labelFor="@+id/etLink"
@ -17,6 +17,17 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tvTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:labelFor="@+id/etLink"
android:text="Link title"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvCaption" />
<EditText
android:id="@+id/etLink"
android:layout_width="match_parent"
@ -26,7 +37,7 @@
android:text="https://email.faircode.eu/"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvOpenLink" />
app:layout_constraintTop_toBottomOf="@id/tvTitle" />
<TextView
android:id="@+id/tvInsecure"