support conversation avatar

This commit is contained in:
Mariotaku Lee 2017-02-13 22:08:28 +08:00
parent b900eedfe5
commit daa0618f26
No known key found for this signature in database
GPG Key ID: 15C10F89D7C33535
15 changed files with 102 additions and 31 deletions

View File

@ -129,6 +129,8 @@ public class DMResponse implements Parcelable {
Message participantsJoin; Message participantsJoin;
@JsonField(name = "conversation_name_update") @JsonField(name = "conversation_name_update")
Message conversationNameUpdate; Message conversationNameUpdate;
@JsonField(name = "conversation_avatar_update")
Message conversationAvatarUpdate;
@JsonField(name = "conversation_read") @JsonField(name = "conversation_read")
Message conversationRead; Message conversationRead;
@JsonField(name = "message_delete") @JsonField(name = "message_delete")
@ -160,6 +162,10 @@ public class DMResponse implements Parcelable {
return conversationNameUpdate; return conversationNameUpdate;
} }
public Message getConversationAvatarUpdate() {
return conversationAvatarUpdate;
}
public Message getConversationRead() { public Message getConversationRead() {
return conversationRead; return conversationRead;
} }
@ -175,7 +181,8 @@ public class DMResponse implements Parcelable {
@Override @Override
public String toString() { public String toString() {
return "Entry{" + return "Entry{" +
"conversationCreate=" + conversationCreate + "conversationAvatarUpdate=" + conversationAvatarUpdate +
", conversationCreate=" + conversationCreate +
", joinConversation=" + joinConversation + ", joinConversation=" + joinConversation +
", message=" + message + ", message=" + message +
", participantsLeave=" + participantsLeave + ", participantsLeave=" + participantsLeave +
@ -183,6 +190,7 @@ public class DMResponse implements Parcelable {
", conversationNameUpdate=" + conversationNameUpdate + ", conversationNameUpdate=" + conversationNameUpdate +
", conversationRead=" + conversationRead + ", conversationRead=" + conversationRead +
", messageDelete=" + messageDelete + ", messageDelete=" + messageDelete +
", removeConversation=" + removeConversation +
'}'; '}';
} }
@ -232,6 +240,9 @@ public class DMResponse implements Parcelable {
@JsonField(name = "conversation_name") @JsonField(name = "conversation_name")
String conversationName; String conversationName;
@JsonField(name = "conversation_avatar_image_https")
String conversationAvatarImageHttps;
@JsonField(name = "request_id") @JsonField(name = "request_id")
String requestId; String requestId;
@ -286,6 +297,10 @@ public class DMResponse implements Parcelable {
return conversationName; return conversationName;
} }
public String getConversationAvatarImageHttps() {
return conversationAvatarImageHttps;
}
public String getByUserId() { public String getByUserId() {
return byUserId; return byUserId;
} }
@ -302,6 +317,7 @@ public class DMResponse implements Parcelable {
", time=" + time + ", time=" + time +
", conversationId='" + conversationId + '\'' + ", conversationId='" + conversationId + '\'' +
", conversationName='" + conversationName + '\'' + ", conversationName='" + conversationName + '\'' +
", conversationAvatarImageHttps='" + conversationAvatarImageHttps + '\'' +
", requestId='" + requestId + '\'' + ", requestId='" + requestId + '\'' +
", senderId='" + senderId + '\'' + ", senderId='" + senderId + '\'' +
", byUserId='" + byUserId + '\'' + ", byUserId='" + byUserId + '\'' +
@ -562,6 +578,9 @@ public class DMResponse implements Parcelable {
@JsonField(name = "name") @JsonField(name = "name")
String name; String name;
@JsonField(name = "avatar_image_https")
String avatarImageHttps;
public String getType() { public String getType() {
return type; return type;
} }
@ -618,6 +637,10 @@ public class DMResponse implements Parcelable {
return name; return name;
} }
public String getAvatarImageHttps() {
return avatarImageHttps;
}
@StringDef({Type.ONE_TO_ONE, Type.GROUP_DM}) @StringDef({Type.ONE_TO_ONE, Type.GROUP_DM})
@Retention(RetentionPolicy.SOURCE) @Retention(RetentionPolicy.SOURCE)
public @interface Type { public @interface Type {

View File

@ -33,7 +33,7 @@ import org.mariotaku.commons.objectcursor.LoganSquareCursorFieldConverter;
import org.mariotaku.library.objectcursor.annotation.CursorField; import org.mariotaku.library.objectcursor.annotation.CursorField;
import org.mariotaku.library.objectcursor.annotation.CursorObject; import org.mariotaku.library.objectcursor.annotation.CursorObject;
import org.mariotaku.twidere.model.message.MessageExtras; import org.mariotaku.twidere.model.message.MessageExtras;
import org.mariotaku.twidere.model.message.NameUpdatedExtras; import org.mariotaku.twidere.model.message.ConversationInfoUpdatedExtras;
import org.mariotaku.twidere.model.message.StickerExtras; import org.mariotaku.twidere.model.message.StickerExtras;
import org.mariotaku.twidere.model.message.UserArrayExtras; import org.mariotaku.twidere.model.message.UserArrayExtras;
import org.mariotaku.twidere.model.util.MessageExtrasConverter; import org.mariotaku.twidere.model.util.MessageExtrasConverter;
@ -161,6 +161,7 @@ public class ParcelableMessage {
String PARTICIPANTS_LEAVE = "participants_leave"; String PARTICIPANTS_LEAVE = "participants_leave";
String PARTICIPANTS_JOIN = "participants_join"; String PARTICIPANTS_JOIN = "participants_join";
String CONVERSATION_NAME_UPDATE = "conversation_name_update"; String CONVERSATION_NAME_UPDATE = "conversation_name_update";
String CONVERSATION_AVATAR_UPDATE = "conversation_avatar_update";
String TEXT = "text"; String TEXT = "text";
String STICKER = "sticker"; String STICKER = "sticker";
} }
@ -169,8 +170,8 @@ public class ParcelableMessage {
static class InternalExtras { static class InternalExtras {
@JsonField(name = "sticker") @JsonField(name = "sticker")
StickerExtras sticker; StickerExtras sticker;
@JsonField(name = "name_updated") @JsonField(name = "info_updated")
NameUpdatedExtras nameUpdated; ConversationInfoUpdatedExtras infoUpdated;
@JsonField(name = "user_array") @JsonField(name = "user_array")
UserArrayExtras userArray; UserArrayExtras userArray;
@ -179,8 +180,8 @@ public class ParcelableMessage {
InternalExtras result = new InternalExtras(); InternalExtras result = new InternalExtras();
if (extras instanceof StickerExtras) { if (extras instanceof StickerExtras) {
result.sticker = (StickerExtras) extras; result.sticker = (StickerExtras) extras;
} else if (extras instanceof NameUpdatedExtras) { } else if (extras instanceof ConversationInfoUpdatedExtras) {
result.nameUpdated = (NameUpdatedExtras) extras; result.infoUpdated = (ConversationInfoUpdatedExtras) extras;
} else if (extras instanceof UserArrayExtras) { } else if (extras instanceof UserArrayExtras) {
result.userArray = (UserArrayExtras) extras; result.userArray = (UserArrayExtras) extras;
} else { } else {
@ -192,8 +193,8 @@ public class ParcelableMessage {
public MessageExtras getExtras() { public MessageExtras getExtras() {
if (sticker != null) { if (sticker != null) {
return sticker; return sticker;
} else if (nameUpdated != null) { } else if (infoUpdated != null) {
return nameUpdated; return infoUpdated;
} else if (userArray != null) { } else if (userArray != null) {
return userArray; return userArray;
} }

View File

@ -72,6 +72,10 @@ public class ParcelableMessageConversation {
@CursorField(Conversations.CONVERSATION_NAME) @CursorField(Conversations.CONVERSATION_NAME)
public String conversation_name; public String conversation_name;
@JsonField(name = "conversation_avatar")
@CursorField(Conversations.CONVERSATION_AVATAR)
public String conversation_avatar;
@ParcelableMessage.MessageType @ParcelableMessage.MessageType
@JsonField(name = "message_type") @JsonField(name = "message_type")
@CursorField(Conversations.MESSAGE_TYPE) @CursorField(Conversations.MESSAGE_TYPE)
@ -167,6 +171,7 @@ public class ParcelableMessageConversation {
", id='" + id + '\'' + ", id='" + id + '\'' +
", conversation_type='" + conversation_type + '\'' + ", conversation_type='" + conversation_type + '\'' +
", conversation_name='" + conversation_name + '\'' + ", conversation_name='" + conversation_name + '\'' +
", conversation_avatar='" + conversation_avatar + '\'' +
", message_type='" + message_type + '\'' + ", message_type='" + message_type + '\'' +
", message_timestamp=" + message_timestamp + ", message_timestamp=" + message_timestamp +
", local_timestamp=" + local_timestamp + ", local_timestamp=" + local_timestamp +
@ -175,9 +180,9 @@ public class ParcelableMessageConversation {
", media=" + Arrays.toString(media) + ", media=" + Arrays.toString(media) +
", spans=" + Arrays.toString(spans) + ", spans=" + Arrays.toString(spans) +
", message_extras=" + message_extras + ", message_extras=" + message_extras +
", conversation_extras_type='" + conversation_extras_type + '\'' +
", conversation_extras=" + conversation_extras + ", conversation_extras=" + conversation_extras +
", participants=" + Arrays.toString(participants) + ", participants=" + Arrays.toString(participants) +
", extras_type='" + conversation_extras_type + '\'' +
", sender_key=" + sender_key + ", sender_key=" + sender_key +
", recipient_key=" + recipient_key + ", recipient_key=" + recipient_key +
", is_outgoing=" + is_outgoing + ", is_outgoing=" + is_outgoing +

View File

@ -36,11 +36,13 @@ import org.mariotaku.twidere.model.ParcelableUser;
@ParcelablePlease @ParcelablePlease
@JsonObject @JsonObject
public class NameUpdatedExtras extends MessageExtras implements Parcelable { public class ConversationInfoUpdatedExtras extends MessageExtras implements Parcelable {
@JsonField(name = "user") @JsonField(name = "user")
ParcelableUser user; ParcelableUser user;
@JsonField(name = "name") @JsonField(name = "name")
String name; String name;
@JsonField(name = "avatar")
String avatar;
public String getName() { public String getName() {
return name; return name;
@ -50,12 +52,19 @@ public class NameUpdatedExtras extends MessageExtras implements Parcelable {
this.name = name; this.name = name;
} }
public String getAvatar() {
return avatar;
}
public void setAvatar(final String avatar) {
this.avatar = avatar;
}
public void setUser(final ParcelableUser user) { public void setUser(final ParcelableUser user) {
this.user = user; this.user = user;
} }
public ParcelableUser getUser() { public ParcelableUser getUser() {
return user; return user;
} }
@ -66,18 +75,18 @@ public class NameUpdatedExtras extends MessageExtras implements Parcelable {
@Override @Override
public void writeToParcel(Parcel dest, int flags) { public void writeToParcel(Parcel dest, int flags) {
NameUpdatedExtrasParcelablePlease.writeToParcel(this, dest, flags); ConversationInfoUpdatedExtrasParcelablePlease.writeToParcel(this, dest, flags);
} }
public static final Creator<NameUpdatedExtras> CREATOR = new Creator<NameUpdatedExtras>() { public static final Creator<ConversationInfoUpdatedExtras> CREATOR = new Creator<ConversationInfoUpdatedExtras>() {
public NameUpdatedExtras createFromParcel(Parcel source) { public ConversationInfoUpdatedExtras createFromParcel(Parcel source) {
NameUpdatedExtras target = new NameUpdatedExtras(); ConversationInfoUpdatedExtras target = new ConversationInfoUpdatedExtras();
NameUpdatedExtrasParcelablePlease.readFromParcel(target, source); ConversationInfoUpdatedExtrasParcelablePlease.readFromParcel(target, source);
return target; return target;
} }
public NameUpdatedExtras[] newArray(int size) { public ConversationInfoUpdatedExtras[] newArray(int size) {
return new NameUpdatedExtras[size]; return new ConversationInfoUpdatedExtras[size];
} }
}; };
} }

View File

@ -48,7 +48,8 @@ public abstract class MessageExtras implements Parcelable {
case MessageType.PARTICIPANTS_JOIN: case MessageType.PARTICIPANTS_JOIN:
return LoganSquare.parse(json, UserArrayExtras.class); return LoganSquare.parse(json, UserArrayExtras.class);
case MessageType.CONVERSATION_NAME_UPDATE: case MessageType.CONVERSATION_NAME_UPDATE:
return LoganSquare.parse(json, NameUpdatedExtras.class); case MessageType.CONVERSATION_AVATAR_UPDATE:
return LoganSquare.parse(json, ConversationInfoUpdatedExtras.class);
} }
return null; return null;
} }

View File

@ -37,6 +37,7 @@ import org.mariotaku.microblog.library.twitter.model.DMResponse;
@ParcelablePlease @ParcelablePlease
@JsonObject @JsonObject
public class TwitterOfficialConversationExtras extends ConversationExtras implements Parcelable { public class TwitterOfficialConversationExtras extends ConversationExtras implements Parcelable {
@JsonField(name = "max_entry_id") @JsonField(name = "max_entry_id")
String maxEntryId; String maxEntryId;
@JsonField(name = "min_entry_id") @JsonField(name = "min_entry_id")

View File

@ -384,6 +384,7 @@ public interface TwidereDataStore {
String CONVERSATION_ID = "conversation_id"; String CONVERSATION_ID = "conversation_id";
String CONVERSATION_TYPE = "conversation_type"; String CONVERSATION_TYPE = "conversation_type";
String CONVERSATION_NAME = "conversation_name"; String CONVERSATION_NAME = "conversation_name";
String CONVERSATION_AVATAR = "conversation_avatar";
String MESSAGE_TYPE = "message_type"; String MESSAGE_TYPE = "message_type";
String MESSAGE_TIMESTAMP = "message_timestamp"; String MESSAGE_TIMESTAMP = "message_timestamp";
String SORT_ID = "sort_id"; String SORT_ID = "sort_id";

View File

@ -34,7 +34,7 @@ import static org.mariotaku.twidere.annotation.PreferenceType.STRING;
public interface Constants extends TwidereConstants { public interface Constants extends TwidereConstants {
String DATABASES_NAME = "twidere.sqlite"; String DATABASES_NAME = "twidere.sqlite";
int DATABASES_VERSION = 172; int DATABASES_VERSION = 173;
int EXTRA_FEATURES_NOTICE_VERSION = 0; int EXTRA_FEATURES_NOTICE_VERSION = 0;

View File

@ -116,7 +116,7 @@ class MessagesConversationAdapter(context: Context) : LoadMoreSupportAdapter<Rec
} }
MessageType.CONVERSATION_CREATE, MessageType.JOIN_CONVERSATION, MessageType.CONVERSATION_CREATE, MessageType.JOIN_CONVERSATION,
MessageType.PARTICIPANTS_LEAVE, MessageType.PARTICIPANTS_JOIN, MessageType.PARTICIPANTS_LEAVE, MessageType.PARTICIPANTS_JOIN,
MessageType.CONVERSATION_NAME_UPDATE -> { MessageType.CONVERSATION_NAME_UPDATE, MessageType.CONVERSATION_AVATAR_UPDATE -> {
return ITEM_TYPE_NOTICE_MESSAGE return ITEM_TYPE_NOTICE_MESSAGE
} }
else -> return ITEM_TYPE_TEXT_MESSAGE else -> return ITEM_TYPE_TEXT_MESSAGE

View File

@ -6,8 +6,8 @@ import org.mariotaku.twidere.model.ParcelableMessage
import org.mariotaku.twidere.model.ParcelableMessage.MessageType import org.mariotaku.twidere.model.ParcelableMessage.MessageType
import org.mariotaku.twidere.model.ParcelableMessageConversation import org.mariotaku.twidere.model.ParcelableMessageConversation
import org.mariotaku.twidere.model.UserKey import org.mariotaku.twidere.model.UserKey
import org.mariotaku.twidere.model.message.ConversationInfoUpdatedExtras
import org.mariotaku.twidere.model.message.MessageExtras import org.mariotaku.twidere.model.message.MessageExtras
import org.mariotaku.twidere.model.message.NameUpdatedExtras
import org.mariotaku.twidere.model.message.UserArrayExtras import org.mariotaku.twidere.model.message.UserArrayExtras
import org.mariotaku.twidere.util.UserColorNameManager import org.mariotaku.twidere.util.UserColorNameManager
@ -65,7 +65,7 @@ internal fun getSummaryText(context: Context, manager: UserColorNameManager, nam
} }
} }
MessageType.CONVERSATION_NAME_UPDATE -> { MessageType.CONVERSATION_NAME_UPDATE -> {
extras as NameUpdatedExtras extras as ConversationInfoUpdatedExtras
val res = context.resources val res = context.resources
if (extras.user != null) { if (extras.user != null) {
return res.getString(R.string.message_format_conversation_name_update_by_user, return res.getString(R.string.message_format_conversation_name_update_by_user,
@ -74,6 +74,16 @@ internal fun getSummaryText(context: Context, manager: UserColorNameManager, nam
return res.getString(R.string.message_format_conversation_name_update, extras.name) return res.getString(R.string.message_format_conversation_name_update, extras.name)
} }
} }
MessageType.CONVERSATION_AVATAR_UPDATE -> {
extras as ConversationInfoUpdatedExtras
val res = context.resources
if (extras.user != null) {
return res.getString(R.string.message_format_conversation_avatar_update_by_user,
manager.getDisplayName(extras.user, nameFirst))
} else {
return res.getString(R.string.message_format_conversation_avatar_update)
}
}
} }
return text return text
} }

View File

@ -11,8 +11,8 @@ import org.mariotaku.twidere.model.ParcelableMedia
import org.mariotaku.twidere.model.ParcelableMessage import org.mariotaku.twidere.model.ParcelableMessage
import org.mariotaku.twidere.model.ParcelableMessage.MessageType import org.mariotaku.twidere.model.ParcelableMessage.MessageType
import org.mariotaku.twidere.model.UserKey import org.mariotaku.twidere.model.UserKey
import org.mariotaku.twidere.model.message.ConversationInfoUpdatedExtras
import org.mariotaku.twidere.model.message.MessageExtras import org.mariotaku.twidere.model.message.MessageExtras
import org.mariotaku.twidere.model.message.NameUpdatedExtras
import org.mariotaku.twidere.model.message.StickerExtras import org.mariotaku.twidere.model.message.StickerExtras
import org.mariotaku.twidere.model.message.UserArrayExtras import org.mariotaku.twidere.model.message.UserArrayExtras
import org.mariotaku.twidere.util.InternalTwitterContentUtils import org.mariotaku.twidere.util.InternalTwitterContentUtils
@ -60,7 +60,14 @@ object ParcelableMessageUtils {
} }
entry.conversationNameUpdate != null -> { entry.conversationNameUpdate != null -> {
return ParcelableMessage().apply { return ParcelableMessage().apply {
applyNameUpdatedEvent(accountKey, entry.conversationNameUpdate, users) applyInfoUpdatedEvent(accountKey, entry.conversationNameUpdate, users,
MessageType.CONVERSATION_NAME_UPDATE)
}
}
entry.conversationAvatarUpdate != null -> {
return ParcelableMessage().apply {
applyInfoUpdatedEvent(accountKey, entry.conversationAvatarUpdate, users,
MessageType.CONVERSATION_AVATAR_UPDATE)
} }
} }
} }
@ -107,12 +114,13 @@ object ParcelableMessageUtils {
this.is_outgoing = false this.is_outgoing = false
} }
private fun ParcelableMessage.applyNameUpdatedEvent(accountKey: UserKey, message: Message, private fun ParcelableMessage.applyInfoUpdatedEvent(accountKey: UserKey, message: Message,
users: Map<String, User>) { users: Map<String, User>, @MessageType type: String) {
this.commonEntry(accountKey, message) this.commonEntry(accountKey, message)
this.message_type = MessageType.CONVERSATION_NAME_UPDATE this.message_type = type
this.extras = NameUpdatedExtras().apply { this.extras = ConversationInfoUpdatedExtras().apply {
this.name = message.conversationName this.name = message.conversationName
this.avatar = message.conversationAvatarImageHttps
this.user = users[message.byUserId]?.convert { ParcelableUserUtils.fromUser(it, accountKey) } this.user = users[message.byUserId]?.convert { ParcelableUserUtils.fromUser(it, accountKey) }
} }
this.is_outgoing = false this.is_outgoing = false

View File

@ -217,6 +217,7 @@ class GetMessagesTask(
val conversation = conversations.addConversation(k, details, message, participants, val conversation = conversations.addConversation(k, details, message, participants,
conversationType) conversationType)
conversation.conversation_name = v.name conversation.conversation_name = v.name
conversation.conversation_avatar = v.avatarImageHttps
conversation.request_cursor = response.cursor conversation.request_cursor = response.cursor
conversation.conversation_extras_type = ParcelableMessageConversation.ExtrasType.TWITTER_OFFICIAL conversation.conversation_extras_type = ParcelableMessageConversation.ExtrasType.TWITTER_OFFICIAL
conversation.conversation_extras = TwitterOfficialConversationExtras().apply { conversation.conversation_extras = TwitterOfficialConversationExtras().apply {

View File

@ -56,6 +56,11 @@ class MediaLoaderWrapper(val imageLoader: ImageLoader) {
.bitmapConfig(Bitmap.Config.RGB_565) .bitmapConfig(Bitmap.Config.RGB_565)
.build() .build()
private val groupConversationAvatarDisplayOptions = DisplayImageOptions.Builder()
.cloneFrom(profileImageDisplayOptions)
.showImageForEmptyUri(R.drawable.ic_profile_image_default_group)
.build()
private val dashboardProfileImageDisplayOptions = DisplayImageOptions.Builder() private val dashboardProfileImageDisplayOptions = DisplayImageOptions.Builder()
.cacheInMemory(true) .cacheInMemory(true)
.cacheOnDisk(true) .cacheOnDisk(true)
@ -176,6 +181,10 @@ class MediaLoaderWrapper(val imageLoader: ImageLoader) {
imageLoader.displayImage(url, view, profileImageDisplayOptions) imageLoader.displayImage(url, view, profileImageDisplayOptions)
} }
fun displayGroupConversationAvatar(view: ImageView, url: String?) {
imageLoader.displayImage(url, view, groupConversationAvatarDisplayOptions)
}
fun loadImageSync(url: String, targetImageSize: ImageSize, options: DisplayImageOptions): Bitmap? { fun loadImageSync(url: String, targetImageSize: ImageSize, options: DisplayImageOptions): Bitmap? {
return imageLoader.loadImageSync(url, targetImageSize, options) return imageLoader.loadImageSync(url, targetImageSize, options)
} }

View File

@ -77,8 +77,7 @@ class MessageEntryViewHolder(itemView: View, val adapter: MessagesEntriesAdapter
// TODO display default profile image // TODO display default profile image
} }
} else { } else {
adapter.mediaLoader.cancelDisplayTask(profileImage) adapter.mediaLoader.displayGroupConversationAvatar(profileImage, conversation.conversation_avatar)
profileImage.setImageResource(R.drawable.ic_profile_image_default_group)
} }
} }

View File

@ -669,6 +669,9 @@
<string name="message_direct_message_deleted">Direct message deleted.</string> <string name="message_direct_message_deleted">Direct message deleted.</string>
<string name="message_direct_message_sent">Direct message sent.</string> <string name="message_direct_message_sent">Direct message sent.</string>
<string name="message_error_invalid_account">Some account data are corrupted, Twidere will remove those accounts to prevent crash.</string> <string name="message_error_invalid_account">Some account data are corrupted, Twidere will remove those accounts to prevent crash.</string>
<string name="message_format_conversation_avatar_update">Conversation avatar changed</string>
<string name="message_format_conversation_avatar_update_by_user">
<xliff:g example="User" id="by_user">%1$s</xliff:g> changed conversation avatar</string>
<string <string
name="message_format_conversation_name_update">Conversation name changed to name="message_format_conversation_name_update">Conversation name changed to
<xliff:g <xliff:g