/*
|
* Copyright (c) 2020 WildFireChat. All rights reserved.
|
*/
|
|
package cn.wildfire.chat.kit.contact.model;
|
|
import android.os.Parcel;
|
import android.os.Parcelable;
|
import android.text.TextUtils;
|
import cn.wildfire.chat.kit.utils.PinyinUtils;
|
import cn.wildfirechat.model.Doctor;
|
import cn.wildfirechat.model.Patient;
|
import cn.wildfirechat.model.UserInfo;
|
import cn.wildfirechat.remote.ChatManager;
|
|
import java.util.ArrayList;
|
import java.util.Collections;
|
import java.util.List;
|
|
public class UIUserInfo implements Parcelable {
|
public static final int Default_TYPE = 0;
|
public static final int Patient_Group_TYPE = 1;
|
public static final int DOCTOR_Group_TYPE = 2;
|
|
|
public static final int PATIENT = 1;
|
public static final int DOCTOR = 2;
|
public static final int DOCTOR_TEAM = 3;
|
|
private String category = "";
|
// 用来排序的字段
|
private String sortName;
|
private boolean showCategory;
|
private UserInfo userInfo;
|
private boolean isChecked;
|
private boolean isCheckable = true;
|
private int type = 0;
|
private Integer userType; //用户分类
|
private Doctor doctorInfo;
|
private String descInfo;
|
private Patient patient; // 患者信息
|
|
public void setUserInfo(UserInfo userInfo) {
|
this.userInfo = userInfo;
|
}
|
|
public Integer getUserType() {
|
return userType;
|
}
|
|
public void setUserType(Integer userType) {
|
this.userType = userType;
|
}
|
|
public Doctor getDoctorInfo() {
|
return doctorInfo;
|
}
|
|
public void setDoctorInfo(Doctor doctorInfo) {
|
this.doctorInfo = doctorInfo;
|
}
|
|
public String getDescInfo() {
|
return descInfo;
|
}
|
|
public void setDescInfo(String descInfo) {
|
this.descInfo = descInfo;
|
}
|
|
public Patient getPatient() {
|
return patient;
|
}
|
|
public void setPatient(Patient patient) {
|
this.patient = patient;
|
}
|
|
public int getType() {
|
return type;
|
}
|
|
public UIUserInfo() {
|
}
|
|
public UIUserInfo setType(int type) {
|
this.type = type;
|
return this;
|
}
|
|
public UIUserInfo(UserInfo userInfo) {
|
this.userInfo = userInfo;
|
}
|
|
public void setCategory(String category) {
|
this.category = category;
|
}
|
|
public UIUserInfo setShowCategory(boolean showCategory) {
|
this.showCategory = showCategory;
|
return this;
|
}
|
|
public String getCategory() {
|
return category;
|
}
|
|
public boolean isShowCategory() {
|
return showCategory;
|
}
|
|
public UserInfo getUserInfo() {
|
return userInfo;
|
}
|
|
public String getSortName() {
|
return sortName;
|
}
|
|
public void setSortName(String displayNamePinyin) {
|
this.sortName = displayNamePinyin;
|
}
|
|
public boolean isChecked() {
|
return isChecked;
|
}
|
|
public void setChecked(boolean checked) {
|
isChecked = checked;
|
}
|
|
public boolean isCheckable() {
|
return isCheckable;
|
}
|
|
public void setCheckable(boolean checkable) {
|
isCheckable = checkable;
|
}
|
|
public static UIUserInfo fromUserInfo(UserInfo userInfo) {
|
UIUserInfo info = new UIUserInfo(userInfo);
|
String indexLetter;
|
String displayName = ChatManager.Instance().getUserDisplayName(userInfo);
|
if (!TextUtils.isEmpty(displayName)) {
|
String pinyin = PinyinUtils.getPinyin(displayName);
|
char c = pinyin.toUpperCase().charAt(0);
|
if (c >= 'A' && c <= 'Z') {
|
indexLetter = c + "";
|
info.setSortName(pinyin);
|
} else {
|
indexLetter = "#";
|
// 为了让排序排到最后
|
info.setSortName("{" + pinyin);
|
}
|
info.setCategory(indexLetter);
|
} else {
|
info.setSortName("");
|
}
|
return info;
|
}
|
public static List<UIUserInfo> fromUserInfos(List<UserInfo> userInfos) {
|
return fromUserInfos(userInfos, false);
|
}
|
|
public static List<UIUserInfo> fromUserInfos(List<UserInfo> userInfos, boolean isFavUser) {
|
if (userInfos != null && !userInfos.isEmpty()) {
|
List<UIUserInfo> uiUserInfos = new ArrayList<>(userInfos.size());
|
String indexLetter;
|
for (UserInfo userInfo : userInfos) {
|
uiUserInfos.add(fromUserInfo(userInfo));
|
}
|
Collections.sort(uiUserInfos, (o1, o2) -> o1.getSortName().compareToIgnoreCase(o2.getSortName()));
|
|
if(isFavUser){
|
UIUserInfo uiUserInfo = uiUserInfos.get(0);
|
uiUserInfo.setShowCategory(true);
|
uiUserInfo.setCategory("星标朋友");
|
}else {
|
String preIndexLetter = null;
|
for (UIUserInfo info : uiUserInfos) {
|
indexLetter = info.getCategory();
|
if (preIndexLetter == null || !preIndexLetter.equals(indexLetter)) {
|
info.setShowCategory(true);
|
}
|
preIndexLetter = indexLetter;
|
}
|
}
|
return uiUserInfos;
|
} else {
|
return null;
|
}
|
}
|
|
@Override
|
public int describeContents() {
|
return 0;
|
}
|
|
@Override
|
public void writeToParcel(Parcel dest, int flags) {
|
dest.writeString(this.category);
|
dest.writeString(this.sortName);
|
dest.writeByte(this.showCategory ? (byte) 1 : (byte) 0);
|
dest.writeParcelable(this.userInfo, flags);
|
dest.writeByte(this.isChecked ? (byte) 1 : (byte) 0);
|
dest.writeByte(this.isCheckable ? (byte) 1 : (byte) 0);
|
}
|
|
protected UIUserInfo(Parcel in) {
|
this.category = in.readString();
|
this.sortName = in.readString();
|
this.showCategory = in.readByte() != 0;
|
this.userInfo = in.readParcelable(UserInfo.class.getClassLoader());
|
this.isChecked = in.readByte() != 0;
|
this.isCheckable = in.readByte() != 0;
|
}
|
|
public static final Parcelable.Creator<UIUserInfo> CREATOR = new Parcelable.Creator<UIUserInfo>() {
|
@Override
|
public UIUserInfo createFromParcel(Parcel source) {
|
return new UIUserInfo(source);
|
}
|
|
@Override
|
public UIUserInfo[] newArray(int size) {
|
return new UIUserInfo[size];
|
}
|
};
|
}
|