You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
2.2 KiB
71 lines
2.2 KiB
package com.community.pocket.data.main.info;
|
|
|
|
|
|
import android.graphics.Bitmap;
|
|
|
|
import androidx.lifecycle.MutableLiveData;
|
|
|
|
import com.community.pocket.data.model.LocalToken;
|
|
import com.community.pocket.ui.main.ui.info.InfoResponse;
|
|
import com.community.pocket.util.HttpFileResponse;
|
|
import com.community.pocket.util.HttpRequest;
|
|
import com.community.pocket.util.HttpUtil;
|
|
import com.community.pocket.util.SimpleHttpParse;
|
|
|
|
import java.io.File;
|
|
|
|
import okhttp3.MediaType;
|
|
import okhttp3.RequestBody;
|
|
|
|
/**
|
|
* 个人信息请求接口
|
|
*/
|
|
public class InfoRequest {
|
|
private static volatile InfoRequest instance;
|
|
|
|
private InfoRequest() {
|
|
}
|
|
|
|
public static InfoRequest getInstance() {
|
|
if (instance == null) {
|
|
instance = new InfoRequest();
|
|
}
|
|
return instance;
|
|
}
|
|
|
|
//修改密码
|
|
@HttpRequest("/my/info/modifyPwd")
|
|
public void modifyPwd(MutableLiveData<InfoResponse> liveData, String oldPassword, String newPassword) {
|
|
HttpUtil.getRequest(HttpUtil.Method.POST,
|
|
new SimpleHttpParse<InfoResponse>(liveData).getInterface(InfoResponse.class),
|
|
LocalToken.create()
|
|
.add("oldPassword", oldPassword)
|
|
.add("newPassword", newPassword)
|
|
.build());
|
|
}
|
|
|
|
//获取个人信息
|
|
@HttpRequest("/my/info")
|
|
public void loadInfo(MutableLiveData<InfoResponse> liveData) {
|
|
HttpUtil.getRequest(HttpUtil.Method.GET,
|
|
new SimpleHttpParse<InfoResponse>(liveData).getInterface(InfoResponse.class),
|
|
LocalToken.create().build());
|
|
}
|
|
|
|
//上传头像
|
|
@HttpRequest("/uploadHeadImg")
|
|
public void uploadImg(MutableLiveData<InfoResponse> liveData, File picFile) {
|
|
HttpUtil.getRequest(new SimpleHttpParse<InfoResponse>(liveData).getInterface(InfoResponse.class),
|
|
LocalToken.createM()
|
|
.addFormDataPart("file", picFile.getName(), RequestBody.create(picFile, MediaType.parse("image/png")))
|
|
.build());
|
|
}
|
|
|
|
//获取头像
|
|
public void getImg(MutableLiveData<Bitmap> liveData, String url) {
|
|
if(url==null){
|
|
return;
|
|
}
|
|
HttpUtil.getRequest(new HttpFileResponse(liveData), url);
|
|
}
|
|
}
|
|
|