Skip to content

Commit ec81aad

Browse files
committed
更改:
1、只允许数字、英文字符和中文字符被转化为群友头像; 2、增加四个emoji。
1 parent 8e4879e commit ec81aad

File tree

4 files changed

+30
-14
lines changed

4 files changed

+30
-14
lines changed

src/main/java/com/oasisfeng/nevo/decorators/wechat/ConversationManager.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
import android.text.TextUtils;
44
import android.util.ArrayMap;
5+
import android.util.Log;
56
import android.util.SparseArray;
67

78
import java.lang.annotation.Retention;
89
import java.lang.annotation.RetentionPolicy;
910
import java.util.Map;
11+
import java.util.regex.Pattern;
1012

1113
import androidx.annotation.IntDef;
1214
import androidx.annotation.Nullable;
@@ -32,6 +34,7 @@ static class Conversation {
3234
@IntDef({ TYPE_UNKNOWN, TYPE_DIRECT_MESSAGE, TYPE_GROUP_CHAT, TYPE_BOT_MESSAGE }) @Retention(RetentionPolicy.SOURCE) @interface ConversationType {}
3335

3436
private static final String SCHEME_ORIGINAL_NAME = "ON:";
37+
private static final Pattern pattern = Pattern.compile("^[a-zA-Z0-9\\u4e00-\\u9fa5]");
3538

3639
final int id;
3740
@Nullable String key;
@@ -71,7 +74,16 @@ Person getGroupParticipant(final String key, final String name) {
7174
if (participant == null) builder = new Person.Builder().setKey(key);
7275
else if (! TextUtils.equals(name, requireNonNull(participant.getUri()).substring(SCHEME_ORIGINAL_NAME.length()))) // Original name is changed
7376
builder = participant.toBuilder();
74-
if (builder != null) mParticipants.put(key, participant = builder.setUri(SCHEME_ORIGINAL_NAME + name).setName(EmojiTranslator.translate(name)).build());
77+
if (builder != null) {
78+
final CharSequence n = EmojiTranslator.translate(name);
79+
builder.setUri(SCHEME_ORIGINAL_NAME + name);
80+
if (pattern.matcher(n).find()) {
81+
builder.setName(n);
82+
} else {
83+
builder.setName("\u200b" + n);
84+
}
85+
mParticipants.put(key, participant = builder.build());
86+
}
7587
return participant;
7688
}
7789

@@ -94,4 +106,5 @@ Conversation getConversation(final int id) {
94106
}
95107

96108
private final SparseArray<Conversation> mConversations = new SparseArray<>();
109+
private static final String TAG = WeChatDecorator.TAG;
97110
}

src/main/java/com/oasisfeng/nevo/decorators/wechat/EmojiMap.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@ public class EmojiMap {
1313
// Pull Request is welcome. (columns are split by "tab" for visual alignment)
1414
// Proper emoji is needed for commented lines.
1515
static final String[][] MAP = new String[][] {
16-
{ "表情", null, "㊙️" },
17-
{ "链接", null, "🔗" },
16+
{ "表情", null, "㊙️" },
17+
{ "链接", null, "🔗" },
18+
{ "花", null, "🌺" },
19+
{ "钱", null, "💰" },
20+
{ "闪烁", null, "✨" },
21+
{ "X", "X", "❌" },
1822
{ "OK", "OK", "👌" },
1923
{ "耶", "Yeah!", "✌" },
2024
{ "嘘", "Silent", "🤫" },
@@ -114,7 +118,7 @@ public class EmojiMap {
114118
// { "机智", "Smart", "" },
115119
// { "抠鼻", "DigNose", "" },
116120
// { "可怜", "Whimper", "" },
117-
{ "皇冠", null, "👑" },
121+
{ "皇冠", null, "👑" },
118122
{ "快哭了", "Puling", "😔" },
119123
// { "左哼哼", "Bah!L", "" },
120124
// { "右哼哼", "Bah!R", "" },

src/main/java/com/oasisfeng/nevo/decorators/wechat/EmojiTranslator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ public class EmojiTranslator {
1717
private static final Map<String, String> ENGLISH_MAP = new HashMap<>(EmojiMap.MAP.length);
1818
static {
1919
for (final String[] entry : EmojiMap.MAP) {
20-
if (entry[0] != null)
21-
CHINESE_MAP.put(entry[0], entry[2]);
22-
if (entry[1] != null)
23-
ENGLISH_MAP.put(entry[1], entry[2]);
20+
if (entry[0] != null)
21+
CHINESE_MAP.put(entry[0], entry[2]);
22+
if (entry[1] != null)
23+
ENGLISH_MAP.put(entry[1], entry[2]);
2424
}
2525
}
2626

src/main/java/com/oasisfeng/nevo/decorators/wechat/MessagingBuilder.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class MessagingBuilder {
9494
final String redundant_prefix = title.toString() + SENDER_MESSAGE_SEPARATOR;
9595
for (final StatusBarNotification each : archive) {
9696
final Notification notification = each.getNotification();
97-
tickerArray.put(notification.when, notification.tickerText);
97+
tickerArray.put(notification.when, notification.tickerText);
9898
final Bundle its_extras = notification.extras;
9999
final CharSequence its_title = EmojiTranslator.translate(its_extras.getCharSequence(Notification.EXTRA_TITLE));
100100
if (! title.equals(its_title)) {
@@ -130,7 +130,7 @@ class MessagingBuilder {
130130
final boolean sender_inline = num_lines_with_colon == textArray.size();
131131
for (int i = 0, size = textArray.size(); i < size; i++) { // All lines have colon in text
132132
messaging.addMessage(buildMessage(conversation, textArray.keyAt(i), tickerArray.valueAt(i), textArray.valueAt(i), sender_inline ? null : title.toString()));
133-
}
133+
}
134134
return messaging;
135135
}
136136

@@ -159,8 +159,8 @@ class MessagingBuilder {
159159
Log.e(TAG, "Error parsing reply intent.", e);
160160
}
161161

162-
final MessagingStyle messaging = buildFromArchive(conversation, n, title, archive);
163-
final List<Message> messages = messaging.getMessages();
162+
final MessagingStyle messaging = buildFromArchive(conversation, n, title, archive);
163+
final List<Message> messages = messaging.getMessages();
164164

165165
final PendingIntent on_read = convs.getReadPendingIntent();
166166
if (on_read != null) mMarkReadPendingIntents.put(sbn.getKey(), on_read); // Mapped by evolved key,
@@ -358,8 +358,7 @@ interface Controller { void recastNotification(String key, Bundle addition); }
358358
}
359359

360360
private static Person buildPersonFromProfile(final Context context) {
361-
return new Person.Builder().setName(context.getString(R.string.self_display_name))
362-
.setIcon(IconCompat.createWithContentUri(Uri.withAppendedPath(Profile.CONTENT_URI, Contacts.Photo.DISPLAY_PHOTO))).build();
361+
return new Person.Builder().setName(context.getString(R.string.self_display_name)).build();
363362
}
364363

365364
void close() {

0 commit comments

Comments
 (0)