mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
copy invite links to clipboard (#2943)
* copy invite links to clipboard * rename INVITE_PAGE to INVITE_DOMAIN * share link together with QR image, improve QR image * share invite-URL instead of QR image * 'Load QR code from image' is no longer a recommended workflow the primary UI works with invite-links now. 'Load QR code from image' is still supported, but is tuned down as no longer recommended workflow. --------- Co-authored-by: B. Petersen <r10s@b44t.com>
This commit is contained in:
committed by
GitHub
parent
9a2968d502
commit
f207251f11
@@ -2,13 +2,12 @@
|
||||
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<item android:title="@string/load_qr_code_as_image"
|
||||
android:id="@+id/load_from_image"
|
||||
android:icon="@drawable/ic_image_white_24dp"
|
||||
app:showAsAction="ifRoom"/>
|
||||
|
||||
<item android:title="@string/paste_from_clipboard"
|
||||
android:id="@+id/paste"
|
||||
app:showAsAction="never"/>
|
||||
|
||||
<item android:title="@string/load_qr_code_as_image"
|
||||
android:id="@+id/load_from_image"
|
||||
app:showAsAction="never"/>
|
||||
|
||||
</menu>
|
||||
|
||||
@@ -82,7 +82,6 @@ public class ConversationListActivity extends PassphraseRequiredActionBarActivit
|
||||
{
|
||||
private static final String TAG = ConversationListActivity.class.getSimpleName();
|
||||
private static final String OPENPGP4FPR = "openpgp4fpr";
|
||||
private static final String INVITE_PAGE = "i.delta.chat";
|
||||
private static final String NDK_ARCH_WARNED = "ndk_arch_warned";
|
||||
public static final String CLEAR_NOTIFICATIONS = "clear_notifications";
|
||||
public static final String ACCOUNT_ID_EXTRA = "account_id";
|
||||
@@ -409,14 +408,9 @@ public class ConversationListActivity extends PassphraseRequiredActionBarActivit
|
||||
return;
|
||||
}
|
||||
|
||||
if (uri.getScheme().equalsIgnoreCase(OPENPGP4FPR)) {
|
||||
String uriString = uri.toString().replaceFirst(OPENPGP4FPR, OPENPGP4FPR.toUpperCase());
|
||||
if (uri.getScheme().equalsIgnoreCase(OPENPGP4FPR) || Util.isInviteURL(uri)) {
|
||||
QrCodeHandler qrCodeHandler = new QrCodeHandler(this);
|
||||
qrCodeHandler.handleQrData(uriString);
|
||||
} else if (INVITE_PAGE.equals(uri.getHost()) && uri.getEncodedFragment() != null) {
|
||||
String data = OPENPGP4FPR.toUpperCase() + ":" + uri.getEncodedFragment().replaceFirst("&", "#");
|
||||
QrCodeHandler qrCodeHandler = new QrCodeHandler(this);
|
||||
qrCodeHandler.handleQrData(data);
|
||||
qrCodeHandler.handleQrData(uri.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ public class QrActivity extends BaseActionBarActivity {
|
||||
finish();
|
||||
return true;
|
||||
case R.id.share:
|
||||
qrShowFragment.shareQr();
|
||||
qrShowFragment.shareInviteURL();
|
||||
break;
|
||||
case R.id.copy:
|
||||
qrShowFragment.copyQrData();
|
||||
|
||||
@@ -87,7 +87,7 @@ public class QrShowActivity extends AppCompatActivity {
|
||||
finish();
|
||||
return true;
|
||||
case R.id.share:
|
||||
fragment.shareQr();
|
||||
fragment.shareInviteURL();
|
||||
break;
|
||||
case R.id.copy:
|
||||
fragment.copyQrData();
|
||||
|
||||
@@ -111,7 +111,7 @@ public class QrShowFragment extends Fragment implements DcEventCenter.DcEventDel
|
||||
FileOutputStream stream = new FileOutputStream(file);
|
||||
Bitmap bitmap = Bitmap.createBitmap(WIDTH, HEIGHT, Bitmap.Config.ARGB_8888);
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
canvas.drawRGB(255, 255, 255); // Clear background to white
|
||||
canvas.drawARGB(0,255, 255, 255); // Clear background to white
|
||||
SVG svg = SVG.getFromString(fixSVG(dcContext.getSecurejoinQrSvg(chatId)));
|
||||
svg.renderToCanvas(canvas);
|
||||
bitmap.compress(Bitmap.CompressFormat.PNG, 90, stream);
|
||||
@@ -121,6 +121,8 @@ public class QrShowFragment extends Fragment implements DcEventCenter.DcEventDel
|
||||
Intent intent = new Intent(Intent.ACTION_SEND);
|
||||
intent.setType("image/png");
|
||||
intent.putExtra(Intent.EXTRA_STREAM, uri);
|
||||
String inviteURL = Util.QrDataToInviteURL(dcContext.getSecurejoinQr(chatId));
|
||||
intent.putExtra(Intent.EXTRA_TEXT, inviteURL);
|
||||
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
startActivity(Intent.createChooser(intent, getString(R.string.chat_share_with_title)));
|
||||
} catch (Exception e) {
|
||||
@@ -128,8 +130,21 @@ public class QrShowFragment extends Fragment implements DcEventCenter.DcEventDel
|
||||
}
|
||||
}
|
||||
|
||||
public void shareInviteURL() {
|
||||
try {
|
||||
Intent intent = new Intent(Intent.ACTION_SEND);
|
||||
intent.setType("text/plain");
|
||||
String inviteURL = Util.QrDataToInviteURL(dcContext.getSecurejoinQr(chatId));
|
||||
intent.putExtra(Intent.EXTRA_TEXT, inviteURL);
|
||||
startActivity(Intent.createChooser(intent, getString(R.string.chat_share_with_title)));
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "failed to share invite URL", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void copyQrData() {
|
||||
Util.writeTextToClipboard(getActivity(), DcHelper.getContext(getActivity()).getSecurejoinQr(chatId));
|
||||
String inviteURL = Util.QrDataToInviteURL(dcContext.getSecurejoinQr(chatId));
|
||||
Util.writeTextToClipboard(getActivity(), inviteURL);
|
||||
Toast.makeText(getActivity(), getString(R.string.copied_to_clipboard), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import android.content.ClipDescription;
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Typeface;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build.VERSION;
|
||||
import android.os.Build.VERSION_CODES;
|
||||
@@ -56,6 +57,7 @@ import java.util.concurrent.CountDownLatch;
|
||||
|
||||
public class Util {
|
||||
private static final String TAG = Util.class.getSimpleName();
|
||||
private static final String INVITE_DOMAIN = "i.delta.chat";
|
||||
|
||||
public static final Handler handler = new Handler(Looper.getMainLooper());
|
||||
|
||||
@@ -63,6 +65,14 @@ public class Util {
|
||||
return value == null || value.getText() == null || TextUtils.isEmpty(value.getTextTrimmed());
|
||||
}
|
||||
|
||||
public static boolean isInviteURL(Uri uri) {
|
||||
return INVITE_DOMAIN.equals(uri.getHost());
|
||||
}
|
||||
|
||||
public static String QrDataToInviteURL(String qrData) {
|
||||
return "https://" + INVITE_DOMAIN + "/#" + qrData.split(":", 2)[1].replaceFirst("#", "&");
|
||||
}
|
||||
|
||||
public static CharSequence getBoldedString(String value) {
|
||||
SpannableString spanned = new SpannableString(value);
|
||||
spanned.setSpan(new StyleSpan(Typeface.BOLD), 0,
|
||||
|
||||
Reference in New Issue
Block a user