From db64b2f6981738aa970fd06dd61c5c87df0936eb Mon Sep 17 00:00:00 2001 From: DrKLO Date: Wed, 11 Jun 2014 04:22:42 +0400 Subject: [PATCH] Photo viewer bug fixes --- .../org/telegram/ui/Cells/ChatMediaCell.java | 12 +++++++ .../java/org/telegram/ui/ChatActivity.java | 5 +++ .../org/telegram/ui/ChatProfileActivity.java | 5 +++ .../java/org/telegram/ui/MediaActivity.java | 6 ++-- .../java/org/telegram/ui/PhotoViewer.java | 33 +++++++++++++++--- .../org/telegram/ui/SettingsActivity.java | 5 +++ .../org/telegram/ui/UserProfileActivity.java | 5 +++ .../res/drawable/photoview_placeholder.png | Bin 0 -> 933 bytes 8 files changed, 64 insertions(+), 7 deletions(-) create mode 100644 TMessagesProj/src/main/res/drawable/photoview_placeholder.png diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMediaCell.java b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMediaCell.java index b6cb0f4f8..abe78fb79 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMediaCell.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMediaCell.java @@ -61,6 +61,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD private ProgressView progressView; public int downloadPhotos = 0; private boolean progressVisible = false; + private boolean photoNotSet = false; private int TAG; @@ -290,6 +291,12 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD } } else if (currentPhotoObject == null) { return true; + } else if (currentPhotoObject != null && photoNotSet) { + String fileName = MessageObject.getAttachFileName(currentPhotoObject.photoOwner); + File cacheFile = new File(Utilities.getCacheDir(), fileName); + if (cacheFile.exists()) { + return true; + } } return false; } @@ -304,6 +311,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD gifDrawable = null; currentPhotoObject = null; currentUrl = null; + photoNotSet = false; if (messageObject.type == 8) { gifDrawable = MediaController.getInstance().getGifDrawable(this, false); @@ -405,6 +413,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD photoImage.setImage(currentPhotoObject.photoOwner.location, currentPhotoFilter, messageObject.isOut() ? placeholderOutDrawable : placeholderInDrawable, currentPhotoObject.photoOwner.size); } } else { + photoNotSet = true; if (messageObject.imagePreview != null) { photoImage.setImageBitmap(messageObject.imagePreview); } else { @@ -597,6 +606,9 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD if (currentMessageObject.type == 8 && lastDownloadedGifMessage != null && lastDownloadedGifMessage.messageOwner.id == currentMessageObject.messageOwner.id && buttonState == 2) { didPressedButton(); } + if (photoNotSet) { + setMessageObject(currentMessageObject); + } } @Override diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java index 8f4da2f30..c2eeac5ad 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java @@ -3371,6 +3371,11 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa return null; } + @Override + public void willHidePhotoViewer() { + updateVisibleRows(); + } + private class ChatAdapter extends BaseAdapter { private Context mContext; diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ChatProfileActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ChatProfileActivity.java index cb42c1aa0..76e5d9bb5 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ChatProfileActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ChatProfileActivity.java @@ -367,6 +367,11 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen return null; } + @Override + public void willHidePhotoViewer() { + + } + public void didReceivedNotification(int id, Object... args) { if (id == MessagesController.updateInterfaces) { int mask = (Integer)args[0]; diff --git a/TMessagesProj/src/main/java/org/telegram/ui/MediaActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/MediaActivity.java index c83042933..22323f834 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/MediaActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/MediaActivity.java @@ -293,8 +293,10 @@ public class MediaActivity extends BaseFragment implements NotificationCenter.No } } return null; -// NotificationCenter.getInstance().addToMemCache(54, messages); TODO -// NotificationCenter.getInstance().addToMemCache(55, i); + } + + @Override + public void willHidePhotoViewer() { } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/PhotoViewer.java b/TMessagesProj/src/main/java/org/telegram/ui/PhotoViewer.java index 4e03a50fa..8e7646c8f 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/PhotoViewer.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/PhotoViewer.java @@ -199,7 +199,8 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat } public static interface PhotoViewerProvider { - public abstract PlaceProviderObject getPlaceForPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation); + public PlaceProviderObject getPlaceForPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation); + public void willHidePhotoViewer(); } private static class FrameLayoutTouchListener extends FrameLayout { @@ -737,17 +738,30 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat TLRPC.PhotoSize sizeFull = PhotoObject.getClosestPhotoSizeWithSize(message.messageOwner.action.photo.sizes, 800, 800); if (sizeFull != null) { size[0] = sizeFull.size; + if (size[0] == 0) { + size[0] = -1; + } return sizeFull.location; + } else { + size[0] = -1; } } } else if (message.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto && message.messageOwner.media.photo != null) { TLRPC.PhotoSize sizeFull = PhotoObject.getClosestPhotoSizeWithSize(message.messageOwner.media.photo.sizes, 800, 800); if (sizeFull != null) { size[0] = sizeFull.size; + if (size[0] == 0) { + size[0] = -1; + } return sizeFull.location; + } else { + size[0] = -1; } } else if (message.messageOwner.media instanceof TLRPC.TL_messageMediaVideo && message.messageOwner.media.video != null && message.messageOwner.media.video.thumb != null) { size[0] = message.messageOwner.media.video.thumb.size; + if (size[0] == 0) { + size[0] = -1; + } return message.messageOwner.media.video.thumb.location; } } @@ -1088,7 +1102,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat } imageReceiver.setImage(fileLocation, null, placeHolder != null ? new BitmapDrawable(null, placeHolder) : null, size[0]); } else { - imageReceiver.setImageBitmap((Bitmap)null); + imageReceiver.setImageBitmap(parentActivity.getResources().getDrawable(R.drawable.photoview_placeholder)); } } else { Bitmap placeHolder = null; @@ -1101,7 +1115,11 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat imageReceiver.setImage(fileLocation, null, placeHolder != null ? new BitmapDrawable(null, placeHolder) : null, size[0]); } } else { - imageReceiver.setImageBitmap((Bitmap)null); + if (size[0] == 0) { + imageReceiver.setImageBitmap((Bitmap) null); + } else { + imageReceiver.setImageBitmap(parentActivity.getResources().getDrawable(R.drawable.photoview_placeholder)); + } } } @@ -1357,11 +1375,10 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat } private void onPhotoClosed(PlaceProviderObject object) { - placeProvider = null; + disableShowCheck = true; currentMessageObject = null; currentFileLocation = null; currentThumb = null; - animatingImageView.setImageBitmap(null); centerImage.setImageBitmap((Bitmap)null); leftImage.setImageBitmap((Bitmap) null); rightImage.setImageBitmap((Bitmap)null); @@ -1371,10 +1388,16 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat containerView.post(new Runnable() { @Override public void run() { + animatingImageView.setImageBitmap(null); WindowManager wm = (WindowManager) parentActivity.getSystemService(Context.WINDOW_SERVICE); wm.removeView(containerView); } }); + if (placeProvider != null) { + placeProvider.willHidePhotoViewer(); + } + placeProvider = null; + disableShowCheck = false; } public boolean isVisible() { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/SettingsActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/SettingsActivity.java index e98749a17..65959ac6d 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/SettingsActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/SettingsActivity.java @@ -444,6 +444,11 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter return null; } + @Override + public void willHidePhotoViewer() { + + } + public void performAskAQuestion() { final SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); int uid = preferences.getInt("support_id", 0); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/UserProfileActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/UserProfileActivity.java index 9ef0ab1b9..597f3e487 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/UserProfileActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/UserProfileActivity.java @@ -485,6 +485,11 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen return null; } + @Override + public void willHidePhotoViewer() { + + } + private void createActionBarMenu() { ActionBarMenu menu = actionBarLayer.createMenu(); menu.clearItems(); diff --git a/TMessagesProj/src/main/res/drawable/photoview_placeholder.png b/TMessagesProj/src/main/res/drawable/photoview_placeholder.png new file mode 100644 index 0000000000000000000000000000000000000000..979ea46d1a327665c55af88492a74946aa1d8a4a GIT binary patch literal 933 zcmaJ=Pmj_-6mQ^SNcOzyX;LnlNT*XkXhU}c6x=435Vl4R9xUwu6Sgz89i(vDcr)?p zw=jD0Sc6JSAunpl0Q@#>4c7~wKVhrj^z2d8=1{%78>ZsO4_kgCNDpacw zRVzp{RNX*zu=`|@Ee@u}$m;KM3D1=0oJR(PtJO+bRTUP`AkuXmsv6X^iioHrYs$T} zLX&dNVBy4%NyG`GAY=3SNn7WkI135*Q7=t@b+&y{Bs$LcMB7>-F{fHLKZZwtF2-&9N5qmm#J+#|GEf z_Caj63t=QOTR0}qanO%h2(~pFux5C+P zKBi*bW3kuoUjH77H*wRp+HU%7^8NkdxJW;JzC3>Al1r&5z4=n;{Nhg@We>;h4Xn4F Hr!W2h>DeB` literal 0 HcmV?d00001