mirror of
https://github.com/NekoX-Dev/NekoX.git
synced 2024-12-13 14:29:30 +01:00
save to gallery in sticker preview
This commit is contained in:
parent
50ee1ecd98
commit
94a130346c
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user