From 613d0d50798bbec97cf832e02105dc6374fc8fe4 Mon Sep 17 00:00:00 2001 From: xtaodada Date: Mon, 29 Jan 2024 14:31:13 +0800 Subject: [PATCH] feat: Copy Photo As Sticker Co-authored-by: arsLan4k1390 <65973611+arsLan4k1390@users.noreply.github.com> --- .../java/org/telegram/ui/ChatActivity.java | 21 +++++++- .../nextalone/nagram/helper/MessageHelper.kt | 54 ++++++++++++++++++- .../src/main/res/values-zh-rCN/strings_na.xml | 1 + .../src/main/res/values/strings_na.xml | 1 + 4 files changed, 73 insertions(+), 4 deletions(-) diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java index 47613ae019..367011c15c 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java @@ -1028,6 +1028,7 @@ public void run() { private final static int OPTION_SPEED_PROMO = 103; private final static int OPTION_OPEN_PROFILE = 104; private final static int OPTION_COPY_PHOTO = 150; + private final static int OPTION_COPY_PHOTO_AS_STICKER = 151; private final static int[] allowedNotificationsDuringChatListAnimations = new int[]{ NotificationCenter.messagesRead, @@ -26140,7 +26141,11 @@ public void setAutoDeleteHistory(int time, int action) { items.add(LocaleController.getString("CopyPhoto", R.string.CopyPhoto)); options.add(OPTION_COPY_PHOTO); icons.add(R.drawable.msg_copy); - } } + items.add(LocaleController.getString("CopyPhotoAsSticker", R.string.CopyPhotoAsSticker)); + options.add(OPTION_COPY_PHOTO_AS_STICKER); + icons.add(R.drawable.msg_copy); + } + } } } } else if (type == 5) { @@ -26508,7 +26513,11 @@ public void setAutoDeleteHistory(int time, int action) { items.add(LocaleController.getString("CopyPhoto", R.string.CopyPhoto)); options.add(OPTION_COPY_PHOTO); icons.add(R.drawable.msg_copy); - }} + items.add(LocaleController.getString("CopyPhotoAsSticker", R.string.CopyPhotoAsSticker)); + options.add(OPTION_COPY_PHOTO_AS_STICKER); + icons.add(R.drawable.msg_copy); + } + } } else if (type == 5) { items.add(LocaleController.getString("ApplyLocalizationFile", R.string.ApplyLocalizationFile)); options.add(OPTION_APPLY_LOCALIZATION_OR_THEME); @@ -28968,6 +28977,14 @@ private void processSelectedOption(int option) { }); break; } + case OPTION_COPY_PHOTO_AS_STICKER:{ + MessageHelper.INSTANCE.addMessageToClipboardAsSticker(selectedObject, () -> { + if (BulletinFactory.canShowBulletin(ChatActivity.this)) { + BulletinFactory.of(this).createCopyBulletin(LocaleController.getString("PhotoCopied", R.string.PhotoCopied)).show(); + } + }); + break; + } case OPTION_HIDE_SPONSORED_MESSAGE: { MessageObject message = selectedObject; showDialog(new PremiumFeatureBottomSheet(ChatActivity.this, PremiumPreviewFragment.PREMIUM_FEATURE_ADS, true)); diff --git a/TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/helper/MessageHelper.kt b/TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/helper/MessageHelper.kt index eafee6fa1d..223a4e297a 100644 --- a/TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/helper/MessageHelper.kt +++ b/TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/helper/MessageHelper.kt @@ -3,13 +3,37 @@ package xyz.nextalone.nagram.helper import android.content.ClipData import android.content.ClipboardManager import android.content.Context +import android.graphics.Bitmap +import android.graphics.BitmapFactory +import android.os.Build import android.text.TextUtils import androidx.core.content.FileProvider -import org.telegram.messenger.* -import org.telegram.tgnet.TLRPC.* +import org.telegram.messenger.AndroidUtilities +import org.telegram.messenger.ApplicationLoader +import org.telegram.messenger.BuildConfig +import org.telegram.messenger.ChatObject +import org.telegram.messenger.DialogObject +import org.telegram.messenger.Emoji +import org.telegram.messenger.FileLoader +import org.telegram.messenger.FileLog +import org.telegram.messenger.LocaleController +import org.telegram.messenger.MediaDataController +import org.telegram.messenger.MessageObject +import org.telegram.messenger.UserConfig +import org.telegram.tgnet.TLRPC.Chat +import org.telegram.tgnet.TLRPC.TL_messageEntityBankCard +import org.telegram.tgnet.TLRPC.TL_messageEntityBotCommand +import org.telegram.tgnet.TLRPC.TL_messageEntityCashtag +import org.telegram.tgnet.TLRPC.TL_messageEntityEmail +import org.telegram.tgnet.TLRPC.TL_messageEntityHashtag +import org.telegram.tgnet.TLRPC.TL_messageEntityMention +import org.telegram.tgnet.TLRPC.TL_messageEntityPhone +import org.telegram.tgnet.TLRPC.TL_messageEntityUrl +import org.telegram.tgnet.TLRPC.TL_messageMediaPoll import org.telegram.ui.ChatActivity import xyz.nextalone.nagram.NaConfig import java.io.File +import java.io.FileOutputStream object MessageHelper { @@ -54,6 +78,32 @@ object MessageHelper { } } + fun addMessageToClipboardAsSticker(selectedObject: MessageObject, callback: Runnable) { + val file = getPathToMessage(selectedObject) + try { + if (file != null) { + val path = file.path + val image = BitmapFactory.decodeFile(path) + if (image != null && !TextUtils.isEmpty(path)) { + val file2 = File( + if (path.endsWith(".jpg")) path.replace( + ".jpg", + ".webp" + ) else "$path.webp" + ) + val stream = FileOutputStream(file2) + if (Build.VERSION.SDK_INT >= 30) { + image.compress(Bitmap.CompressFormat.WEBP_LOSSLESS, 100, stream) + } else { + image.compress(Bitmap.CompressFormat.WEBP, 100, stream) + } + stream.close() + addFileToClipboard(file2, callback) + } + } + } catch (ignored: java.lang.Exception) { + } + } fun addFileToClipboard(file: File?, callback: Runnable) { try { diff --git a/TMessagesProj/src/main/res/values-zh-rCN/strings_na.xml b/TMessagesProj/src/main/res/values-zh-rCN/strings_na.xml index 46181258e5..90939482f0 100644 --- a/TMessagesProj/src/main/res/values-zh-rCN/strings_na.xml +++ b/TMessagesProj/src/main/res/values-zh-rCN/strings_na.xml @@ -94,4 +94,5 @@ 显示方形头像 禁用私聊的自定义背景 禁用频道的自定义背景 + 复制图片但是贴纸 diff --git a/TMessagesProj/src/main/res/values/strings_na.xml b/TMessagesProj/src/main/res/values/strings_na.xml index efcb79f01a..bccc8a1f7e 100644 --- a/TMessagesProj/src/main/res/values/strings_na.xml +++ b/TMessagesProj/src/main/res/values/strings_na.xml @@ -97,4 +97,5 @@ Show square avatar Disable user custom wallpaper Disable channel custom wallpaper + Copy Photo As Sticker