From 2f191225b7cdf2cc9a23a179e91f563314272c02 Mon Sep 17 00:00:00 2001 From: DrKLO Date: Sat, 5 Apr 2014 09:55:51 +0400 Subject: [PATCH] Fixed null pointer exceptions --- TMessagesProj/build.gradle | 4 +-- .../org/telegram/objects/MessageObject.java | 3 +++ .../org/telegram/ui/Cells/ChatMediaCell.java | 27 ++++++++++++++----- .../java/org/telegram/ui/ChatActivity.java | 12 +++++++-- .../org/telegram/ui/GalleryImageViewer.java | 13 ++++++++- 5 files changed, 48 insertions(+), 11 deletions(-) diff --git a/TMessagesProj/build.gradle b/TMessagesProj/build.gradle index 83bd704d8..61046e2a8 100644 --- a/TMessagesProj/build.gradle +++ b/TMessagesProj/build.gradle @@ -82,7 +82,7 @@ android { defaultConfig { minSdkVersion 8 targetSdkVersion 19 - versionCode 225 - versionName "1.4.10" + versionCode 226 + versionName "1.4.11" } } diff --git a/TMessagesProj/src/main/java/org/telegram/objects/MessageObject.java b/TMessagesProj/src/main/java/org/telegram/objects/MessageObject.java index f414a9c8e..1408795e9 100644 --- a/TMessagesProj/src/main/java/org/telegram/objects/MessageObject.java +++ b/TMessagesProj/src/main/java/org/telegram/objects/MessageObject.java @@ -376,6 +376,9 @@ public class MessageObject { } } else if (attach instanceof TLRPC.PhotoSize) { TLRPC.PhotoSize photo = (TLRPC.PhotoSize)attach; + if (photo.location == null) { + return ""; + } return photo.location.volume_id + "_" + photo.location.local_id + ".jpg"; } else if (attach instanceof TLRPC.Audio) { TLRPC.Audio audio = (TLRPC.Audio)attach; 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 137003d20..0c0906000 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMediaCell.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMediaCell.java @@ -53,6 +53,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD private int photoWidth; private int photoHeight; private PhotoObject currentPhotoObject; + private String currentUrl; private String currentPhotoFilter; private ImageReceiver photoImage; private ProgressView progressView; @@ -274,19 +275,33 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD } } - @Override - protected boolean isUserDataChanged() { - return currentPhotoObject == null || super.isUserDataChanged(); + private boolean isPhotoDataChanged(MessageObject object) { + if (object.type == 4) { + if (currentUrl == null) { + return true; + } + double lat = object.messageOwner.media.geo.lat; + double lon = object.messageOwner.media.geo._long; + String url = String.format(Locale.US, "https://maps.googleapis.com/maps/api/staticmap?center=%f,%f&zoom=13&size=100x100&maptype=roadmap&scale=%d&markers=color:red|size:big|%f,%f&sensor=false", lat, lon, Math.min(2, (int)Math.ceil(Utilities.density)), lat, lon); + if (!url.equals(currentUrl)) { + return true; + } + } else if (currentPhotoObject == null) { + return true; + } + return false; } @Override public void setMessageObject(MessageObject messageObject) { - if (currentMessageObject != messageObject || isUserDataChanged()) { + if (currentMessageObject != messageObject || isPhotoDataChanged(messageObject) || isUserDataChanged()) { super.setMessageObject(messageObject); progressVisible = false; buttonState = -1; gifDrawable = null; + currentPhotoObject = null; + currentUrl = null; if (messageObject.type == 8) { gifDrawable = MediaController.getInstance().getGifDrawable(this, false); @@ -321,8 +336,8 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD double lat = messageObject.messageOwner.media.geo.lat; double lon = messageObject.messageOwner.media.geo._long; - String url = String.format(Locale.US, "https://maps.googleapis.com/maps/api/staticmap?center=%f,%f&zoom=13&size=100x100&maptype=roadmap&scale=%d&markers=color:red|size:big|%f,%f&sensor=false", lat, lon, Math.min(2, (int)Math.ceil(Utilities.density)), lat, lon); - photoImage.setImage(url, null, messageObject.isOut() ? placeholderOutDrawable : placeholderInDrawable); + currentUrl = String.format(Locale.US, "https://maps.googleapis.com/maps/api/staticmap?center=%f,%f&zoom=13&size=100x100&maptype=roadmap&scale=%d&markers=color:red|size:big|%f,%f&sensor=false", lat, lon, Math.min(2, (int)Math.ceil(Utilities.density)), lat, lon); + photoImage.setImage(currentUrl, null, messageObject.isOut() ? placeholderOutDrawable : placeholderInDrawable); } else { photoWidth = (int) (Math.min(Utilities.displaySize.x, Utilities.displaySize.y) * 0.7f); photoHeight = photoWidth + Utilities.dp(100); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java index 25997a08c..5da655958 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java @@ -1468,13 +1468,21 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa TLRPC.FileLocation newPhoto = null; int placeHolderId = 0; if (currentUser != null) { - currentUser = MessagesController.getInstance().users.get(currentUser.id); + TLRPC.User user = MessagesController.getInstance().users.get(currentUser.id); + if (user == null) { + return; + } + currentUser = user; if (currentUser.photo != null) { newPhoto = currentUser.photo.photo_small; } placeHolderId = Utilities.getUserAvatarForId(currentUser.id); } else if (currentChat != null) { - currentChat = MessagesController.getInstance().chats.get(currentChat.id); + TLRPC.Chat chat = MessagesController.getInstance().chats.get(currentChat.id); + if (chat == null) { + return; + } + currentChat = chat; if (currentChat.photo != null) { newPhoto = currentChat.photo.photo_small; } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/GalleryImageViewer.java b/TMessagesProj/src/main/java/org/telegram/ui/GalleryImageViewer.java index b2dd8cd6a..227e83c6e 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/GalleryImageViewer.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/GalleryImageViewer.java @@ -172,6 +172,14 @@ public class GalleryImageViewer extends AbstractGalleryActivity implements Notif timeTextView.setVisibility(View.INVISIBLE); localPagerAdapter = new LocalPagerAdapter(arr); } else if (messagesArr != null) { + MessageObject object = null; + for (MessageObject messageObject : messagesArr) { + if (messageObject.messageOwner.dialog_id != 0 || messageObject.messageOwner.to_id != null) { + object = messageObject; + break; + } + } + ArrayList imagesArr = new ArrayList(); HashMap imagesByIds = new HashMap(); imagesArr.addAll(messagesArr); @@ -181,10 +189,13 @@ public class GalleryImageViewer extends AbstractGalleryActivity implements Notif } index = imagesArr.size() - index - 1; - MessageObject object = imagesArr.get(0); + if (object.messageOwner.dialog_id != 0) { currentDialog = object.messageOwner.dialog_id; } else { + if (object.messageOwner.to_id == null) { + finish(); + } if (object.messageOwner.to_id.chat_id != 0) { currentDialog = -object.messageOwner.to_id.chat_id; } else {