feat: Added copy photo to PhotoViewer

Thanks to OwlGram
This commit is contained in:
xtaodada 2022-06-30 17:39:49 +08:00
parent 45d70e459e
commit 783415e3d0
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659

View File

@ -256,6 +256,7 @@ import tw.nekomimi.nekogram.transtale.TranslatorKt;
import tw.nekomimi.nekogram.utils.AlertUtil; import tw.nekomimi.nekogram.utils.AlertUtil;
import tw.nekomimi.nekogram.utils.ProxyUtil; import tw.nekomimi.nekogram.utils.ProxyUtil;
import xyz.nextalone.nagram.NaConfig; import xyz.nextalone.nagram.NaConfig;
import xyz.nextalone.nagram.helper.MessageHelper;
@SuppressLint("WrongConstant") @SuppressLint("WrongConstant")
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@ -1229,6 +1230,8 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
private final static int gallery_menu_share2 = 18; private final static int gallery_menu_share2 = 18;
private final static int gallery_menu_speed = 19; private final static int gallery_menu_speed = 19;
private final static int gallery_menu_copy = 100;
private static DecelerateInterpolator decelerateInterpolator; private static DecelerateInterpolator decelerateInterpolator;
private static Paint progressPaint; private static Paint progressPaint;
@ -4474,6 +4477,26 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
thumb = null; thumb = null;
} }
placeProvider.openPhotoForEdit(f.getAbsolutePath(), thumb, isVideo); placeProvider.openPhotoForEdit(f.getAbsolutePath(), thumb, isVideo);
} else if (id == gallery_menu_copy) {
File f = null;
if (currentMessageObject != null) {
if (currentMessageObject.messageOwner.media instanceof TLRPC.TL_messageMediaWebPage && currentMessageObject.messageOwner.media.webpage != null && currentMessageObject.messageOwner.media.webpage.document == null) {
TLObject fileLocation = getFileLocation(currentIndex, null);
f = FileLoader.getPathToAttach(fileLocation, true);
} else {
f = FileLoader.getPathToMessage(currentMessageObject.messageOwner);
}
} else if (currentFileLocationVideo != null) {
f = FileLoader.getPathToAttach(getFileLocation(currentFileLocationVideo), getFileLocationExt(currentFileLocationVideo), avatarsDialogId != 0 || isEvent);
} else if (pageBlocksAdapter != null) {
f = pageBlocksAdapter.getFile(currentIndex);
}
if (f != null && f.exists()) {
MessageHelper.INSTANCE.addFileToClipboard(f, () -> BulletinFactory.of(containerView, null).createCopyBulletin(LocaleController.getString("PhotoCopied", R.string.PhotoCopied)).show());
} else {
showDownloadAlert();
}
} }
} }
@ -4557,6 +4580,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
menuItem.addSubItem(gallery_menu_masks2, R.drawable.msg_sticker, LocaleController.getString("ShowStickers", R.string.ShowStickers)).setColors(0xfffafafa, 0xfffafafa); menuItem.addSubItem(gallery_menu_masks2, R.drawable.msg_sticker, LocaleController.getString("ShowStickers", R.string.ShowStickers)).setColors(0xfffafafa, 0xfffafafa);
menuItem.addSubItem(gallery_menu_share, R.drawable.msg_shareout, LocaleController.getString("ShareFile", R.string.ShareFile)).setColors(0xfffafafa, 0xfffafafa); menuItem.addSubItem(gallery_menu_share, R.drawable.msg_shareout, LocaleController.getString("ShareFile", R.string.ShareFile)).setColors(0xfffafafa, 0xfffafafa);
menuItem.addSubItem(gallery_menu_save, R.drawable.msg_gallery, LocaleController.getString("SaveToGallery", R.string.SaveToGallery)).setColors(0xfffafafa, 0xfffafafa); menuItem.addSubItem(gallery_menu_save, R.drawable.msg_gallery, LocaleController.getString("SaveToGallery", R.string.SaveToGallery)).setColors(0xfffafafa, 0xfffafafa);
menuItem.addSubItem(gallery_menu_copy, R.drawable.msg_copy, LocaleController.getString("CopyPhoto", R.string.CopyPhoto)).setColors(0xfffafafa, 0xfffafafa);
menuItem.addSubItem(gallery_menu_scan, R.drawable.wallet_qr, LocaleController.getString("ScanQRCode", R.string.ScanQRCode)).setColors(0xfffafafa, 0xfffafafa); menuItem.addSubItem(gallery_menu_scan, R.drawable.wallet_qr, LocaleController.getString("ScanQRCode", R.string.ScanQRCode)).setColors(0xfffafafa, 0xfffafafa);
@ -10571,6 +10595,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
if (currentAnimation != null) { if (currentAnimation != null) {
menuItem.hideSubItem(gallery_menu_save); menuItem.hideSubItem(gallery_menu_save);
menuItem.hideSubItem(gallery_menu_copy);
menuItem.hideSubItem(gallery_menu_share); menuItem.hideSubItem(gallery_menu_share);
menuItem.hideSubItem(gallery_menu_scan); menuItem.hideSubItem(gallery_menu_scan);
if (!newMessageObject.canDeleteMessage(parentChatActivity != null && parentChatActivity.isInScheduleMode(), null)) { if (!newMessageObject.canDeleteMessage(parentChatActivity != null && parentChatActivity.isInScheduleMode(), null)) {
@ -10658,6 +10683,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
if (isEmbedVideo || newMessageObject.messageOwner.ttl != 0 && newMessageObject.messageOwner.ttl < 60 * 60 || noforwardsOverride) { if (isEmbedVideo || newMessageObject.messageOwner.ttl != 0 && newMessageObject.messageOwner.ttl < 60 * 60 || noforwardsOverride) {
allowShare = false; allowShare = false;
menuItem.hideSubItem(gallery_menu_save); menuItem.hideSubItem(gallery_menu_save);
menuItem.hideSubItem(gallery_menu_copy);
bottomButtonsLayout.setVisibility(View.GONE); bottomButtonsLayout.setVisibility(View.GONE);
menuItem.hideSubItem(gallery_menu_scan); menuItem.hideSubItem(gallery_menu_scan);
menuItem.hideSubItem(gallery_menu_share); menuItem.hideSubItem(gallery_menu_share);
@ -10675,6 +10701,11 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
} else { } else {
menuItem.showSubItem(gallery_menu_share); menuItem.showSubItem(gallery_menu_share);
} }
if (newMessageObject.isPhoto()) {
menuItem.showSubItem(gallery_menu_copy);
} else {
menuItem.hideSubItem(gallery_menu_copy);
}
} }
groupedPhotosListView.fillList(); groupedPhotosListView.fillList();
} }
@ -10682,6 +10713,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
allowShare = false; allowShare = false;
menuItem.showSubItem(gallery_menu_delete); menuItem.showSubItem(gallery_menu_delete);
menuItem.hideSubItem(gallery_menu_save); menuItem.hideSubItem(gallery_menu_save);
menuItem.hideSubItem(gallery_menu_copy);
menuItem.hideSubItem(gallery_menu_scan); menuItem.hideSubItem(gallery_menu_scan);
nameTextView.setText(""); nameTextView.setText("");
dateTextView.setText(""); dateTextView.setText("");
@ -10705,7 +10737,8 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
nameTextView.setText(""); nameTextView.setText("");
} }
} }
long date = (long) avatarsArr.get(switchingToIndex).date * 1000; TLRPC.Photo avatar = avatarsArr.get(switchingToIndex);
long date = (long) avatar.date * 1000;
if (date != 0) { if (date != 0) {
String dateString = LocaleController.formatString("formatDateAtTime", R.string.formatDateAtTime, LocaleController.getInstance().formatterYear.format(new Date(date)), LocaleController.getInstance().formatterDay.format(new Date(date))); String dateString = LocaleController.formatString("formatDateAtTime", R.string.formatDateAtTime, LocaleController.getInstance().formatterYear.format(new Date(date)), LocaleController.getInstance().formatterDay.format(new Date(date)));
dateString = String.format(Locale.US, "%s @DC%d", dateString, avatarsArr.get(switchingToIndex).dc_id); dateString = String.format(Locale.US, "%s @DC%d", dateString, avatarsArr.get(switchingToIndex).dc_id);
@ -10747,6 +10780,11 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
} else { } else {
menuItem.showSubItem(gallery_menu_save); menuItem.showSubItem(gallery_menu_save);
} }
if (!noforwardsOverrided && avatar.video_sizes.isEmpty()) {
menuItem.showSubItem(gallery_menu_copy);
} else {
menuItem.hideSubItem(gallery_menu_copy);
}
menuItem.showSubItem(gallery_menu_scan); menuItem.showSubItem(gallery_menu_scan);
allowShare = !noforwardsOverrided; allowShare = !noforwardsOverrided;
shareButton.setVisibility(allowShare && shareItem.getVisibility() != View.VISIBLE ? View.VISIBLE : View.GONE); shareButton.setVisibility(allowShare && shareItem.getVisibility() != View.VISIBLE ? View.VISIBLE : View.GONE);
@ -11013,6 +11051,9 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
groupedPhotosListView.fillList(); groupedPhotosListView.fillList();
pageBlocksAdapter.updateSlideshowCell(pageBlock); pageBlocksAdapter.updateSlideshowCell(pageBlock);
} }
if (!NaConfig.INSTANCE.getShowCopyPhoto().Bool()){
menuItem.hideSubItem(gallery_menu_copy);
}
setCurrentCaption(newMessageObject, caption, animateCaption); setCurrentCaption(newMessageObject, caption, animateCaption);
} }
@ -11127,6 +11168,11 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
menuItem.hideSubItem(gallery_menu_scan); menuItem.hideSubItem(gallery_menu_scan);
setDoubleTapEnabled(false); setDoubleTapEnabled(false);
} }
if (canZoom && allowShare && !isVideo && NaConfig.INSTANCE.getShowCopyPhoto().Bool()) {
menuItem.showSubItem(gallery_menu_copy);
} else {
menuItem.hideSubItem(gallery_menu_copy);
}
} }
if (isVideo || isEmbedVideo) { if (isVideo || isEmbedVideo) {
speedItem.setVisibility(View.VISIBLE); speedItem.setVisibility(View.VISIBLE);