refactored the message adapter a bit
This commit is contained in:
parent
be358b77d6
commit
aaeba697bd
|
@ -25,6 +25,7 @@ import java.util.List;
|
||||||
|
|
||||||
import eu.siacs.conversations.Config;
|
import eu.siacs.conversations.Config;
|
||||||
import eu.siacs.conversations.R;
|
import eu.siacs.conversations.R;
|
||||||
|
import eu.siacs.conversations.entities.Account;
|
||||||
import eu.siacs.conversations.entities.Contact;
|
import eu.siacs.conversations.entities.Contact;
|
||||||
import eu.siacs.conversations.entities.Conversation;
|
import eu.siacs.conversations.entities.Conversation;
|
||||||
import eu.siacs.conversations.entities.Downloadable;
|
import eu.siacs.conversations.entities.Downloadable;
|
||||||
|
@ -339,7 +340,9 @@ public class MessageAdapter extends ArrayAdapter<Message> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View getView(int position, View view, ViewGroup parent) {
|
public View getView(int position, View view, ViewGroup parent) {
|
||||||
final Message item = getItem(position);
|
final Message message = getItem(position);
|
||||||
|
final Conversation conversation = message.getConversation();
|
||||||
|
final Account account = conversation.getAccount();
|
||||||
int type = getItemViewType(position);
|
int type = getItemViewType(position);
|
||||||
ViewHolder viewHolder;
|
ViewHolder viewHolder;
|
||||||
if (view == null) {
|
if (view == null) {
|
||||||
|
@ -407,10 +410,9 @@ public class MessageAdapter extends ArrayAdapter<Message> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type == STATUS) {
|
if (type == STATUS) {
|
||||||
if (item.getConversation().getMode() == Conversation.MODE_SINGLE) {
|
if (conversation.getMode() == Conversation.MODE_SINGLE) {
|
||||||
viewHolder.contact_picture.setImageBitmap(activity
|
viewHolder.contact_picture.setImageBitmap(activity
|
||||||
.avatarService().get(
|
.avatarService().get(conversation.getContact(),
|
||||||
item.getConversation().getContact(),
|
|
||||||
activity.getPixel(32)));
|
activity.getPixel(32)));
|
||||||
viewHolder.contact_picture.setAlpha(0.5f);
|
viewHolder.contact_picture.setAlpha(0.5f);
|
||||||
viewHolder.contact_picture
|
viewHolder.contact_picture
|
||||||
|
@ -418,8 +420,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
String name = item.getConversation()
|
String name = conversation.getName();
|
||||||
.getName();
|
|
||||||
String read = getContext()
|
String read = getContext()
|
||||||
.getString(
|
.getString(
|
||||||
R.string.contact_has_read_up_to_this_point,
|
R.string.contact_has_read_up_to_this_point,
|
||||||
|
@ -441,15 +442,15 @@ public class MessageAdapter extends ArrayAdapter<Message> {
|
||||||
view.setLayoutParams(view.getLayoutParams());
|
view.setLayoutParams(view.getLayoutParams());
|
||||||
return view;
|
return view;
|
||||||
} else if (type == RECEIVED) {
|
} else if (type == RECEIVED) {
|
||||||
Contact contact = item.getContact();
|
Contact contact = message.getContact();
|
||||||
if (contact != null) {
|
if (contact != null) {
|
||||||
viewHolder.contact_picture.setImageBitmap(activity.avatarService().get(contact, activity.getPixel(48)));
|
viewHolder.contact_picture.setImageBitmap(activity.avatarService().get(contact, activity.getPixel(48)));
|
||||||
} else if (item.getConversation().getMode() == Conversation.MODE_MULTI) {
|
} else if (conversation.getMode() == Conversation.MODE_MULTI) {
|
||||||
viewHolder.contact_picture.setImageBitmap(activity.avatarService().get(getDisplayedMucCounterpart(item.getCounterpart()),
|
viewHolder.contact_picture.setImageBitmap(activity.avatarService().get(getDisplayedMucCounterpart(message.getCounterpart()),
|
||||||
activity.getPixel(48)));
|
activity.getPixel(48)));
|
||||||
}
|
}
|
||||||
} else if (type == SENT) {
|
} else if (type == SENT && viewHolder.contact_picture != null) {
|
||||||
viewHolder.contact_picture.setImageBitmap(activity.avatarService().get(item.getConversation().getAccount(), activity.getPixel(48)));
|
viewHolder.contact_picture.setImageBitmap(activity.avatarService().get(account, activity.getPixel(48)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (viewHolder != null && viewHolder.contact_picture != null) {
|
if (viewHolder != null && viewHolder.contact_picture != null) {
|
||||||
|
@ -460,7 +461,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
if (MessageAdapter.this.mOnContactPictureClickedListener != null) {
|
if (MessageAdapter.this.mOnContactPictureClickedListener != null) {
|
||||||
MessageAdapter.this.mOnContactPictureClickedListener
|
MessageAdapter.this.mOnContactPictureClickedListener
|
||||||
.onContactPictureClicked(item);
|
.onContactPictureClicked(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -472,7 +473,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
|
||||||
public boolean onLongClick(View v) {
|
public boolean onLongClick(View v) {
|
||||||
if (MessageAdapter.this.mOnContactPictureLongClickedListener != null) {
|
if (MessageAdapter.this.mOnContactPictureLongClickedListener != null) {
|
||||||
MessageAdapter.this.mOnContactPictureLongClickedListener
|
MessageAdapter.this.mOnContactPictureLongClickedListener
|
||||||
.onContactPictureLongClicked(item);
|
.onContactPictureLongClicked(message);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
@ -481,10 +482,10 @@ public class MessageAdapter extends ArrayAdapter<Message> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item.getDownloadable() != null && item.getDownloadable().getStatus() != Downloadable.STATUS_UPLOADING) {
|
if (message.getDownloadable() != null && message.getDownloadable().getStatus() != Downloadable.STATUS_UPLOADING) {
|
||||||
Downloadable d = item.getDownloadable();
|
Downloadable d = message.getDownloadable();
|
||||||
if (d.getStatus() == Downloadable.STATUS_DOWNLOADING) {
|
if (d.getStatus() == Downloadable.STATUS_DOWNLOADING) {
|
||||||
if (item.getType() == Message.TYPE_FILE) {
|
if (message.getType() == Message.TYPE_FILE) {
|
||||||
displayInfoMessage(viewHolder,activity.getString(R.string.receiving_file,d.getMimeType(),d.getProgress()));
|
displayInfoMessage(viewHolder,activity.getString(R.string.receiving_file,d.getMimeType(),d.getProgress()));
|
||||||
} else {
|
} else {
|
||||||
displayInfoMessage(viewHolder,activity.getString(R.string.receiving_image,d.getProgress()));
|
displayInfoMessage(viewHolder,activity.getString(R.string.receiving_image,d.getProgress()));
|
||||||
|
@ -492,35 +493,35 @@ public class MessageAdapter extends ArrayAdapter<Message> {
|
||||||
} else if (d.getStatus() == Downloadable.STATUS_CHECKING) {
|
} else if (d.getStatus() == Downloadable.STATUS_CHECKING) {
|
||||||
displayInfoMessage(viewHolder,activity.getString(R.string.checking_image));
|
displayInfoMessage(viewHolder,activity.getString(R.string.checking_image));
|
||||||
} else if (d.getStatus() == Downloadable.STATUS_DELETED) {
|
} else if (d.getStatus() == Downloadable.STATUS_DELETED) {
|
||||||
if (item.getType() == Message.TYPE_FILE) {
|
if (message.getType() == Message.TYPE_FILE) {
|
||||||
displayInfoMessage(viewHolder, activity.getString(R.string.file_deleted));
|
displayInfoMessage(viewHolder, activity.getString(R.string.file_deleted));
|
||||||
} else {
|
} else {
|
||||||
displayInfoMessage(viewHolder, activity.getString(R.string.image_file_deleted));
|
displayInfoMessage(viewHolder, activity.getString(R.string.image_file_deleted));
|
||||||
}
|
}
|
||||||
} else if (d.getStatus() == Downloadable.STATUS_OFFER) {
|
} else if (d.getStatus() == Downloadable.STATUS_OFFER) {
|
||||||
if (item.getType() == Message.TYPE_FILE) {
|
if (message.getType() == Message.TYPE_FILE) {
|
||||||
displayDownloadableMessage(viewHolder,item,activity.getString(R.string.download_file,d.getMimeType()));
|
displayDownloadableMessage(viewHolder,message,activity.getString(R.string.download_file,d.getMimeType()));
|
||||||
} else {
|
} else {
|
||||||
displayDownloadableMessage(viewHolder, item,activity.getString(R.string.download_image));
|
displayDownloadableMessage(viewHolder, message,activity.getString(R.string.download_image));
|
||||||
}
|
}
|
||||||
} else if (d.getStatus() == Downloadable.STATUS_OFFER_CHECK_FILESIZE) {
|
} else if (d.getStatus() == Downloadable.STATUS_OFFER_CHECK_FILESIZE) {
|
||||||
displayDownloadableMessage(viewHolder, item,activity.getString(R.string.check_image_filesize));
|
displayDownloadableMessage(viewHolder, message,activity.getString(R.string.check_image_filesize));
|
||||||
} else if (d.getStatus() == Downloadable.STATUS_FAILED) {
|
} else if (d.getStatus() == Downloadable.STATUS_FAILED) {
|
||||||
if (item.getType() == Message.TYPE_FILE) {
|
if (message.getType() == Message.TYPE_FILE) {
|
||||||
displayInfoMessage(viewHolder, activity.getString(R.string.file_transmission_failed));
|
displayInfoMessage(viewHolder, activity.getString(R.string.file_transmission_failed));
|
||||||
} else {
|
} else {
|
||||||
displayInfoMessage(viewHolder, activity.getString(R.string.image_transmission_failed));
|
displayInfoMessage(viewHolder, activity.getString(R.string.image_transmission_failed));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (item.getType() == Message.TYPE_IMAGE && item.getEncryption() != Message.ENCRYPTION_PGP && item.getEncryption() != Message.ENCRYPTION_DECRYPTION_FAILED) {
|
} else if (message.getType() == Message.TYPE_IMAGE && message.getEncryption() != Message.ENCRYPTION_PGP && message.getEncryption() != Message.ENCRYPTION_DECRYPTION_FAILED) {
|
||||||
displayImageMessage(viewHolder, item);
|
displayImageMessage(viewHolder, message);
|
||||||
} else if (item.getType() == Message.TYPE_FILE && item.getEncryption() != Message.ENCRYPTION_PGP && item.getEncryption() != Message.ENCRYPTION_DECRYPTION_FAILED) {
|
} else if (message.getType() == Message.TYPE_FILE && message.getEncryption() != Message.ENCRYPTION_PGP && message.getEncryption() != Message.ENCRYPTION_DECRYPTION_FAILED) {
|
||||||
if (item.getImageParams().width > 0) {
|
if (message.getImageParams().width > 0) {
|
||||||
displayImageMessage(viewHolder,item);
|
displayImageMessage(viewHolder,message);
|
||||||
} else {
|
} else {
|
||||||
displayOpenableMessage(viewHolder, item);
|
displayOpenableMessage(viewHolder, message);
|
||||||
}
|
}
|
||||||
} else if (item.getEncryption() == Message.ENCRYPTION_PGP) {
|
} else if (message.getEncryption() == Message.ENCRYPTION_PGP) {
|
||||||
if (activity.hasPgp()) {
|
if (activity.hasPgp()) {
|
||||||
displayInfoMessage(viewHolder,activity.getString(R.string.encrypted_message));
|
displayInfoMessage(viewHolder,activity.getString(R.string.encrypted_message));
|
||||||
} else {
|
} else {
|
||||||
|
@ -537,13 +538,13 @@ public class MessageAdapter extends ArrayAdapter<Message> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (item.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED) {
|
} else if (message.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED) {
|
||||||
displayDecryptionFailed(viewHolder);
|
displayDecryptionFailed(viewHolder);
|
||||||
} else {
|
} else {
|
||||||
displayTextMessage(viewHolder, item);
|
displayTextMessage(viewHolder, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
displayStatus(viewHolder, item);
|
displayStatus(viewHolder, message);
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue