Warn for insecure links

pull/152/head
M66B 7 years ago
parent d8c81668b5
commit 0e2b1ef865

@ -1601,7 +1601,11 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
} else { } else {
View view = LayoutInflater.from(context).inflate(R.layout.dialog_link, null); View view = LayoutInflater.from(context).inflate(R.layout.dialog_link, null);
final EditText etLink = view.findViewById(R.id.etLink); final EditText etLink = view.findViewById(R.id.etLink);
TextView tvInsecure = view.findViewById(R.id.tvInsecure);
etLink.setText(uri.toString()); etLink.setText(uri.toString());
tvInsecure.setVisibility("http".equals(uri.getScheme()) ? View.VISIBLE : View.GONE);
new DialogBuilderLifecycle(context, owner) new DialogBuilderLifecycle(context, owner)
.setView(view) .setView(view)
.setPositiveButton(R.string.title_yes, new DialogInterface.OnClickListener() { .setPositiveButton(R.string.title_yes, new DialogInterface.OnClickListener() {

@ -55,6 +55,7 @@ import android.text.SpannableString;
import android.text.SpannableStringBuilder; import android.text.SpannableStringBuilder;
import android.text.Spanned; import android.text.Spanned;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.style.ImageSpan; import android.text.style.ImageSpan;
import android.text.style.QuoteSpan; import android.text.style.QuoteSpan;
import android.text.style.StyleSpan; import android.text.style.StyleSpan;
@ -770,31 +771,44 @@ public class FragmentCompose extends FragmentBase {
} }
private void onMenuStyle(int id) { private void onMenuStyle(int id) {
int start = etBody.getSelectionStart(); int s = etBody.getSelectionStart();
int end = etBody.getSelectionEnd(); int e = etBody.getSelectionEnd();
if (start > end) {
int tmp = start; if (s < 0)
start = end; s = 0;
end = tmp; if (e < 0)
e = 0;
if (s > e) {
int tmp = s;
s = e;
e = tmp;
} }
if (start == end)
Snackbar.make(view, R.string.title_no_selection, Snackbar.LENGTH_LONG).show(); final int start = s;
else { final int end = e;
final SpannableString s = new SpannableString(etBody.getText());
final SpannableString ss = new SpannableString(etBody.getText());
switch (id) { switch (id) {
case R.id.menu_bold: case R.id.menu_bold:
s.setSpan(new StyleSpan(Typeface.BOLD), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); if (start == end)
Snackbar.make(view, R.string.title_no_selection, Snackbar.LENGTH_LONG).show();
else
ss.setSpan(new StyleSpan(Typeface.BOLD), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
break; break;
case R.id.menu_italic: case R.id.menu_italic:
s.setSpan(new StyleSpan(Typeface.ITALIC), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); if (start == end)
Snackbar.make(view, R.string.title_no_selection, Snackbar.LENGTH_LONG).show();
else
ss.setSpan(new StyleSpan(Typeface.ITALIC), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
break; break;
case R.id.menu_clear: case R.id.menu_clear:
for (Object span : s.getSpans(start, end, Object.class)) for (Object span : ss.getSpans(0, ss.length(), Object.class))
if (!(span instanceof ImageSpan)) if (!(span instanceof ImageSpan))
s.removeSpan(span); ss.removeSpan(span);
break; break;
case R.id.menu_link: case R.id.menu_link:
@ -809,18 +823,35 @@ public class FragmentCompose extends FragmentBase {
} }
View view = LayoutInflater.from(getContext()).inflate(R.layout.dialog_link, null); View view = LayoutInflater.from(getContext()).inflate(R.layout.dialog_link, null);
final int fStart = start;
final int fEnd = end;
final EditText etLink = view.findViewById(R.id.etLink); final EditText etLink = view.findViewById(R.id.etLink);
final TextView tvInsecure = view.findViewById(R.id.tvInsecure);
etLink.setText(uri == null ? "https://" : uri.toString()); etLink.setText(uri == null ? "https://" : uri.toString());
tvInsecure.setVisibility(View.GONE);
etLink.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
tvInsecure.setVisibility("http".equals(Uri.parse(s.toString()).getScheme()) ? View.VISIBLE : View.GONE);
}
@Override
public void afterTextChanged(Editable s) {
}
});
new DialogBuilderLifecycle(getContext(), getViewLifecycleOwner()) new DialogBuilderLifecycle(getContext(), getViewLifecycleOwner())
.setView(view) .setView(view)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
s.setSpan(new URLSpan(etLink.getText().toString()), fStart, fEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); ss.setSpan(new URLSpan(etLink.getText().toString()), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
etBody.setText(s); etBody.setText(ss);
etBody.setSelection(fEnd); etBody.setSelection(end);
} }
}) })
.show(); .show();
@ -834,10 +865,9 @@ public class FragmentCompose extends FragmentBase {
return; return;
} }
etBody.setText(s); etBody.setText(ss);
etBody.setSelection(end); etBody.setSelection(end);
} }
}
private void onMenuSendAfter() { private void onMenuSendAfter() {
DialogDuration.show(getContext(), getViewLifecycleOwner(), R.string.title_send_at, DialogDuration.show(getContext(), getViewLifecycleOwner(), R.string.title_send_at,

@ -25,4 +25,17 @@
android:textAppearance="@style/TextAppearance.AppCompat.Small" android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvOpenLink" /> app:layout_constraintTop_toBottomOf="@id/tvOpenLink" />
<TextView
android:id="@+id/tvInsecure"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_insecure_link"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="?attr/colorWarning"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etLink" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

@ -517,6 +517,7 @@
<string name="title_hint_sync">Downloading messages can take some time, depending on the speed of the provider, internet connection and device and on the number of messages. While downloading messages the app might respond slower.</string> <string name="title_hint_sync">Downloading messages can take some time, depending on the speed of the provider, internet connection and device and on the number of messages. While downloading messages the app might respond slower.</string>
<string name="title_open_link">Open link</string> <string name="title_open_link">Open link</string>
<string name="title_insecure_link">This link is insecure</string>
<string name="title_select_app">Select app</string> <string name="title_select_app">Select app</string>
<string name="title_updated">There is an update to version %1$s available</string> <string name="title_updated">There is an update to version %1$s available</string>
<string name="title_issue">Do you have a question or problem?</string> <string name="title_issue">Do you have a question or problem?</string>

Loading…
Cancel
Save