Skip to content

Commit

Permalink
接口请求回调优化;update数据保存优化;ToastUtils和CenterDialog显示优化
Browse files Browse the repository at this point in the history
  • Loading branch information
Airry666 committed Oct 16, 2020
1 parent ae8169d commit 9b57ed7
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 107 deletions.
2 changes: 1 addition & 1 deletion geetolsdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ android {
minSdkVersion 17
targetSdkVersion 26
versionCode 16
versionName "4.5.2"
versionName "4.5.3"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,6 @@ public void onResponse(Call call, Response response) throws IOException {

/**
* 分发失败的时候回调
*
* @param request
* @param e
* @param callBack
*/
private void deliverDataFailure(final Request request, final IOException e, final DataCallBack callBack) {
mHandler.post(() -> {
Expand All @@ -227,9 +223,6 @@ private void deliverDataFailure(final Request request, final IOException e, fina

/**
* 分发成功的时候回调
*
* @param result
* @param callBack
*/
private void deliverDataSuccess(final String result, final DataCallBack callBack) {
mHandler.post(() -> {
Expand All @@ -245,9 +238,6 @@ private void deliverDataSuccess(final String result, final DataCallBack callBack

/**
* map根据key值比较大小
*
* @param map
* @return
*/
private static Map<String, String> sortMapByKey(Map<String, String> map) {
if (map == null || map.isEmpty()) {
Expand All @@ -261,8 +251,6 @@ private static Map<String, String> sortMapByKey(Map<String, String> map) {
/**
* 内部处理Map集合
* 得到from表单 (post请求)
*
* @return
*/
private RequestBody getRequestBody(Map<String, String> map) {
RequestBody requestBody = null;
Expand Down Expand Up @@ -294,7 +282,6 @@ private RequestBody getRequestBody(Map<String, String> map) {
str = str.replace("\n", "");//去除换行
str = str.replace("\\s", "");//去除空格
Log.e("请求参数:", "string:" + str);
// Log.e("testaaaa",str);
isFirst = !isFirst;
alga.update(str.getBytes());
/**
Expand Down Expand Up @@ -327,7 +314,7 @@ public void postGetAppUrl(long apid, BaseCallback callback) {
}

/**
* 提供给外部调用的添加服务单接口
* 添加反馈
*
* @param callback 回调函数
*/
Expand All @@ -336,43 +323,34 @@ public void postAddService(String title, String descibe, String type, String img
}

/**
* 获取服务单接口
*
* @param page
* @param limit
* @param callback
* 获取反馈列表
*/
public void postGetServices(int page, int limit, BaseCallback callback) {
post(commonUrl + API.GET_SERVICE, MapUtils.getGetServiceMap(page, limit), callback);
}

/**
* 获取服务单详情的接口
*
* @param service_id
* @param callback
* 获取反馈详情
*/
public void postGetServicesDetails(int service_id, BaseCallback callback) {
post(commonUrl + API.GET_SERVICE_DETAILS, MapUtils.getServiceDetialsMap(service_id), callback);
}

/**
* 添加服务单回复接口
* 添加反馈回复
*
* @param service_id 服务单id
* @param repley 回复内容
* @param img 回复图片 base64处理的图片 多个用,分割
* @param callback
*/
public void postAddRepley(int service_id, String repley, String img, BaseCallback callback) {
post(commonUrl + API.ADD_REPLEY, MapUtils.getAddRepleyMap(service_id, repley, img), callback);
}

/**
* 结束服务
* 结束反馈
*
* @param id 服务单id
* @param callback
*/
public void postEndService(int id, BaseCallback callback) {
post(commonUrl + API.END_SERVICE, MapUtils.getServiceDetialsMap(id), callback);
Expand Down Expand Up @@ -548,7 +526,6 @@ public void userCodeLogin(String tel, String smscode, String smskey, BaseCallbac

/**
* 登陆校验
* @param callback
*/
public void checkLogin(BaseCallback callback) {
post(commonUrl + API.USER_LOGIN_CHECK, MapUtils.getCurrencyMap(), callback, API.USER_LOGIN_CHECK);
Expand Down Expand Up @@ -596,56 +573,61 @@ public void onFailure(Call call, IOException e) {
public void onResponse(Call call, Response response) throws IOException {
if (response.isSuccessful()) {
//返回成功回调
String result = response.body().string();
if (requestType.equals(API.USER_LOGIN) || requestType.equals(API.USER_LOGIN_CODE)) {
// 保存用户信息
LoginInfoBean info = GsonUtils.getFromClass(result, LoginInfoBean.class);
if (info != null && info.isIssucc()) {
Utils.setLoginInfo(info.getData().getUser_id(),
info.getData().getUkey(),
info.getData().getHeadimg());
}
} else if (requestType.equals(API.GET_ALIOSS)) {
// 获取阿里云信息
try {
JSONObject jsonObject = new JSONObject(result);
if (jsonObject.getBoolean("issucc")) {
String data = jsonObject.getString("data");
if (!TextUtils.isEmpty(data)) {
Log.e("哈哈", "阿里云数据:" + data);
Utils.setAliOssParam(data);
try {
String result = response.body().string();
Log.e("请求返回数据:", result);
if (requestType.equals(API.USER_LOGIN) || requestType.equals(API.USER_LOGIN_CODE)) {
// 保存用户信息
LoginInfoBean info = GsonUtils.getFromClass(result, LoginInfoBean.class);
if (info != null && info.isIssucc()) {
Utils.setLoginInfo(info.getData().getUser_id(),
info.getData().getUkey(),
info.getData().getHeadimg());
}
} else if (requestType.equals(API.GET_ALIOSS)) {
// 获取阿里云信息
try {
JSONObject jsonObject = new JSONObject(result);
if (jsonObject.getBoolean("issucc")) {
String data = jsonObject.getString("data");
if (!TextUtils.isEmpty(data)) {
Log.e("请求返回数据", "阿里云数据:" + data);
Utils.setAliOssParam(data);
}
}
} catch (JSONException e) {
e.printStackTrace();
}
} else if (requestType.equals(API.UPDATE)) {
// 获取所有数据
UpdateBean updateBean = GsonUtils.getFromClass(result, UpdateBean.class);
if (updateBean != null) {
DataSaveUtils.getInstance().saveAppData(updateBean);
}
} else if (requestType.equals(API.USER_LOGIN_CHECK)) {
// 校验登陆
ResultBean resultBean = GsonUtils.getFromClass(result, ResultBean.class);
if (resultBean != null && !resultBean.isIssucc()) {
// 已在别的设备登陆,清空本机登陆状态
Utils.setLoginInfo("", "", "");
}
} catch (JSONException e) {
e.printStackTrace();
}
} else if (requestType.equals(API.UPDATE)) {
// 获取所有数据
UpdateBean updateBean = GsonUtils.getFromClass(result, UpdateBean.class);
if (updateBean != null) {
DataSaveUtils.getInstance().saveAppData(updateBean);
}
} else if (requestType.equals(API.USER_LOGIN_CHECK)) {
// 校验登陆
ResultBean resultBean = GsonUtils.getFromClass(result, ResultBean.class);
if (resultBean != null && !resultBean.isIssucc()) {
// 已在别的设备登陆,清空本机登陆状态
Utils.setLoginInfo("", "", "");
}
}
Log.e("请求数据:", result);
if (callback.mType == String.class) {
//如果我们需要返回String类型
callbackSuccess(response, result, callback);
} else {
//如果返回是其他类型,则用Gson去解析
try {
Object o = gson.fromJson(result, callback.mType);
callbackSuccess(response, o, callback);
} catch (JsonSyntaxException e) {
e.printStackTrace();
callbackError(response, callback, e);
if (callback.mType == String.class) {
//如果我们需要返回String类型
callbackSuccess(response, result, callback);
} else {
//如果返回是其他类型,则用Gson去解析
try {
Object o = gson.fromJson(result, callback.mType);
callbackSuccess(response, o, callback);
} catch (JsonSyntaxException e) {
e.printStackTrace();
callbackError(response, callback, e);
}
}
} catch (Exception e) {
e.printStackTrace();
callbackError(response, callback, null);
}
} else {
callbackError(response, callback, null);
Expand All @@ -659,7 +641,6 @@ public void onResponse(Call call, Response response) throws IOException {
*
* @param url 请求路径
* @param params from表单
* @return
*/
private Request getRequest(String url, Map<String, String> params) {
//可以从这么划分get和post请求,暂时只支持post
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public String getHelpUrl() {
if (updateBean != null) {
return updateBean.getHpurl();
}
return null;
return "";
}

/**
Expand All @@ -142,7 +142,7 @@ public String getShareUrl() {
if (updateBean != null) {
return updateBean.getShare_url();
}
return null;
return "";
}

/**
Expand All @@ -163,7 +163,7 @@ public String getContractType() {
if (contract != null && !TextUtils.isEmpty(contract.getTxt())) {
return contract.getTxt();
}
return null;
return "";
}

/**
Expand All @@ -174,7 +174,7 @@ public String getContractNum() {
if (contract != null && !TextUtils.isEmpty(contract.getNum())) {
return contract.getNum();
}
return null;
return "";
}

/**
Expand Down Expand Up @@ -216,7 +216,7 @@ public String getWxId() {
}
}
}
return null;
return "";
}

/**
Expand Down Expand Up @@ -257,7 +257,6 @@ public String getIp() {
if (updateBean != null) {
return updateBean.getIp();
}
return null;
return "";
}

}
Original file line number Diff line number Diff line change
@@ -1,58 +1,60 @@
package com.gtdev5.geetolsdk.mylibrary.util;

import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.widget.Toast;

import com.gtdev5.geetolsdk.mylibrary.initialization.GeetolSDK;

/**
* Created by cheng
* PackageName ModelTest
* 2018/1/4 14:24
* Toast工具类
* Toast工具类
*/

public class ToastUtils {
private static Toast mToast = null;

private static Context mContext;

public static void init(Context context){
if (mContext == null){
public static void init(Context context) {
if (mContext == null) {
mContext = context;
mToast = new Toast(mContext);


}else {
Log.e(GeetolSDK.TAG,"未初始化lib");
return;
} else {
Log.e(GeetolSDK.TAG, "未初始化lib");
}
}

/**
* short Toast
* short Toast
*
* @param msg
*/
public static void showShortToast(String msg){
if (mToast == null){
mToast = Toast.makeText(mContext,msg,Toast.LENGTH_SHORT);
}else {
mToast = Toast.makeText(mContext,msg,Toast.LENGTH_SHORT);
//mToast.setText(msg);
//mToast.setDuration(Toast.LENGTH_SHORT);
public static void showShortToast(String msg) {
if (mToast == null) {
mToast = Toast.makeText(mContext, msg, Toast.LENGTH_SHORT);
} else {
mToast = Toast.makeText(mContext, msg, Toast.LENGTH_SHORT);
}
Activity activity = (Activity) mContext;
if (activity != null && !activity.isFinishing()) {
mToast.show();
}
mToast.show();
}

/**
* long Toast
* long Toast
*
* @param msg
*/
public static void showLongToast(String msg){
if (mToast == null){
mToast = Toast.makeText(mContext,msg,Toast.LENGTH_LONG);
}else {
mToast = Toast.makeText(mContext,msg,Toast.LENGTH_LONG);
public static void showLongToast(String msg) {
if (mToast == null) {
mToast = Toast.makeText(mContext, msg, Toast.LENGTH_LONG);
} else {
mToast = Toast.makeText(mContext, msg, Toast.LENGTH_LONG);
}
mToast.show();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,16 @@ protected void onCreate(Bundle savedInstanceState) {

@Override
public void show() {
super.show();
try {
if (context != null) {
Activity activity = (Activity) context;
if (!activity.isFinishing()) {
super.show();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}

@Override
Expand Down

0 comments on commit 9b57ed7

Please sign in to comment.