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

137 lines
4.1 KiB
Java
Raw Normal View History

2020-09-10 22:38:32 +08:00
package com.tianrun.sipcall.db;
2021-04-14 18:05:34 +08:00
import android.util.Log;
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 = "";
2021-04-14 18:05:34 +08:00
public int groupOrder = 0;
public int priority = 0;
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;
2021-04-14 18:05:34 +08:00
public boolean isEmpty = false;
private static final String TAG = "DBUser";
2020-09-13 09:35:07 +08:00
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;
}
2021-04-14 18:05:34 +08:00
public DBUser () {
}
2020-09-10 22:38:32 +08:00
public DBUser(JSONObject d) {
2021-04-14 18:05:34 +08:00
try {
this.name = d.getString("name");
this.phone = d.getString("extn");
this.status = d.getString("sip_state");
status = status == null ? "" : status;
String weight = d.getString("weight");
if (weight != null) {
this.isManager = weight.equals("1") ? true : false;
} else {
this.isManager = false;
}
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;
String _groupOrder = d.getString("group_order");
this.groupOrder = _groupOrder != null ? Integer.parseInt(_groupOrder) : 0;
String _priority = d.getString("priority");
this.priority = _priority != null ? Integer.parseInt(_priority) : 0;
isEmpty = false;
} catch (Exception e){
Log.i(TAG, "onRequestComplete: " + e);
2020-09-11 22:59:19 +08:00
}
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;
2021-04-14 18:05:34 +08:00
int cellSize = 5;
int oldGroupOrder = -1;
2020-09-10 22:38:32 +08:00
for (Object o : array) {
u = new DBUser((JSONObject) o);
2021-04-14 18:05:34 +08:00
if(oldGroupOrder >= 0 && oldGroupOrder != u.groupOrder) {
//需要分组
int yushu = allUser.size() % cellSize;
if(yushu > 0){
yushu = cellSize - yushu;
for (int i=0;i<yushu;i++){
DBUser _u = new DBUser();
_u.isEmpty = true;
allUser.add(_u);
}
}
}
oldGroupOrder = u.groupOrder;
2020-09-10 22:38:32 +08:00
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);
}
}