Skip to content

Commit

Permalink
Merge pull request deltachat#3374 from deltachat/adb/use-createQrSvg
Browse files Browse the repository at this point in the history
Allow to share proxy via QR
  • Loading branch information
adbenitez authored Oct 23, 2024
2 parents 5a2c28b + cfd9371 commit 6c482af
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 6 deletions.
10 changes: 10 additions & 0 deletions jni/dc_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,16 @@ JNIEXPORT jstring Java_com_b44t_messenger_DcContext_getSecurejoinQrSvg(JNIEnv *e
return ret;
}

JNIEXPORT jstring Java_com_b44t_messenger_DcContext_createQrSvg(JNIEnv *env, jobject obj, jstring payload)
{
CHAR_REF(payload);
char* temp = dc_create_qr_svg(payloadPtr);
jstring ret = JSTRING_NEW(temp);
dc_str_unref(temp);
CHAR_UNREF(payload);
return ret;
}

JNIEXPORT jint Java_com_b44t_messenger_DcContext_joinSecurejoin(JNIEnv *env, jobject obj, jstring qr)
{
CHAR_REF(qr);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/b44t/messenger/DcContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ protected void finalize() throws Throwable {
public DcLot checkQr (String qr) { return new DcLot(checkQrCPtr(qr)); }
public native String getSecurejoinQr (int chat_id);
public native String getSecurejoinQrSvg (int chat_id);
public native String createQrSvg (String payload);
public native int joinSecurejoin (String qr);
public native void sendLocationsToChat (int chat_id, int seconds);
public native boolean isSendingLocationsToChat(int chat_id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
import com.b44t.messenger.DcContext;
import com.b44t.messenger.DcEvent;
import com.b44t.messenger.DcLot;
import com.caverock.androidsvg.SVG;
import com.caverock.androidsvg.SVGImageView;
import com.caverock.androidsvg.SVGParseException;

import org.thoughtcrime.securesms.BaseActionBarActivity;
import org.thoughtcrime.securesms.R;
Expand Down Expand Up @@ -115,10 +118,25 @@ public void onItemClick(String proxyUrl) {

@Override
public void onItemShare(String proxyUrl) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, proxyUrl);
startActivity(Intent.createChooser(intent, getString(R.string.chat_share_with_title)));
View view = View.inflate(this, R.layout.dialog_share_proxy, null);
SVGImageView qrImage = view.findViewById(R.id.qr_image);
try {
SVG svg = SVG.getFromString(DcHelper.getContext(this).createQrSvg(proxyUrl));
qrImage.setSVG(svg);
} catch (SVGParseException e) {
e.printStackTrace();
}

AlertDialog dialog = new AlertDialog.Builder(this)
.setView(view)
.setPositiveButton(android.R.string.ok, null)
.setNeutralButton(R.string.proxy_share_link, (dlg, btn) -> {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, proxyUrl);
startActivity(Intent.createChooser(intent, getString(R.string.chat_share_with_title)));
})
.show();
}

@Override
Expand Down
28 changes: 28 additions & 0 deletions src/main/res/layout/dialog_share_proxy.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingBottom="10dp"
android:orientation="vertical"
>

<com.caverock.androidsvg.SVGImageView
android:id="@+id/qr_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="16dp"
android:contentDescription="@string/qrscan_title"
/>

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:text="@string/proxy_share_explain"
/>

</LinearLayout>
6 changes: 4 additions & 2 deletions src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -621,12 +621,14 @@
<string name="proxy_use_proxy">Use Proxy</string>
<string name="proxy_add">Add Proxy</string>
<string name="proxy_add_explain">Supported proxy types: HTTP(S), SOCKS5 and Shadowsocks.</string>
<string name="proxy_add_url_hint">Enter proxy URL here</string>
<string name="proxy_invalid">Invalid or unsupported proxy URL</string>
<string name="proxy_add_url_hint">Enter proxy link here</string>
<string name="proxy_invalid">Invalid or unsupported proxy</string>
<string name="proxy_list_header">Saved Proxies</string>
<string name="proxy_delete">Delete Proxy</string>
<string name="proxy_delete_explain">Are you sure you want to delete \"%1$s\"?</string>
<string name="proxy_use_proxy_confirm">Do you want to use proxy \"%1$s\"?</string>
<string name="proxy_share_explain">Your friends can add this proxy by scanning the QR code.</string>
<string name="proxy_share_link">Share Link</string>

<!-- deprecated -->
<string name="login_socks5">SOCKS5</string>
Expand Down

0 comments on commit 6c482af

Please sign in to comment.