Fixed null pointer exceptions

This commit is contained in:
DrKLO 2014-04-05 09:55:51 +04:00
parent 0aea8f1532
commit 2f191225b7
5 changed files with 48 additions and 11 deletions

View File

@ -82,7 +82,7 @@ android {
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
versionCode 225
versionName "1.4.10"
versionCode 226
versionName "1.4.11"
}
}

View File

@ -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;

View File

@ -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);

View File

@ -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;
}

View File

@ -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<MessageObject> imagesArr = new ArrayList<MessageObject>();
HashMap<Integer, MessageObject> imagesByIds = new HashMap<Integer, MessageObject>();
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 {