Remove ID-dependency from stub-avatar generation (unnecessary and complicated as contact and group IDs differ while both may describe a chat with the same user and use the same title).

This commit is contained in:
B. Petersen
2016-10-23 22:24:49 +02:00
parent cf5871c663
commit 100e155b75
7 changed files with 43 additions and 15 deletions
@@ -106,7 +106,7 @@ public class ChatActionCell extends BaseCell {
}
}
}
avatarDrawable.setInfo(id, null, null, false);
avatarDrawable.setInfo(null, null, false);
if (currentMessageObject.messageOwner.action instanceof TLRPC.TL_messageActionUserUpdatedPhoto) {
imageReceiver.setImage(currentMessageObject.messageOwner.action.newUserPhoto.photo_small, "50_50", avatarDrawable, null, false);
} else {
@@ -3886,8 +3886,16 @@ public class ChatMessageCell extends BaseCell implements SeekBar.SeekBarDelegate
currentChat = MessagesController.getInstance().getChat(currentMessageObject.messageOwner.to_id.channel_id);
}
String cname = "";
if(currentUser!=null && isChat) {
long hContact = MrMailbox.MrMailboxGetContactById(MrMailbox.hMailbox, currentUser.id);
cname = MrMailbox.MrContactGetDisplayName(hContact);
MrMailbox.MrContactUnref(hContact);
}
if (isChat && !messageObject.isOutOwner() && messageObject.isFromUser()) {
isAvatarVisible = true;
/*
if (currentUser != null) {
if (currentUser.photo != null) {
currentPhoto = currentUser.photo.photo_small;
@@ -3906,6 +3914,10 @@ public class ChatMessageCell extends BaseCell implements SeekBar.SeekBarDelegate
currentPhoto = null;
avatarDrawable.setInfo(messageObject.messageOwner.from_id, null, null, false);
}
*/
// MrAvatar ...
avatarDrawable.setInfo(cname, null, false);
avatarImage.setImage(currentPhoto, "50_50", avatarDrawable, null, false);
}
@@ -3944,9 +3956,7 @@ public class ChatMessageCell extends BaseCell implements SeekBar.SeekBarDelegate
if (authorName) {
if (currentUser != null) {
// EDIT BY MR
long hContact= MrMailbox.MrMailboxGetContactById(MrMailbox.hMailbox, currentUser.id);
currentNameString = MrMailbox.MrContactGetDisplayName(hContact);
MrMailbox.MrContactUnref(hContact);
currentNameString = cname;
// /EDIT BY MR
} else if (currentChat != null) {
currentNameString = currentChat.title;
@@ -945,8 +945,10 @@ public class DialogCell extends BaseCell {
avatarDrawable.setInfo(chat);
}
*/
// MrAvatar
String cname = MrMailbox.MrChatGetName(m_hChat);
avatarDrawable.setInfo(MrMailbox.MrChatGetId(m_hChat), cname, null, false); // TODO: read photos from address book
avatarDrawable.setInfo(cname, null, false);
avatarImage.setImage(photo, "50_50", avatarDrawable, null, false);
@@ -416,7 +416,7 @@ public class ProfileSearchCell extends BaseCell {
}
avatarDrawable.setInfo(chat);
} else {
avatarDrawable.setInfo(0, null, null, false);
avatarDrawable.setInfo(null, null, false);
}
if (mask != 0) {
@@ -31,7 +31,7 @@ public class AvatarDrawable extends Drawable {
private static Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
private static TextPaint namePaint;
private static TextPaint namePaintSmall;
private static int[] arrColors = {0xffe56555, 0xfff28c48, 0xff8e85ee, 0xff76c84d, 0xff5fbed5, 0xff549cdd, 0xff8e85ee, 0xfff2749a};
private static int[] arrColors = {0xffe56555, 0xfff28c48, 0xff8e85ee, 0xff76c84d, 0xff5fbed5, 0xff549cdd, 0xff8e85ee, 0xff8cdc99};
private static int[] arrColorsProfiles = {0xffd86f65, 0xfff69d61, 0xff8c79d2, 0xff67b35d, 0xff56a2bb, Theme.ACTION_BAR_MAIN_AVATAR_COLOR, 0xff8c79d2, 0xfff37fa6};
private static int[] arrColorsProfilesBack = {Theme.ACTION_BAR_PROFILE_COLOR, Theme.ACTION_BAR_PROFILE_COLOR, Theme.ACTION_BAR_PROFILE_COLOR, Theme.ACTION_BAR_PROFILE_COLOR, Theme.ACTION_BAR_PROFILE_COLOR, Theme.ACTION_BAR_PROFILE_COLOR, Theme.ACTION_BAR_PROFILE_COLOR, Theme.ACTION_BAR_PROFILE_COLOR};
private static int[] arrColorsProfilesText = {0xfff9cbc5, 0xfffdddc8, 0xffcdc4ed, 0xffc0edba, 0xffb8e2f0, Theme.ACTION_BAR_PROFILE_SUBTITLE_COLOR, 0xffcdc4ed, 0xffb3d7f7};
@@ -81,7 +81,7 @@ public class AvatarDrawable extends Drawable {
this();
isProfile = profile;
if (user != null) {
setInfo(user.id, user.first_name, user.last_name, false);
setInfo(user.first_name, user.last_name, false);
}
}
@@ -89,7 +89,7 @@ public class AvatarDrawable extends Drawable {
this();
isProfile = profile;
if (chat != null) {
setInfo(chat.id, chat.title, null, chat.id < 0);
setInfo(chat.title, null, chat.id < 0);
}
}
@@ -154,13 +154,13 @@ public class AvatarDrawable extends Drawable {
public void setInfo(TLRPC.User user) {
if (user != null) {
setInfo(user.id, user.first_name, user.last_name, false);
setInfo(user.first_name, user.last_name, false);
}
}
public void setInfo(TLRPC.Chat chat) {
if (chat != null) {
setInfo(chat.id, chat.title, null, chat.id < 0);
setInfo(chat.title, null, chat.id < 0);
}
}
@@ -168,7 +168,21 @@ public class AvatarDrawable extends Drawable {
color = value;
}
public void setInfo(int id, String firstName, String lastName, boolean isBroadcast) {
private int strChecksum(String str) {
int ret = 0;
if( str!=null ) {
int i;
for (i = 0; i < str.length(); i++) {
ret += (i+1)*str.charAt(i);
ret %= 0x00FFFFFF;
}
}
return ret;
}
public void setInfo(String firstName, String lastName, boolean isBroadcast) {
int id = strChecksum(firstName) + strChecksum(lastName);
if (isProfile) {
color = arrColorsProfiles[getColorIndex(id)];
} else {
@@ -297,7 +297,9 @@ public class ChatAvatarContainer extends FrameLayout {
avatarDrawable.setInfo(chat);
}
*/
avatarDrawable.setInfo(MrMailbox.MrChatGetId(parentFragment.m_hChat), MrMailbox.MrChatGetName(parentFragment.m_hChat), null, false); // EDIT BY MR
// MrAvatar ...
avatarDrawable.setInfo(MrMailbox.MrChatGetName(parentFragment.m_hChat), null, false);
if (avatarImageView != null) {
avatarImageView.setImage(newPhoto, "50_50", avatarDrawable);
@@ -212,7 +212,7 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati
avatarImage = new BackupImageView(context);
avatarImage.setRoundRadius(AndroidUtilities.dp(32));
avatarDrawable.setInfo(5, null, null, chatType == ChatObject.CHAT_TYPE_BROADCAST);
avatarDrawable.setInfo(null, null, chatType == ChatObject.CHAT_TYPE_BROADCAST);
avatarImage.setImageDrawable(avatarDrawable);
frameLayout.addView(avatarImage);
FrameLayout.LayoutParams layoutParams1 = (FrameLayout.LayoutParams) avatarImage.getLayoutParams();
@@ -301,7 +301,7 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati
@Override
public void afterTextChanged(Editable s) {
avatarDrawable.setInfo(5, nameTextView.length() > 0 ? nameTextView.getText().toString() : null, null, false);
avatarDrawable.setInfo(nameTextView.length() > 0 ? nameTextView.getText().toString() : null, null, false);
avatarImage.invalidate();
}
});