From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: alina sireneva <alina@tei.su>
Date: Sat, 11 Apr 2026 03:35:42 +0300
Subject: "copy photo" in photo viewer

---
 .../java/org/telegram/ui/PhotoViewer.java     | 41 ++++++++++++++++---
 1 file changed, 36 insertions(+), 5 deletions(-)

diff --git a/TMessagesProj/src/main/java/org/telegram/ui/PhotoViewer.java b/TMessagesProj/src/main/java/org/telegram/ui/PhotoViewer.java
index 0000000..0000000 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/PhotoViewer.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/PhotoViewer.java
@@ -885,7 +885,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
     public BlurringShader.BlurManager blurManager;
     private BlurringShader.StoryBlurDrawer shadowBlurer;
     private WindowManager.LayoutParams windowLayoutParams;
-    private FrameLayoutDrawer containerView;
+    public FrameLayoutDrawer containerView;
     private PhotoViewerWebView photoViewerWebView;
     public FrameLayout windowView;
     private ClippingImageView animatingImageView;
@@ -895,7 +895,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
     private TextView docNameTextView;
     private TextView docInfoTextView;
     private TextView doneButtonFullWidth;
-    private ActionBarMenuItem menuItem;
+    public ActionBarMenuItem menuItem;
     private ActionBarMenuItem videoItem;
     private ActionBarMenuSubItem allMediaItem;
     private ActionBarMenuSlider.SpeedSlider speedItem;
@@ -4595,7 +4595,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
         }
     }
 
-    private void showDownloadAlert() {
+    public void showDownloadAlert() {
         AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity, resourcesProvider);
         builder.setTitle(getString(R.string.AppName));
         builder.setPositiveButton(getString("OK", R.string.OK), null);
@@ -5537,6 +5537,8 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
                     } catch (Exception e) {
                         FileLog.e(e);
                     }
+                } else if (desu.inugram.helpers.media.PhotoViewerHelper.handleMenuClick(id, PhotoViewer.this)) {
+                    // handled by inugram
                 } else if (id == gallery_menu_masks || id == gallery_menu_masks2) {
                     if (parentActivity == null || currentMessageObject == null) {
                         return;
@@ -5898,6 +5900,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
         galleryGap = menuItem.addColoredGap();
         galleryGap.setColor(0xff181818);
         menuItem.addSubItem(gallery_menu_openin, R.drawable.msg_openin, getString(R.string.OpenInExternalApp)).setColors(0xfffafafa, 0xfffafafa);
+        desu.inugram.helpers.media.PhotoViewerHelper.addMenuItems(menuItem);
         pipItem = menuItem.addSubItem(gallery_menu_pip, R.drawable.menu_video_pip, getString(R.string.PipMinimize)).setColors(0xfffafafa, 0xfffafafa);
         allMediaItem = menuItem.addSubItem(gallery_menu_showall, R.drawable.msg_media, getString(R.string.ShowAllMedia));
         allMediaItem.setColors(0xfffafafa, 0xfffafafa);
@@ -5914,6 +5917,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
         menuItem.addSubItem(gallery_menu_hide_translation, R.drawable.msg_translate, getString(R.string.HideTranslation)).setColors(0xfffafafa, 0xfffafafa);
         menuItem.addSubItem(gallery_menu_delete, R.drawable.msg_delete, getString(R.string.Delete)).setColors(0xfffafafa, 0xfffafafa);
         menuItem.addSubItem(gallery_menu_cancel_loading, R.drawable.msg_cancel, getString(R.string.StopDownload)).setColors(0xfffafafa, 0xfffafafa);
+        desu.inugram.helpers.media.PhotoViewerHelper.addFooter(menuItem);
         menuItem.redrawPopup(0xf9222222);
         menuItem.hideSubItem(gallery_menu_translate);
         menuItem.hideSubItem(gallery_menu_hide_translation);
@@ -13997,6 +14001,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
         menuItem.hideSubItem(gallery_menu_report);
         menuItem.hideSubItem(gallery_menu_share);
         menuItem.hideSubItem(gallery_menu_openin);
+        desu.inugram.helpers.media.PhotoViewerHelper.resetMenuItems(menuItem);
         menuItem.hideSubItem(gallery_menu_savegif);
         menuItem.hideSubItem(gallery_menu_masks2);
         menuItem.hideSubItem(gallery_menu_edit_avatar);
@@ -14537,6 +14542,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
                 subtitle = LocaleController.formatDateAudio(newMessageObject.messageOwner.date, false);
             }
             actionBarContainer.setSubtitle(subtitle, animated);
+            desu.inugram.helpers.media.PhotoViewerHelper.setFooter(newMessageObject);
 
             boolean isInvoice = newMessageObject.isInvoice();
             boolean noforwards = MessagesController.getInstance(currentAccount).isPeerNoForwards(newMessageObject.getDialogId()) || (newMessageObject.messageOwner != null && newMessageObject.messageOwner.noforwards) || newMessageObject.hasRevealedExtendedMedia();
@@ -14597,6 +14603,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
                     menuItem.hideSubItem(gallery_menu_hide_translation);
                 }
                 allowShare = !noforwards;
+                desu.inugram.helpers.media.PhotoViewerHelper.updateMenuItems(menuItem, allowShare, isVideo, newMessageObject.isGif());
                 if (newMessageObject.isNewGif() && allowShare && !DialogObject.isEncryptedDialog(newMessageObject.getDialogId())) {
                     menuItem.showSubItem(gallery_menu_savegif);
                 }
@@ -14837,11 +14844,13 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
             if (avatarsDialogId != 0) {
                 title = DialogObject.getName(avatarsDialogId);
                 ImageLocation imageLocation = imagesArrLocations.get(index);
-                if (imageLocation != null && imageLocation.photo != null) {
-                    actionBarContainer.setSubtitle(LocaleController.formatDateTime(imageLocation.photo.date, true), animated);
+                CharSequence avatarSubtitle = desu.inugram.helpers.media.PhotoViewerHelper.getAvatarSubtitle(imageLocation, avatarsDialogId, currentAccount);
+                if (avatarSubtitle != null) {
+                    actionBarContainer.setSubtitle(avatarSubtitle, animated);
                 } else {
                     actionBarContainer.setSubtitle("", animated);
                 }
+                desu.inugram.helpers.media.PhotoViewerHelper.setFooter(imageLocation, currentAccount);
                 menuItem.showSubItem(gallery_menu_report);
             }
 
@@ -14866,6 +14875,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
                 galleryGap.setVisibility(View.VISIBLE);
             }
             allowShare = !noforwards;
+            desu.inugram.helpers.media.PhotoViewerHelper.updateMenuItems(menuItem, allowShare, false, false);
             menuItem.showSubItem(gallery_menu_share);
             menuItem.checkHideMenuItem();
             groupedPhotosListView.fillList();
@@ -15152,6 +15162,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
             TL_iv.PageBlock pageBlock = pageBlocksAdapter.get(switchingToIndex);
             caption = pageBlocksAdapter.getCaption(switchingToIndex);
             isVideo = pageBlocksAdapter.isVideo(switchingToIndex);
+            desu.inugram.helpers.media.PhotoViewerHelper.updateMenuItems(menuItem, allowShare, isVideo, false);
             if (isVideo) {
                 if (allowShare) {
                     menuItem.showSubItem(gallery_menu_openin);
@@ -23460,6 +23471,26 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
         return pipItem != null && pipItem.isEnabled() && isPlaying;
     }
 
+    public File inu_getCurrentPhotoFile() {
+        File f = null;
+        if (currentMessageObject != null) {
+            if (MessageObject.getMedia(currentMessageObject.messageOwner) instanceof TLRPC.TL_messageMediaWebPage && MessageObject.getMedia(currentMessageObject.messageOwner).webpage != null && MessageObject.getMedia(currentMessageObject.messageOwner).webpage.document == null) {
+                TLObject fileLocation = getFileLocation(currentIndex, null);
+                f = FileLoader.getInstance(currentAccount).getPathToAttach(fileLocation, true);
+            } else {
+                f = FileLoader.getInstance(currentAccount).getPathToMessage(currentMessageObject.messageOwner);
+            }
+        } else if (currentFileLocationVideo != null) {
+            f = FileLoader.getInstance(currentAccount).getPathToAttach(getFileLocation(currentFileLocationVideo), getFileLocationExt(currentFileLocationVideo), avatarsDialogId != 0 || isEvent);
+        } else if (pageBlocksAdapter != null) {
+            f = pageBlocksAdapter.getFile(currentIndex);
+        }
+        if (f != null && !f.exists()) {
+            f = new File(FileLoader.getDirectory(FileLoader.MEDIA_DIR_CACHE), f.getName());
+        }
+        return f != null && f.exists() ? f : null;
+    }
+
     @Override
     public Bitmap pipCreatePrimaryWindowViewBitmap() {
         if (videoTextureView != null) {
