Skip to content

Commit

Permalink
fix: Long Press Link Menu in ChatActivity
Browse files Browse the repository at this point in the history
  • Loading branch information
omg-xtao committed Jul 14, 2024
1 parent 533950b commit f3bbfb3
Showing 1 changed file with 78 additions and 26 deletions.
104 changes: 78 additions & 26 deletions TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -34083,16 +34083,23 @@ private void openClickableLink(CharacterStyle url, String str, boolean longPress
}
final int finalTimestamp = timestamp;
// boolean noforwards = getMessagesController().isChatNoForwards(currentChat) || (messageObject != null && messageObject.messageOwner != null && messageObject.messageOwner.noforwards);
boolean noforwards = false;
builder.setItems(noforwards ? new CharSequence[] {LocaleController.getString("Open", R.string.Open)} : new CharSequence[]{LocaleController.getString("Open", R.string.Open), LocaleController.getString("Copy", R.string.Copy)}, (dialog, which) -> {
CharSequence[] items = new CharSequence[]{
LocaleController.getString("Open", R.string.Open),
LocaleController.getString("Copy", R.string.Copy),
LocaleController.getString("ShareQRCode", R.string.ShareQRCode),
LocaleController.getString("ShareMessages", R.string.ShareMessages)
};
// builder.setItems(noforwards ? new CharSequence[] {LocaleController.getString("Open", R.string.Open)} : new CharSequence[]{LocaleController.getString("Open", R.string.Open), LocaleController.getString("Copy", R.string.Copy)}, (dialog, which) -> {
builder.setItems(items, (dialog, which) -> {
if (which == 0) {
if (str.startsWith("video?")) {
didPressMessageUrl(url, false, messageObject, cell);
} else {
logSponsoredClicked(messageObject);
openClickableLink(url, str, false, cell, messageObject, true);
}
} else if (which == 1) {
} else if (which == 1 || which == 3) {
String urlFinal = str;
if (str.startsWith("video?") && messageObject != null && !messageObject.scheduled) {
MessageObject messageObject1 = messageObject;
boolean isMedia = messageObject.isVideo() || messageObject.isRoundVideo() || messageObject.isVoice() || messageObject.isMusic();
Expand Down Expand Up @@ -34129,21 +34136,36 @@ private void openClickableLink(CharacterStyle url, String str, boolean longPress
if (link == null) {
return;
}
AndroidUtilities.addToClipboard(link);
urlFinal = link;
// AndroidUtilities.addToClipboard(link);
} else {
AndroidUtilities.addToClipboard(str);
// AndroidUtilities.addToClipboard(str);
}
createUndoView();
if (undoView == null) {
return;
}
if (str.startsWith("@")) {
undoView.showWithAction(0, UndoView.ACTION_USERNAME_COPIED, null);
} else if (str.startsWith("#") || str.startsWith("$")) {
undoView.showWithAction(0, UndoView.ACTION_HASHTAG_COPIED, null);
if (which == 1) {
AndroidUtilities.addToClipboard(urlFinal);
createUndoView();
if (undoView == null) {
return;
}
if (str.startsWith("@")) {
undoView.showWithAction(0, UndoView.ACTION_USERNAME_COPIED, null);
} else if (str.startsWith("#") || str.startsWith("$")) {
undoView.showWithAction(0, UndoView.ACTION_HASHTAG_COPIED, null);
} else {
undoView.showWithAction(0, UndoView.ACTION_LINK_COPIED, null);
}
} else {
undoView.showWithAction(0, UndoView.ACTION_LINK_COPIED, null);
// ShareMessage
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT, urlFinal);
Intent chooserIntent = Intent.createChooser(shareIntent, LocaleController.getString("ShareFile", R.string.ShareFile));
chooserIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ApplicationLoader.applicationContext.startActivity(chooserIntent);
}
} else if (which == 2) {
// QRCode
ProxyUtil.showQrDialog(getParentActivity(), str);
}
});
builder.setOnPreDismissListener(di -> {
Expand Down Expand Up @@ -41640,6 +41662,10 @@ public void showPremiumFloodWaitBulletin(final boolean isUpload) {
).setDuration(8000).show(true);
}

interface NagramCopyMesage {
void run(boolean isCopy);
}

public void didLongPressLink(ChatMessageCell cell, MessageObject messageObject, CharacterStyle span, String str) {
final ItemOptions options = ItemOptions.makeOptions(ChatActivity.this, cell, true);
final ScrimOptions dialog = new ScrimOptions(getContext(), themeDelegate);
Expand All @@ -41664,7 +41690,8 @@ public void didLongPressLink(ChatMessageCell cell, MessageObject messageObject,
});
}

options.add(R.drawable.msg_copy, getString(R.string.CopyLink), () -> {
NagramCopyMesage run1 = (boolean isCopy) -> {
String urlFinal = str;
if (str.startsWith("video?") && messageObject != null && !messageObject.scheduled) {
MessageObject messageObject1 = messageObject;
boolean isMedia = messageObject.isVideo() || messageObject.isRoundVideo() || messageObject.isVoice() || messageObject.isMusic();
Expand Down Expand Up @@ -41704,22 +41731,47 @@ public void didLongPressLink(ChatMessageCell cell, MessageObject messageObject,
if (link == null) {
return;
}
AndroidUtilities.addToClipboard(link);
urlFinal = link;
// AndroidUtilities.addToClipboard(link);
} else {
AndroidUtilities.addToClipboard(str);
// AndroidUtilities.addToClipboard(str);
}
createUndoView();
if (undoView == null) {
return;
}
if (str.startsWith("@")) {
undoView.showWithAction(0, UndoView.ACTION_USERNAME_COPIED, null);
} else if (str.startsWith("#") || str.startsWith("$")) {
undoView.showWithAction(0, UndoView.ACTION_HASHTAG_COPIED, null);
if (isCopy) {
AndroidUtilities.addToClipboard(urlFinal);
createUndoView();
if (undoView == null) {
return;
}
if (str.startsWith("@")) {
undoView.showWithAction(0, UndoView.ACTION_USERNAME_COPIED, null);
} else if (str.startsWith("#") || str.startsWith("$")) {
undoView.showWithAction(0, UndoView.ACTION_HASHTAG_COPIED, null);
} else {
undoView.showWithAction(0, UndoView.ACTION_LINK_COPIED, null);
}
} else {
undoView.showWithAction(0, UndoView.ACTION_LINK_COPIED, null);
// ShareMessage
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT, urlFinal);
Intent chooserIntent = Intent.createChooser(shareIntent, LocaleController.getString("ShareFile", R.string.ShareFile));
chooserIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ApplicationLoader.applicationContext.startActivity(chooserIntent);
}
};
options.add(R.drawable.msg_copy, getString(R.string.CopyLink), () -> {
run1.run(true);
});
// ----- Nagram Hook start -----
options.add(R.drawable.wallet_qr, getString("ShareQRCode", R.string.ShareQRCode), () -> {
// QRCode
ProxyUtil.showQrDialog(getParentActivity(), str);
});
options.add(R.drawable.msg_shareout, getString("ShareMessages", R.string.ShareMessages), () -> {
// ShareMessage
run1.run(false);
});
// ----- Nagram Hook end -----

dialog.setItemOptions(options);
if (span instanceof URLSpanReplacement) {
Expand Down

0 comments on commit f3bbfb3

Please sign in to comment.