IOS
hefeixia
2021-02-18 49f3c1374873f73dbde2983ca0fcf1fb10bfedbf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/*
 * 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];
        }
    };
}