From 94a130346c39af87da99ea13916fb1590a0807c2 Mon Sep 17 00:00:00 2001 From: luvletter2333 Date: Fri, 20 Aug 2021 16:13:57 +0800 Subject: [PATCH] save to gallery in sticker preview --- .../org/telegram/ui/ContentPreviewViewer.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ContentPreviewViewer.java b/TMessagesProj/src/main/java/org/telegram/ui/ContentPreviewViewer.java index c61b466cc..64618d681 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ContentPreviewViewer.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ContentPreviewViewer.java @@ -12,6 +12,7 @@ import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; import android.graphics.Bitmap; +import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.PixelFormat; @@ -34,6 +35,7 @@ import android.view.WindowManager; import android.widget.FrameLayout; import org.telegram.messenger.AndroidUtilities; +import org.telegram.messenger.MediaController; import org.telegram.messenger.MediaDataController; import org.telegram.messenger.Emoji; import org.telegram.messenger.FileLoader; @@ -55,9 +57,11 @@ import org.telegram.ui.Cells.ContextLinkCell; import org.telegram.ui.Cells.StickerCell; import org.telegram.ui.Cells.StickerEmojiCell; import org.telegram.ui.Components.AlertsCreator; +import org.telegram.ui.Components.ChatAvatarContainer; import org.telegram.ui.Components.LayoutHelper; import org.telegram.ui.Components.RecyclerListView; +import java.io.FileOutputStream; import java.util.ArrayList; import tw.nekomimi.nekogram.NekoConfig; @@ -191,6 +195,9 @@ public class ContentPreviewViewer { icons.add(R.drawable.msg_delete); actions.add(5); } + items.add(LocaleController.getString("SaveToGallery", R.string.SaveToGallery)); + icons.add(R.drawable.baseline_image_24); + actions.add(110); } 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)); @@ -233,6 +240,20 @@ 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) { + // 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); + } + } } }); builder.setDimBehind(false);