avoid npe on weird platform bugs

This commit is contained in:
iNPUTmice 2014-12-15 16:55:38 +01:00
parent f8a496a5f1
commit 209e62d68b
1 changed files with 29 additions and 29 deletions

View File

@ -268,7 +268,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
startDonwloadable(message); startDownloadable(message);
} }
}); });
viewHolder.download_button.setOnLongClickListener(openContextMenu); viewHolder.download_button.setOnLongClickListener(openContextMenu);
@ -284,7 +284,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
openDonwloadable(file); openDownloadable(file);
} }
}); });
viewHolder.download_button.setOnLongClickListener(openContextMenu); viewHolder.download_button.setOnLongClickListener(openContextMenu);
@ -438,6 +438,8 @@ public class MessageAdapter extends ArrayAdapter<Message> {
} }
view.setLayoutParams(view.getLayoutParams()); view.setLayoutParams(view.getLayoutParams());
return view; return view;
} else if (viewHolder.messageBody == null || viewHolder.image == null) {
return view; //avoiding weird platform bugs
} else if (type == RECEIVED) { } else if (type == RECEIVED) {
Contact contact = message.getContact(); Contact contact = message.getContact();
if (contact != null) { if (contact != null) {
@ -446,38 +448,36 @@ public class MessageAdapter extends ArrayAdapter<Message> {
viewHolder.contact_picture.setImageBitmap(activity.avatarService().get(getDisplayedMucCounterpart(message.getCounterpart()), viewHolder.contact_picture.setImageBitmap(activity.avatarService().get(getDisplayedMucCounterpart(message.getCounterpart()),
activity.getPixel(48))); activity.getPixel(48)));
} }
} else if (type == SENT && viewHolder.contact_picture != null) { } else if (type == SENT) {
viewHolder.contact_picture.setImageBitmap(activity.avatarService().get(account, activity.getPixel(48))); viewHolder.contact_picture.setImageBitmap(activity.avatarService().get(account, activity.getPixel(48)));
} }
if (viewHolder != null && viewHolder.contact_picture != null) { viewHolder.contact_picture
viewHolder.contact_picture .setOnClickListener(new OnClickListener() {
.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (MessageAdapter.this.mOnContactPictureClickedListener != null) {
MessageAdapter.this.mOnContactPictureClickedListener
.onContactPictureClicked(message);
}
@Override
public void onClick(View v) {
if (MessageAdapter.this.mOnContactPictureClickedListener != null) {
MessageAdapter.this.mOnContactPictureClickedListener
.onContactPictureClicked(message);
} }
});
viewHolder.contact_picture
.setOnLongClickListener(new OnLongClickListener() {
@Override }
public boolean onLongClick(View v) { });
if (MessageAdapter.this.mOnContactPictureLongClickedListener != null) { viewHolder.contact_picture
MessageAdapter.this.mOnContactPictureLongClickedListener .setOnLongClickListener(new OnLongClickListener() {
.onContactPictureLongClicked(message);
return true; @Override
} else { public boolean onLongClick(View v) {
return false; if (MessageAdapter.this.mOnContactPictureLongClickedListener != null) {
} MessageAdapter.this.mOnContactPictureLongClickedListener
.onContactPictureLongClicked(message);
return true;
} else {
return false;
} }
}); }
} });
if (message.getDownloadable() != null && message.getDownloadable().getStatus() != Downloadable.STATUS_UPLOADING) { if (message.getDownloadable() != null && message.getDownloadable().getStatus() != Downloadable.STATUS_UPLOADING) {
Downloadable d = message.getDownloadable(); Downloadable d = message.getDownloadable();
@ -546,7 +546,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
return view; return view;
} }
public void startDonwloadable(Message message) { public void startDownloadable(Message message) {
Downloadable downloadable = message.getDownloadable(); Downloadable downloadable = message.getDownloadable();
if (downloadable != null) { if (downloadable != null) {
if (!downloadable.start()) { if (!downloadable.start()) {
@ -556,7 +556,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
} }
} }
public void openDonwloadable(DownloadableFile file) { public void openDownloadable(DownloadableFile file) {
if (!file.exists()) { if (!file.exists()) {
Toast.makeText(activity,R.string.file_deleted,Toast.LENGTH_SHORT).show(); Toast.makeText(activity,R.string.file_deleted,Toast.LENGTH_SHORT).show();
return; return;