mirror of
https://github.com/deltachat/deltachat-android.git
synced 2025-10-05 10:39:24 +02:00
register app for opening ss:// and socks5:// proxy URLs
also linkify proxy URLs in text messages
This commit is contained in:
parent
6f3d8a4414
commit
8487c286e6
4 changed files with 66 additions and 2 deletions
|
@ -252,7 +252,22 @@
|
|||
<activity android:name=".proxy.ProxySettingsActivity"
|
||||
android:label="@string/proxy_settings"
|
||||
android:windowSoftInputMode="stateHidden"
|
||||
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize"/>
|
||||
android:exported="true"
|
||||
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize">
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW"/>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
<category android:name="android.intent.category.BROWSABLE"/>
|
||||
<!-- Android's scheme matcher is case-sensitive, so include most likely variations -->
|
||||
<data android:scheme="ss" />
|
||||
<data android:scheme="socks5" />
|
||||
<data android:scheme="SOCKS5" tools:ignore="AppLinkUrlError" />
|
||||
<data android:scheme="SS" tools:ignore="AppLinkUrlError" />
|
||||
</intent-filter>
|
||||
|
||||
</activity>
|
||||
|
||||
|
||||
<activity android:name=".LogViewActivity"
|
||||
android:label="@string/pref_log_header"
|
||||
|
|
|
@ -213,6 +213,7 @@ public class EmojiTextView extends AppCompatTextView {
|
|||
// tools for linkify
|
||||
|
||||
private static final Pattern CMD_PATTERN = Pattern.compile("(?<=^|\\s)/[a-zA-Z][a-zA-Z@\\d_/.-]{0,254}");
|
||||
private static final Pattern PROXY_PATTERN = Pattern.compile("(?<=^|\\s)(SOCKS5|socks5|ss|SS):[^ \\n]+");
|
||||
|
||||
private static void replaceURLSpan(SpannableString messageBody) {
|
||||
URLSpan[] urlSpans = messageBody.getSpans(0, messageBody.length(), URLSpan.class);
|
||||
|
@ -231,6 +232,10 @@ public class EmojiTextView extends AppCompatTextView {
|
|||
EmojiTextView.replaceURLSpan(messageBody); // replace URLSpan so that it is not removed on the next addLinks() call
|
||||
}
|
||||
|
||||
if (Linkify.addLinks(messageBody, PROXY_PATTERN, null, null, null)) {
|
||||
EmojiTextView.replaceURLSpan(messageBody); // replace URLSpan so that it is not removed on the next addLinks() call
|
||||
}
|
||||
|
||||
// linkyfiy urls etc., this removes all existing URLSpan
|
||||
if (Linkify.addLinks(messageBody, Linkify.EMAIL_ADDRESSES|Linkify.WEB_URLS|Linkify.PHONE_NUMBERS)) {
|
||||
EmojiTextView.replaceURLSpan(messageBody);
|
||||
|
|
|
@ -4,6 +4,7 @@ import static org.thoughtcrime.securesms.connect.DcHelper.CONFIG_PROXY_ENABLED;
|
|||
import static org.thoughtcrime.securesms.connect.DcHelper.CONFIG_PROXY_URL;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
|
@ -70,6 +71,14 @@ public class ProxySettingsActivity extends BaseActionBarActivity
|
|||
proxyList.addFooterView(footer);
|
||||
adapter.changeData(DcHelper.get(this, CONFIG_PROXY_URL));
|
||||
DcHelper.getEventCenter(this).addObserver(DcContext.DC_EVENT_CONNECTIVITY_CHANGED, this);
|
||||
|
||||
handleOpenProxyUrl();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
super.onNewIntent(intent);
|
||||
handleOpenProxyUrl();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -173,6 +182,34 @@ public class ProxySettingsActivity extends BaseActionBarActivity
|
|||
.show();
|
||||
}
|
||||
|
||||
private void handleOpenProxyUrl() {
|
||||
if (getIntent() != null && Intent.ACTION_VIEW.equals(getIntent().getAction())) {
|
||||
Uri uri = getIntent().getData();
|
||||
if (uri == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
DcContext dcContext = DcHelper.getContext(this);
|
||||
final DcLot qrParsed = dcContext.checkQr(uri.toString());
|
||||
if (qrParsed.getState() == DcContext.DC_QR_PROXY) {
|
||||
new AlertDialog.Builder(this)
|
||||
.setTitle(R.string.proxy_use_proxy)
|
||||
.setMessage(getString(R.string.proxy_use_proxy_confirm, qrParsed.getText1()))
|
||||
.setPositiveButton(R.string.proxy_use_proxy, (dlg, btn) -> {
|
||||
dcContext.setConfigFromQr(uri.toString());
|
||||
dcContext.restartIo();
|
||||
adapter.changeData(DcHelper.get(this, CONFIG_PROXY_URL));
|
||||
proxySwitch.setChecked(DcHelper.getInt(this, CONFIG_PROXY_ENABLED) == 1);
|
||||
})
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.setCancelable(false)
|
||||
.show();
|
||||
} else {
|
||||
Toast.makeText(this, R.string.proxy_invalid, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleEvent(@NonNull DcEvent event) {
|
||||
if (event.getId() == DcContext.DC_EVENT_CONNECTIVITY_CHANGED) {
|
||||
|
|
|
@ -81,7 +81,14 @@ public class LongClickCopySpan extends ClickableSpan {
|
|||
QrCodeHandler qrCodeHandler = new QrCodeHandler((Activity) widget.getContext());
|
||||
qrCodeHandler.handleQrData(url);
|
||||
} else {
|
||||
IntentUtils.showBrowserIntent(widget.getContext(), url);
|
||||
Activity activity = (Activity) widget.getContext();
|
||||
DcContext dcContext = DcHelper.getContext(activity);
|
||||
if (dcContext.checkQr(url).getState() == DcContext.DC_QR_PROXY) {
|
||||
QrCodeHandler qrCodeHandler = new QrCodeHandler(activity);
|
||||
qrCodeHandler.handleQrData(url);
|
||||
} else {
|
||||
IntentUtils.showBrowserIntent(widget.getContext(), url);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue