|
@@ -26,10 +26,15 @@ public class ContactBean extends BaseBean {
|
|
|
}
|
|
|
|
|
|
public String getNickName(Context context) {
|
|
|
- String[] value = name.split("_");
|
|
|
+ if (!name.contains("_"))
|
|
|
+ return name;
|
|
|
+ String[] value = splitWithFirst(name, "_");
|
|
|
+ if (value.length <= 1 || !isInteger(value[0]))
|
|
|
+ return name;
|
|
|
int index = Integer.parseInt(value[0]);
|
|
|
- if (index == 11) {
|
|
|
- return value[1];
|
|
|
+ String nickname = value[1];
|
|
|
+ if (index == 11 || (nickname.length() > 0 && !nickname.equals("null"))) {
|
|
|
+ return nickname;
|
|
|
} else {
|
|
|
switch (index) {
|
|
|
case 0:
|
|
@@ -49,38 +54,66 @@ public class ContactBean extends BaseBean {
|
|
|
case 7:
|
|
|
return context.getString(R.string.tcl_family_7);
|
|
|
default:
|
|
|
- return "";
|
|
|
+ return "tcl_family_" + index;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public int getHeadDefaultId(Context context) {
|
|
|
- String[] value = name.split("_");
|
|
|
- int index = Integer.parseInt(value[0]);
|
|
|
- if (index == 11) {
|
|
|
+ if (!name.contains("_"))
|
|
|
return R.drawable.default_contact;
|
|
|
- } else {
|
|
|
- switch (index) {
|
|
|
- case 0:
|
|
|
- return R.drawable.default_contact_0;
|
|
|
- case 1:
|
|
|
- return R.drawable.default_contact_1;
|
|
|
- case 2:
|
|
|
- return R.drawable.default_contact_2;
|
|
|
- case 3:
|
|
|
- return R.drawable.default_contact_3;
|
|
|
- case 4:
|
|
|
- return R.drawable.default_contact_4;
|
|
|
- case 5:
|
|
|
- return R.drawable.default_contact_5;
|
|
|
- case 6:
|
|
|
- return R.drawable.default_contact_6;
|
|
|
- case 7:
|
|
|
- return R.drawable.default_contact_7;
|
|
|
- default:
|
|
|
- return 0;
|
|
|
- }
|
|
|
+ String[] value = splitWithFirst(name, "_");
|
|
|
+ if (value.length <= 1 || !isInteger(value[0]))
|
|
|
+ return R.drawable.default_contact;
|
|
|
+ int index = Integer.parseInt(value[0]);
|
|
|
+ switch (index) {
|
|
|
+ case 0:
|
|
|
+ return R.drawable.default_contact_0;
|
|
|
+ case 1:
|
|
|
+ return R.drawable.default_contact_1;
|
|
|
+ case 2:
|
|
|
+ return R.drawable.default_contact_2;
|
|
|
+ case 3:
|
|
|
+ return R.drawable.default_contact_3;
|
|
|
+ case 4:
|
|
|
+ return R.drawable.default_contact_4;
|
|
|
+ case 5:
|
|
|
+ return R.drawable.default_contact_5;
|
|
|
+ case 6:
|
|
|
+ return R.drawable.default_contact_6;
|
|
|
+ case 7:
|
|
|
+ return R.drawable.default_contact_7;
|
|
|
+ case 11:
|
|
|
+ return R.drawable.default_contact;
|
|
|
+ default:
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static boolean isInteger(String str) {
|
|
|
+ if (str == null || str.isEmpty()) {
|
|
|
+ return false;
|
|
|
}
|
|
|
+ // 仅匹配整数,不包含负数
|
|
|
+ String regex = "^[0-9]\\d*$";
|
|
|
+ return str.matches(regex);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String[] splitWithFirst(String str, String separator) {
|
|
|
+ if (str == null) {
|
|
|
+ return new String[0];
|
|
|
+ }
|
|
|
+
|
|
|
+ int index = str.indexOf(separator);
|
|
|
+ if (index == -1) {
|
|
|
+ // 没有找到下划线,返回包含原字符串的数组
|
|
|
+ return new String[]{str};
|
|
|
+ }
|
|
|
+
|
|
|
+ // 分割为两部分:下划线前的部分和下划线后的部分
|
|
|
+ String firstPart = str.substring(0, index);
|
|
|
+ String secondPart = str.substring(index + 1);
|
|
|
+ return new String[]{firstPart, secondPart};
|
|
|
}
|
|
|
|
|
|
public String beanToString() {
|