diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java index 5d93491f1..d4cd40345 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java @@ -290,6 +290,7 @@ import cn.hutool.core.util.StrUtil; import kotlin.Unit; import tw.nekomimi.nekogram.ui.BottomBuilder; import tw.nekomimi.nekogram.ui.MessageDetailsActivity; +import tw.nekomimi.nekogram.ui.MessageHelper; import tw.nekomimi.nekogram.utils.EnvUtil; import tw.nekomimi.nekogram.NekoConfig; import tw.nekomimi.nekogram.NekoXConfig; @@ -23131,38 +23132,6 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not MediaController.saveFile(path, getParentActivity(), messageObject.isVideo() ? 1 : 0, null, null); } - private void saveStickerToGallery(MessageObject messageObject) { - - String path = messageObject.messageOwner.attachPath; - if (!TextUtils.isEmpty(path)) { - File temp = new File(path); - if (!temp.exists()) { - path = null; - } - } - if (TextUtils.isEmpty(path)) { - path = FileLoader.getPathToMessage(messageObject.messageOwner).toString(); - File temp = new File(path); - if (!temp.exists()) { - path = null; - } - } - if (TextUtils.isEmpty(path)) { - path = FileLoader.getPathToAttach(messageObject.getDocument(), true).toString(); - } - if (!TextUtils.isEmpty(path)) { - try { - Bitmap image = BitmapFactory.decodeFile(path); - FileOutputStream stream = new FileOutputStream(path + ".png"); - image.compress(Bitmap.CompressFormat.PNG, 100, stream); - stream.close(); - MediaController.saveFile(path + ".png", getParentActivity(), 0, null, null); - } catch (Exception e) { - FileLog.e(e); - } - } - } - public MessageObject getMessageForTranslate() { MessageObject messageObject = null; if (selectedObjectGroup != null && !selectedObjectGroup.isDocuments) { @@ -29197,7 +29166,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not selectedObjectToEditCaption = null; return; } - saveStickerToGallery(selectedObject); + getMessageHelper().saveStickerToGallery(getParentActivity(), selectedObject); break; } case nkbtn_translate: { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ContentPreviewViewer.java b/TMessagesProj/src/main/java/org/telegram/ui/ContentPreviewViewer.java index 83f36da70..2412a3680 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ContentPreviewViewer.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ContentPreviewViewer.java @@ -65,6 +65,7 @@ import java.io.FileOutputStream; import java.util.ArrayList; import tw.nekomimi.nekogram.NekoConfig; +import tw.nekomimi.nekogram.ui.MessageHelper; public class ContentPreviewViewer { @@ -121,6 +122,8 @@ public class ContentPreviewViewer { private final static int CONTENT_TYPE_STICKER = 0; private final static int CONTENT_TYPE_GIF = 1; + private final static int nkbtn_stickerdl = 110; + private static TextPaint textPaint; private int startX; @@ -197,7 +200,7 @@ public class ContentPreviewViewer { } items.add(LocaleController.getString("SaveToGallery", R.string.SaveToGallery)); icons.add(R.drawable.baseline_image_24); - actions.add(110); + actions.add(nkbtn_stickerdl); } 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)); @@ -240,20 +243,9 @@ public class ContentPreviewViewer { MediaDataController.getInstance(currentAccount).addRecentSticker(MediaDataController.TYPE_IMAGE, parentObject, currentDocument, (int) (System.currentTimeMillis() / 1000), true); } else if (actions.get(which) == 5) { delegate.remove(importingSticker); - } else if (actions.get(which) == 110) { + } else if (actions.get(which) == nkbtn_stickerdl) { // save to gallery - String path = FileLoader.getPathToAttach(currentDocument, true).toString(); - if (!TextUtils.isEmpty(path)) { - try { - Bitmap image = BitmapFactory.decodeFile(path); - FileOutputStream stream = new FileOutputStream(path + ".png"); - image.compress(Bitmap.CompressFormat.PNG, 100, stream); - stream.close(); - MediaController.saveFile(path + ".png", parentActivity, 0, null, null); - } catch (Exception e) { - FileLog.e(e); - } - } + MessageHelper.getInstance(currentAccount).saveStickerToGallery(parentActivity, currentDocument); } }); builder.setDimBehind(false); diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/ui/MessageHelper.java b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/ui/MessageHelper.java index 200e9aae1..833601166 100644 --- a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/ui/MessageHelper.java +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/ui/MessageHelper.java @@ -4,13 +4,19 @@ import static tw.nekomimi.nekogram.utils.LangsKt.uDismiss; import static tw.nekomimi.nekogram.utils.LangsKt.uUpdate; import android.content.Context; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.text.TextUtils; import android.util.SparseArray; import org.telegram.SQLite.SQLiteCursor; import org.telegram.SQLite.SQLiteException; +import org.telegram.messenger.AccountInstance; import org.telegram.messenger.AndroidUtilities; import org.telegram.messenger.BaseController; +import org.telegram.messenger.FileLoader; import org.telegram.messenger.FileLog; +import org.telegram.messenger.MediaController; import org.telegram.messenger.MessageObject; import org.telegram.messenger.MessagesController; import org.telegram.messenger.NotificationCenter; @@ -20,6 +26,8 @@ import org.telegram.tgnet.NativeByteBuffer; import org.telegram.tgnet.TLRPC; import org.telegram.ui.ActionBar.AlertDialog; +import java.io.File; +import java.io.FileOutputStream; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -348,4 +356,62 @@ public class MessageHelper extends BaseController { return ret; } + public void saveStickerToGallery(Context context, MessageObject messageObject) { + if (messageObject.isAnimatedSticker()) return; + // Animated Sticker is not supported. + + String path = messageObject.messageOwner.attachPath; + if (!TextUtils.isEmpty(path)) { + File temp = new File(path); + if (!temp.exists()) { + path = null; + } + } + if (TextUtils.isEmpty(path)) { + path = FileLoader.getPathToMessage(messageObject.messageOwner).toString(); + File temp = new File(path); + if (!temp.exists()) { + path = null; + } + } + if (TextUtils.isEmpty(path)) { + path = FileLoader.getPathToAttach(messageObject.getDocument(), true).toString(); + } + if (!TextUtils.isEmpty(path)) { + if (messageObject.isVideoSticker()) { + MediaController.saveFile(path, context, 1, null, null); + } else { + try { + Bitmap image = BitmapFactory.decodeFile(path); + FileOutputStream stream = new FileOutputStream(path + ".png"); + image.compress(Bitmap.CompressFormat.PNG, 100, stream); + stream.close(); + MediaController.saveFile(path + ".png", context, 0, null, null); + } catch (Exception e) { + FileLog.e(e); + } + } + } + } + + public void saveStickerToGallery(Context context, TLRPC.Document document) { + String path = FileLoader.getPathToAttach(document, true).toString(); + + if (!TextUtils.isEmpty(path)) { + if (MessageObject.isVideoSticker(document)) { + MediaController.saveFile(path, context, 1, null, document.mime_type); + } else { + try { + Bitmap image = BitmapFactory.decodeFile(path); + FileOutputStream stream = new FileOutputStream(path + ".png"); + image.compress(Bitmap.CompressFormat.PNG, 100, stream); + stream.close(); + MediaController.saveFile(path + ".png", context, 0, null, null); + } catch (Exception e) { + FileLog.e(e); + } + } + } + } + }