Allow using title uri

pull/178/head
M66B 5 years ago
parent 395da7feb6
commit 4d186bba67

@ -5229,12 +5229,15 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
sanitized = (changed ? builder.build() : uri); sanitized = (changed ? builder.build() : uri);
} }
final Uri uriTitle = Uri.parse(title == null ? "" : title);
View dview = LayoutInflater.from(getContext()).inflate(R.layout.dialog_open_link, null); View dview = LayoutInflater.from(getContext()).inflate(R.layout.dialog_open_link, null);
TextView tvTitle = dview.findViewById(R.id.tvTitle); TextView tvTitle = dview.findViewById(R.id.tvTitle);
final EditText etLink = dview.findViewById(R.id.etLink);
ImageButton ibShare = dview.findViewById(R.id.ibShare); ImageButton ibShare = dview.findViewById(R.id.ibShare);
ImageButton ibCopy = dview.findViewById(R.id.ibCopy); ImageButton ibCopy = dview.findViewById(R.id.ibCopy);
final EditText etLink = dview.findViewById(R.id.etLink);
TextView tvDifferent = dview.findViewById(R.id.tvDifferent); TextView tvDifferent = dview.findViewById(R.id.tvDifferent);
ImageButton ibDifferent = dview.findViewById(R.id.ibDifferent);
final CheckBox cbSecure = dview.findViewById(R.id.cbSecure); final CheckBox cbSecure = dview.findViewById(R.id.cbSecure);
CheckBox cbSanitize = dview.findViewById(R.id.cbSanitize); CheckBox cbSanitize = dview.findViewById(R.id.cbSanitize);
final Button btnOwner = dview.findViewById(R.id.btnOwner); final Button btnOwner = dview.findViewById(R.id.btnOwner);
@ -5242,33 +5245,9 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
final ContentLoadingProgressBar pbWait = dview.findViewById(R.id.pbWait); final ContentLoadingProgressBar pbWait = dview.findViewById(R.id.pbWait);
final TextView tvHost = dview.findViewById(R.id.tvHost); final TextView tvHost = dview.findViewById(R.id.tvHost);
final TextView tvOwner = dview.findViewById(R.id.tvOwner); final TextView tvOwner = dview.findViewById(R.id.tvOwner);
final Group grpDifferent = dview.findViewById(R.id.grpDifferent);
final Group grpOwner = dview.findViewById(R.id.grpOwner); final Group grpOwner = dview.findViewById(R.id.grpOwner);
ibShare.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent send = new Intent();
send.setAction(Intent.ACTION_SEND);
send.putExtra(Intent.EXTRA_TEXT, uri.toString());
send.setType("text/plain");
startActivity(Intent.createChooser(send, title));
}
});
ibCopy.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ClipboardManager clipboard =
(ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
if (clipboard != null) {
ClipData clip = ClipData.newPlainText(title, uri.toString());
clipboard.setPrimaryClip(clip);
ToastEx.makeText(getContext(), R.string.title_clipboard_copied, Toast.LENGTH_LONG).show();
}
}
});
etLink.addTextChangedListener(new TextWatcher() { etLink.addTextChangedListener(new TextWatcher() {
@Override @Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
@ -5301,6 +5280,38 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
} }
}); });
ibShare.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent send = new Intent();
send.setAction(Intent.ACTION_SEND);
send.putExtra(Intent.EXTRA_TEXT, etLink.getText().toString());
send.setType("text/plain");
startActivity(Intent.createChooser(send, title));
}
});
ibCopy.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ClipboardManager clipboard =
(ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
if (clipboard != null) {
ClipData clip = ClipData.newPlainText(title, etLink.getText().toString());
clipboard.setPrimaryClip(clip);
ToastEx.makeText(getContext(), R.string.title_clipboard_copied, Toast.LENGTH_LONG).show();
}
}
});
ibDifferent.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
etLink.setText(uriTitle.toString());
}
});
cbSecure.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { cbSecure.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@ -5392,8 +5403,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
tvTitle.setVisibility(TextUtils.isEmpty(title) ? View.GONE : View.VISIBLE); tvTitle.setVisibility(TextUtils.isEmpty(title) ? View.GONE : View.VISIBLE);
etLink.setText(uri.toString()); etLink.setText(uri.toString());
Uri uriTitle = Uri.parse(title == null ? "" : title); grpDifferent.setVisibility(uriTitle.getHost() == null || uri.getHost() == null ||
tvDifferent.setVisibility(uriTitle.getHost() == null || uri.getHost() == null ||
uriTitle.getHost().equalsIgnoreCase(uri.getHost()) uriTitle.getHost().equalsIgnoreCase(uri.getHost())
? View.GONE : View.VISIBLE); ? View.GONE : View.VISIBLE);

@ -28,10 +28,23 @@
android:text="Link title" android:text="Link title"
android:textAppearance="@style/TextAppearance.AppCompat.Medium" android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textStyle="italic" android:textStyle="italic"
app:layout_constraintEnd_toStartOf="@+id/ibShare" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvCaption" /> app:layout_constraintTop_toBottomOf="@id/tvCaption" />
<eu.faircode.email.EditTextPlain
android:id="@+id/etLink"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:imeOptions="actionDone"
android:inputType="textUri|textMultiLine"
android:text="https://email.faircode.eu/"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvTitle" />
<ImageButton <ImageButton
android:id="@+id/ibShare" android:id="@+id/ibShare"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -39,8 +52,8 @@
android:layout_marginEnd="12dp" android:layout_marginEnd="12dp"
android:background="?android:attr/selectableItemBackgroundBorderless" android:background="?android:attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/title_share" android:contentDescription="@string/title_share"
app:layout_constraintBottom_toBottomOf="@id/tvTitle"
app:layout_constraintEnd_toStartOf="@+id/ibCopy" app:layout_constraintEnd_toStartOf="@+id/ibCopy"
app:layout_constraintTop_toBottomOf="@id/etLink"
app:srcCompat="@drawable/baseline_share_24" /> app:srcCompat="@drawable/baseline_share_24" />
<ImageButton <ImageButton
@ -49,34 +62,33 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackgroundBorderless" android:background="?android:attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/title_clipboard_copy" android:contentDescription="@string/title_clipboard_copy"
app:layout_constraintBottom_toBottomOf="@id/tvTitle"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/etLink"
app:srcCompat="@drawable/baseline_assignment_24" /> app:srcCompat="@drawable/baseline_assignment_24" />
<eu.faircode.email.EditTextPlain
android:id="@+id/etLink"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:imeOptions="actionDone"
android:inputType="textUri|textMultiLine"
android:text="https://email.faircode.eu/"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvTitle" />
<eu.faircode.email.FixedTextView <eu.faircode.email.FixedTextView
android:id="@+id/tvDifferent" android:id="@+id/tvDifferent"
android:layout_width="wrap_content" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="24dp" android:layout_marginTop="12dp"
android:layout_marginEnd="12dp"
android:text="@string/title_different_link" android:text="@string/title_different_link"
android:textAppearance="@style/TextAppearance.AppCompat.Small" android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="?attr/colorWarning" android:textColor="?attr/colorWarning"
android:textStyle="bold" android:textStyle="bold"
app:layout_constraintEnd_toStartOf="@+id/ibDifferent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etLink" /> app:layout_constraintTop_toBottomOf="@id/ibCopy" />
<ImageButton
android:id="@+id/ibDifferent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/title_clipboard_copy"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@id/tvDifferent"
app:srcCompat="@drawable/baseline_insert_link_24" />
<CheckBox <CheckBox
android:id="@+id/cbSecure" android:id="@+id/cbSecure"
@ -87,7 +99,7 @@
android:textColor="?attr/colorWarning" android:textColor="?attr/colorWarning"
android:textStyle="bold" android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvDifferent" /> app:layout_constraintTop_toBottomOf="@id/ibDifferent" />
<CheckBox <CheckBox
android:id="@+id/cbSanitize" android:id="@+id/cbSanitize"
@ -159,6 +171,12 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvHost" /> app:layout_constraintTop_toBottomOf="@id/tvHost" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpDifferent"
android:layout_width="0dp"
android:layout_height="0dp"
app:constraint_referenced_ids="tvDifferent,ibDifferent" />
<androidx.constraintlayout.widget.Group <androidx.constraintlayout.widget.Group
android:id="@+id/grpOwner" android:id="@+id/grpOwner"
android:layout_width="0dp" android:layout_width="0dp"

Loading…
Cancel
Save