Skip to content

Commit

Permalink
feat: Copy Photo As Sticker
Browse files Browse the repository at this point in the history
Co-authored-by: arsLan4k1390 <[email protected]>
  • Loading branch information
2 people authored and LiuYi0526 committed Jan 29, 2024
1 parent df602bc commit d6192f8
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 4 deletions.
21 changes: 19 additions & 2 deletions TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions TMessagesProj/src/main/res/values-zh-rCN/strings_na.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,5 @@
<string name="ShowSquareAvatar">显示方形头像</string>
<string name="DisableCustomWallpaperUser">禁用私聊的自定义背景</string>
<string name="DisableCustomWallpaperChannel">禁用频道的自定义背景</string>
<string name="CopyPhotoAsSticker">复制图片但是贴纸</string>
</resources>
1 change: 1 addition & 0 deletions TMessagesProj/src/main/res/values/strings_na.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,5 @@
<string name="ShowSquareAvatar">Show square avatar</string>
<string name="DisableCustomWallpaperUser">Disable user custom wallpaper</string>
<string name="DisableCustomWallpaperChannel">Disable channel custom wallpaper</string>
<string name="CopyPhotoAsSticker">Copy Photo As Sticker</string>
</resources>

0 comments on commit d6192f8

Please sign in to comment.