Behavior improvement

pull/184/head
M66B 4 years ago
parent 4a20ca9c06
commit ceea8cd1f8

@ -5870,17 +5870,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
return; return;
Uri uri = Uri.parse(etLink.getText().toString()); Uri uri = Uri.parse(etLink.getText().toString());
Uri.Builder builder = uri.buildUpon(); etLink.setText(secure(uri, checked).toString());
builder.scheme(checked ? "https" : "http");
String authority = uri.getEncodedAuthority();
if (authority != null) {
authority = authority.replace(checked ? ":80" : ":443", checked ? ":443" : ":80");
builder.encodedAuthority(authority);
}
etLink.setText(builder.build().toString());
} }
}); });
@ -5889,10 +5879,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
cbSanitize.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { cbSanitize.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
if (checked) etLink.setText(secure(checked ? sanitized : uri, cbSecure.isChecked()).toString());
etLink.setText(sanitized.toString());
else
etLink.setText(uri.toString());
} }
}); });
@ -6065,6 +6052,23 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
return (changed ? builder.build() : null); return (changed ? builder.build() : null);
} }
private static Uri secure(Uri uri, boolean https) {
String scheme = uri.getScheme();
if (https ? "http".equals(scheme) : "https".equals(scheme)) {
Uri.Builder builder = uri.buildUpon();
builder.scheme(https ? "https" : "http");
String authority = uri.getEncodedAuthority();
if (authority != null) {
authority = authority.replace(https ? ":80" : ":443", https ? ":443" : ":80");
builder.encodedAuthority(authority);
}
return builder.build();
} else
return uri;
}
} }
public static class FragmentDialogJunk extends FragmentDialogBase { public static class FragmentDialogJunk extends FragmentDialogBase {

Loading…
Cancel
Save