Skip to content

Commit

Permalink
feat: copy sticker as sticker or photo
Browse files Browse the repository at this point in the history
  • Loading branch information
omg-xtao committed Apr 3, 2024
1 parent 22c7aaf commit 83ef19c
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
26 changes: 26 additions & 0 deletions TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java
Expand Up @@ -358,6 +358,8 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
private final static int nkbtn_greatOrPoor = 2027;
private final static int nkbtn_repeatascopy = 2028;
private final static int nkbtn_setReminder = 2029;
private final static int nkbtn_sticker_copy = 2031;
private final static int nkbtn_sticker_copy_png = 2032;


public int shareAlertDebugMode = DEBUG_SHARE_ALERT_MODE_NORMAL;
Expand Down Expand Up @@ -28251,6 +28253,14 @@ public void setAutoDeleteHistory(int time, int action) {
items.add(LocaleController.getString("SaveToGallery", R.string.SaveToGallery));
options.add(nkbtn_stickerdl);
icons.add(R.drawable.msg_gallery);
if (NaConfig.INSTANCE.getShowCopyPhoto().Bool()) {
items.add(LocaleController.getString("CopyPhotoAsSticker", R.string.CopyPhotoAsSticker));
icons.add(R.drawable.msg_copy);
options.add(nkbtn_sticker_copy);
items.add(LocaleController.getString("CopyPhoto", R.string.CopyPhoto));
icons.add(R.drawable.msg_copy);
options.add(nkbtn_sticker_copy_png);
}
}
items.add(LocaleController.getString("AddToStickers", R.string.AddToStickers));
options.add(OPTION_ADD_TO_STICKERS_OR_MASKS);
Expand Down Expand Up @@ -39211,6 +39221,22 @@ private void nkbtn_onclick(int id) {
getMessageHelper().saveStickerToGallery(getParentActivity(), selectedObject);
break;
}
case nkbtn_sticker_copy: {
getMessageHelper().addStickerToClipboard(selectedObject.getDocument(), () -> {
if (BulletinFactory.canShowBulletin(ChatActivity.this)) {
BulletinFactory.of(this).createCopyBulletin(LocaleController.getString("PhotoCopied", R.string.PhotoCopied)).show();
}
});
break;
}
case nkbtn_sticker_copy_png: {
getMessageHelper().addStickerToClipboardAsPNG(selectedObject.getDocument(), () -> {
if (BulletinFactory.canShowBulletin(ChatActivity.this)) {
BulletinFactory.of(this).createCopyBulletin(LocaleController.getString("PhotoCopied", R.string.PhotoCopied)).show();
}
});
break;
}
case nkbtn_translate: {
if (NekoConfig.useTelegramTranslateInChat.Bool() && !selectedObject.isPoll()) {
String toLang = LocaleController.getInstance().getCurrentLocale().getLanguage();
Expand Down
Expand Up @@ -83,6 +83,7 @@
import org.telegram.ui.Components.AnimatedEmojiDrawable;
import org.telegram.ui.Components.AnimatedEmojiSpan;
import org.telegram.ui.Components.BackupImageView;
import org.telegram.ui.Components.BulletinFactory;
import org.telegram.ui.Components.CubicBezierInterpolator;
import org.telegram.ui.Components.EmojiPacksAlert;
import org.telegram.ui.Components.EmojiView;
Expand All @@ -103,6 +104,7 @@
import tw.nekomimi.nekogram.NekoConfig;
import tw.nekomimi.nekogram.ui.MessageHelper;
import tw.nekomimi.nekogram.utils.VibrateUtil;
import xyz.nextalone.nagram.NaConfig;

public class ContentPreviewViewer {

Expand Down Expand Up @@ -251,6 +253,8 @@ default boolean isStickerEditor() {

private final static int nkbtn_send_without_sound = 100;
private final static int nkbtn_stickerdl = 110;
private final static int nkbtn_sticker_copy = 111;
private final static int nkbtn_sticker_copy_png = 112;

private static TextPaint textPaint;

Expand Down Expand Up @@ -487,6 +491,14 @@ public void dismiss() {
items.add(LocaleController.getString("SaveToGallery", R.string.SaveToGallery));
icons.add(R.drawable.msg_gallery);
actions.add(nkbtn_stickerdl);
if (NaConfig.INSTANCE.getShowCopyPhoto().Bool()) {
items.add(LocaleController.getString("CopyPhotoAsSticker", R.string.CopyPhotoAsSticker));
icons.add(R.drawable.msg_copy);
actions.add(nkbtn_sticker_copy);
items.add(LocaleController.getString("CopyPhoto", R.string.CopyPhoto));
icons.add(R.drawable.msg_copy);
actions.add(nkbtn_sticker_copy_png);
}
}
if (!MessageObject.isMaskDocument(currentDocument) && (inFavs || MediaDataController.getInstance(currentAccount).canAddStickerToFavorites() && MessageObject.isStickerHasSet(currentDocument))) {
items.add(inFavs ? LocaleController.getString("DeleteFromFavorites", R.string.DeleteFromFavorites) : LocaleController.getString("AddToFavorites", R.string.AddToFavorites));
Expand Down Expand Up @@ -555,6 +567,14 @@ public void onClick(View v) {
delegate.remove(importingSticker);
} else if (actions.get(which) == nkbtn_stickerdl) {
MessageHelper.getInstance(currentAccount).saveStickerToGallery(parentActivity, currentDocument);
} else if (actions.get(which) == nkbtn_sticker_copy) {
MessageHelper.getInstance(currentAccount).addStickerToClipboard(currentDocument, () -> {
BulletinFactory.global().createCopyBulletin(LocaleController.getString("PhotoCopied", R.string.PhotoCopied)).show();
});
} else if (actions.get(which) == nkbtn_sticker_copy_png) {
MessageHelper.getInstance(currentAccount).addStickerToClipboardAsPNG(currentDocument, () -> {
BulletinFactory.global().createCopyBulletin(LocaleController.getString("PhotoCopied", R.string.PhotoCopied)).show();
});
} else if (actions.get(which) == 7) {
delegate.editSticker(currentDocument);
} else if (actions.get(which) == 8) {
Expand Down
Expand Up @@ -447,6 +447,42 @@ public void saveStickerToGallery(Context context, TLRPC.Document document) {
}
}

public void addStickerToClipboard(TLRPC.Document document, Runnable callback) {
String path = FileLoader.getInstance(currentAccount).getPathToAttach(document, true).toString();

if (TextUtils.isEmpty(path)) {
return;
}
if (MessageObject.isVideoSticker(document)) {
return;
}
File file = new File(path);
if (file.exists()) {
xyz.nextalone.nagram.helper.MessageHelper.INSTANCE.addFileToClipboard(file, callback);
}
}

public void addStickerToClipboardAsPNG(TLRPC.Document document, Runnable callback) {
String path = FileLoader.getInstance(currentAccount).getPathToAttach(document, true).toString();

if (TextUtils.isEmpty(path)) {
return;
}
if (MessageObject.isVideoSticker(document)) {
return;
}
try {
Bitmap image = BitmapFactory.decodeFile(path);
File png = new File(path + ".png");
FileOutputStream stream = new FileOutputStream(png);
image.compress(Bitmap.CompressFormat.PNG, 100, stream);
stream.close();
xyz.nextalone.nagram.helper.MessageHelper.INSTANCE.addFileToClipboard(png, callback);
} catch (Exception e) {
FileLog.e(e);
}
}

public MessageObject getMessageForRepeat(MessageObject selectedObject, MessageObject.GroupedMessages selectedObjectGroup) {
MessageObject messageObject = null;
if (selectedObjectGroup != null && !selectedObjectGroup.isDocuments) {
Expand Down

0 comments on commit 83ef19c

Please sign in to comment.