Files
SipPhone/app/src/main/java/com/tianrun/sipcall/db/DBUser.java

104 lines
2.9 KiB
Java
Raw Normal View History

2020-09-10 22:38:32 +08:00
package com.tianrun.sipcall.db;
2020-09-11 22:59:19 +08:00
import android.widget.ImageView;
import android.widget.TextView;
2020-09-10 22:38:32 +08:00
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
2020-09-11 22:59:19 +08:00
import com.alibaba.fastjson.serializer.FloatCodec;
2020-09-10 22:38:32 +08:00
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class DBUser {
public static List<DBUser> allUser = new ArrayList<>();
public static HashMap<String, DBUser> mapUsers = new HashMap<>();
public static DBUser mySelf;
public String name = "";
public String phone = "";
public String status = "";
2020-09-15 17:57:15 +08:00
public boolean isManager = true;
2020-09-10 22:38:32 +08:00
public boolean isAddFlag = false;
2020-09-13 09:35:07 +08:00
public boolean isMute = false;
public boolean isVMute = false;
public boolean isLayout = false;
2020-09-10 22:38:32 +08:00
public DBUser(String name, String phone, String status) {
this.name = name;
this.phone = phone;
this.status = status;
}
public DBUser(JSONObject d) {
this.name = d.getString("name");
this.phone = d.getString("extn");
this.status = d.getString("sip_state");
2021-01-20 21:51:15 +08:00
status = status == null ? "" : status;
2020-09-11 22:59:19 +08:00
String weight = d.getString("weight");
2020-09-14 16:43:36 +08:00
if (weight != null) {
2020-09-15 17:57:15 +08:00
this.isManager = weight.equals("1") ? true : false;
2020-09-11 22:59:19 +08:00
} else {
this.isManager = false;
}
2020-09-14 16:43:36 +08:00
String ifMute = d.getString("ifMute");
this.isMute = ifMute != null ? ifMute.equals("true") : false;
String ifVMute = d.getString("ifVMute");
this.isVMute = ifVMute != null ? ifVMute.equals("true") : false;
2020-09-10 22:38:32 +08:00
}
public boolean isBusy() {
return status.equals("busy");
}
public boolean isOnline() {
return status.equals("true");
}
public boolean isOffline() {
return status.equals("false");
}
public static void onGetUsers(JSONArray array) {
allUser.clear();
DBUser u;
for (Object o : array) {
u = new DBUser((JSONObject) o);
allUser.add(u);
mapUsers.put(u.phone, u);
2020-09-15 17:57:15 +08:00
if (mySelf != null && u.phone.equals(mySelf.phone)) {
2020-09-10 22:38:32 +08:00
mySelf = u;
}
}
}
2020-09-22 11:15:45 +08:00
public static void refreshUser(DBUser user) {
for(int i=0; i < allUser.size();i++) {
DBUser u = allUser.get(i);
if(u.phone.equals(user.phone)) {
allUser.set(i, user);
mapUsers.put(user.phone, user);
return;
}
}
allUser.add(user);
mapUsers.put(user.phone, user);
}
public static void onGetGroupMembers(JSONObject content) {
DBGroup group = new DBGroup();
group.head = new DBHead(content);
JSONArray array = content.getJSONArray("members_msg");
for (Object o : array) {
DBUser u = new DBUser((JSONObject) o);
refreshUser(u);
}
}
2020-09-10 22:38:32 +08:00
public static DBUser getUser(String phoneNo) {
return mapUsers.get(phoneNo);
}
}