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;
@JsonField(name = "conversation_name_update")
Message conversationNameUpdate;
@JsonField(name = "conversation_avatar_update")
Message conversationAvatarUpdate;
@JsonField(name = "conversation_read")
Message conversationRead;
@JsonField(name = "message_delete")
@ -160,6 +162,10 @@ public class DMResponse implements Parcelable {
return conversationNameUpdate;
}
public Message getConversationAvatarUpdate() {
return conversationAvatarUpdate;
}
public Message getConversationRead() {
return conversationRead;
}
@ -175,7 +181,8 @@ public class DMResponse implements Parcelable {
@Override
public String toString() {
return "Entry{" +
"conversationCreate=" + conversationCreate +
"conversationAvatarUpdate=" + conversationAvatarUpdate +
", conversationCreate=" + conversationCreate +
", joinConversation=" + joinConversation +
", message=" + message +
", participantsLeave=" + participantsLeave +
@ -183,6 +190,7 @@ public class DMResponse implements Parcelable {
", conversationNameUpdate=" + conversationNameUpdate +
", conversationRead=" + conversationRead +
", messageDelete=" + messageDelete +
", removeConversation=" + removeConversation +
'}';
}
@ -232,6 +240,9 @@ public class DMResponse implements Parcelable {
@JsonField(name = "conversation_name")
String conversationName;
@JsonField(name = "conversation_avatar_image_https")
String conversationAvatarImageHttps;
@JsonField(name = "request_id")
String requestId;
@ -286,6 +297,10 @@ public class DMResponse implements Parcelable {
return conversationName;
}
public String getConversationAvatarImageHttps() {
return conversationAvatarImageHttps;
}
public String getByUserId() {
return byUserId;
}
@ -302,6 +317,7 @@ public class DMResponse implements Parcelable {
", time=" + time +
", conversationId='" + conversationId + '\'' +
", conversationName='" + conversationName + '\'' +
", conversationAvatarImageHttps='" + conversationAvatarImageHttps + '\'' +
", requestId='" + requestId + '\'' +
", senderId='" + senderId + '\'' +
", byUserId='" + byUserId + '\'' +
@ -562,6 +578,9 @@ public class DMResponse implements Parcelable {
@JsonField(name = "name")
String name;
@JsonField(name = "avatar_image_https")
String avatarImageHttps;
public String getType() {
return type;
}
@ -618,6 +637,10 @@ public class DMResponse implements Parcelable {
return name;
}
public String getAvatarImageHttps() {
return avatarImageHttps;
}
@StringDef({Type.ONE_TO_ONE, Type.GROUP_DM})
@Retention(RetentionPolicy.SOURCE)
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.CursorObject;
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.UserArrayExtras;
import org.mariotaku.twidere.model.util.MessageExtrasConverter;
@ -161,6 +161,7 @@ public class ParcelableMessage {
String PARTICIPANTS_LEAVE = "participants_leave";
String PARTICIPANTS_JOIN = "participants_join";
String CONVERSATION_NAME_UPDATE = "conversation_name_update";
String CONVERSATION_AVATAR_UPDATE = "conversation_avatar_update";
String TEXT = "text";
String STICKER = "sticker";
}
@ -169,8 +170,8 @@ public class ParcelableMessage {
static class InternalExtras {
@JsonField(name = "sticker")
StickerExtras sticker;
@JsonField(name = "name_updated")
NameUpdatedExtras nameUpdated;
@JsonField(name = "info_updated")
ConversationInfoUpdatedExtras infoUpdated;
@JsonField(name = "user_array")
UserArrayExtras userArray;
@ -179,8 +180,8 @@ public class ParcelableMessage {
InternalExtras result = new InternalExtras();
if (extras instanceof StickerExtras) {
result.sticker = (StickerExtras) extras;
} else if (extras instanceof NameUpdatedExtras) {
result.nameUpdated = (NameUpdatedExtras) extras;
} else if (extras instanceof ConversationInfoUpdatedExtras) {
result.infoUpdated = (ConversationInfoUpdatedExtras) extras;
} else if (extras instanceof UserArrayExtras) {
result.userArray = (UserArrayExtras) extras;
} else {
@ -192,8 +193,8 @@ public class ParcelableMessage {
public MessageExtras getExtras() {
if (sticker != null) {
return sticker;
} else if (nameUpdated != null) {
return nameUpdated;
} else if (infoUpdated != null) {
return infoUpdated;
} else if (userArray != null) {
return userArray;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -34,7 +34,7 @@ import static org.mariotaku.twidere.annotation.PreferenceType.STRING;
public interface Constants extends TwidereConstants {
String DATABASES_NAME = "twidere.sqlite";
int DATABASES_VERSION = 172;
int DATABASES_VERSION = 173;
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.PARTICIPANTS_LEAVE, MessageType.PARTICIPANTS_JOIN,
MessageType.CONVERSATION_NAME_UPDATE -> {
MessageType.CONVERSATION_NAME_UPDATE, MessageType.CONVERSATION_AVATAR_UPDATE -> {
return ITEM_TYPE_NOTICE_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.ParcelableMessageConversation
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.NameUpdatedExtras
import org.mariotaku.twidere.model.message.UserArrayExtras
import org.mariotaku.twidere.util.UserColorNameManager
@ -65,7 +65,7 @@ internal fun getSummaryText(context: Context, manager: UserColorNameManager, nam
}
}
MessageType.CONVERSATION_NAME_UPDATE -> {
extras as NameUpdatedExtras
extras as ConversationInfoUpdatedExtras
val res = context.resources
if (extras.user != null) {
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)
}
}
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
}

View File

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

View File

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

View File

@ -56,6 +56,11 @@ class MediaLoaderWrapper(val imageLoader: ImageLoader) {
.bitmapConfig(Bitmap.Config.RGB_565)
.build()
private val groupConversationAvatarDisplayOptions = DisplayImageOptions.Builder()
.cloneFrom(profileImageDisplayOptions)
.showImageForEmptyUri(R.drawable.ic_profile_image_default_group)
.build()
private val dashboardProfileImageDisplayOptions = DisplayImageOptions.Builder()
.cacheInMemory(true)
.cacheOnDisk(true)
@ -176,6 +181,10 @@ class MediaLoaderWrapper(val imageLoader: ImageLoader) {
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? {
return imageLoader.loadImageSync(url, targetImageSize, options)
}

View File

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

View File

@ -669,6 +669,9 @@
<string name="message_direct_message_deleted">Direct message deleted.</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_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
name="message_format_conversation_name_update">Conversation name changed to
<xliff:g