11111
This commit is contained in:
@@ -1,26 +1,35 @@
|
||||
package com.yunbao.common.manager;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.TypeReference;
|
||||
import com.google.gson.Gson;
|
||||
import com.yunbao.common.bean.IMLoginModel;
|
||||
import com.yunbao.common.http.HttpCallback;
|
||||
import com.yunbao.common.http.HttpClient;
|
||||
import com.yunbao.common.manager.base.BaseCacheManager;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 登录者信息管理
|
||||
*/
|
||||
public class IMLoginManager extends BaseCacheManager {
|
||||
|
||||
|
||||
private final static String KEY_USER_INFO = "keyUserInfo";
|
||||
|
||||
private static IMLoginManager manager;
|
||||
private IMLoginModel userInfo;
|
||||
//根据用户信息
|
||||
private Handler netHandler = new Handler();
|
||||
private Context context;
|
||||
|
||||
private IMLoginManager(Context context) {
|
||||
super(context);
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -54,19 +63,46 @@ public class IMLoginManager extends BaseCacheManager {
|
||||
* @param model
|
||||
*/
|
||||
public void setupLoginUser(@NonNull IMLoginModel model) {
|
||||
put(KEY_USER_INFO, new Gson().toJson(model));
|
||||
this.userInfo = model;
|
||||
|
||||
netHandler.post(isInstructorRunnable);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取是不是新手指导员的身份
|
||||
*/
|
||||
private Runnable isInstructorRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
HttpClient.getInstance().get("User.isInstructor", "isInstructor")
|
||||
.params("uid", userInfo.getId())
|
||||
.params("token", userInfo.getToken())
|
||||
.execute(new HttpCallback() {
|
||||
@Override
|
||||
public void onSuccess(int code, String msg, String[] info) {
|
||||
if (info.length > 0) {
|
||||
if ("1".equals(info[0])) {
|
||||
userInfo.setIsAdmin("1");
|
||||
InstructorRemarkManager.get(context).getNetInstructorRemark();
|
||||
} else {
|
||||
userInfo.setIsAdmin("0");
|
||||
}
|
||||
}
|
||||
put(KEY_USER_INFO, new Gson().toJson(userInfo));
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* 退出登录
|
||||
*/
|
||||
public void logout() {
|
||||
//删除用户登录信息
|
||||
deleteByKey(KEY_USER_INFO);
|
||||
//用户对象置空
|
||||
userInfo=null;
|
||||
deleteByKey(KEY_USER_INFO);
|
||||
//用户对象置空
|
||||
userInfo = null;
|
||||
manager = null;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
package com.yunbao.common.manager;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.TypeReference;
|
||||
import com.google.gson.Gson;
|
||||
import com.yunbao.common.bean.IMLoginModel;
|
||||
import com.yunbao.common.http.HttpCallback;
|
||||
import com.yunbao.common.http.HttpClient;
|
||||
import com.yunbao.common.manager.base.BaseCacheManager;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 新手指导员备注列表
|
||||
*/
|
||||
public class InstructorRemarkManager extends BaseCacheManager {
|
||||
private final static String KEY_INSTRUCTOR_REMARK = "InstructorRemark";
|
||||
private static InstructorRemarkManager manager;
|
||||
private Context context;
|
||||
private Map<String, String> instructorRemarkMap;
|
||||
private Handler netHandler = new Handler();
|
||||
|
||||
private InstructorRemarkManager(Context context) {
|
||||
super(context);
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指导员备注信息
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Map<String, String> getInstructorRemark() {
|
||||
if (null == instructorRemarkMap) {
|
||||
instructorRemarkMap = JSON.parseObject(getString(KEY_INSTRUCTOR_REMARK), new TypeReference<Map<String, String>>() {
|
||||
});
|
||||
}
|
||||
return instructorRemarkMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置指导员备注信息
|
||||
*/
|
||||
public void setInstructorRemark(String map) {
|
||||
this.instructorRemarkMap = JSON.parseObject(map, new TypeReference<Map<String, String>>() {
|
||||
});
|
||||
put(KEY_INSTRUCTOR_REMARK, map);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增备注
|
||||
*
|
||||
* @param key 用户id
|
||||
* @param value 备注信息
|
||||
*/
|
||||
public void addInstructorRemark(String key, String value) {
|
||||
this.instructorRemarkMap.put(key, value);
|
||||
String json = new Gson().toJson(instructorRemarkMap).toString();
|
||||
put(KEY_INSTRUCTOR_REMARK, json);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从服务器获取信息
|
||||
*/
|
||||
public void getNetInstructorRemark() {
|
||||
netHandler.post(getInstructorRemarkRunnable);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单利
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static InstructorRemarkManager get(Context context) {
|
||||
if (null == manager) {
|
||||
manager = new InstructorRemarkManager(context);
|
||||
}
|
||||
return manager;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取备注信息
|
||||
*/
|
||||
private Runnable getInstructorRemarkRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
IMLoginModel userInfo = IMLoginManager.get(context).getUserInfo();
|
||||
HttpClient.getInstance().get("User.getInstructorRemark", "getInstructorRemark")
|
||||
.params("uid", userInfo.getId())
|
||||
.params("token", userInfo.getToken())
|
||||
.execute(new HttpCallback() {
|
||||
@Override
|
||||
public void onSuccess(int code, String msg, String[] info) {
|
||||
if (code == 0 && info.length > 0) {
|
||||
instructorRemarkMap = JSON.parseObject(info[0], new TypeReference<Map<String, String>>() {
|
||||
|
||||
});
|
||||
setInstructorRemark(info[0]);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user