kotlin转化
This commit is contained in:
parent
8e4d517c40
commit
2aa61c64b3
@ -36,7 +36,7 @@ android {
|
||||
targetSdkVersion 30
|
||||
versionCode 49
|
||||
versionName "3.1.9"
|
||||
flavorDimensions "environment"
|
||||
flavorDimensions "CHANNEL_VALUE"
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
javaCompileOptions {
|
||||
|
||||
@ -49,8 +49,8 @@ android {
|
||||
ndk {
|
||||
|
||||
//选择要添加的对应 cpu 类型的 .so 库。
|
||||
abiFilters 'armeabi', 'armeabi-v7a', 'arm64-v8a'
|
||||
// 还可以添加 'x86', 'x86_64', 'mips', 'mips64'
|
||||
abiFilters 'armeabi', 'armeabi-v7a'
|
||||
// 还可以添加 'x86', 'x86_64', 'mips', 'mips64' , 'arm64-v8a'
|
||||
|
||||
}
|
||||
|
||||
@ -69,11 +69,6 @@ android {
|
||||
VIVO_APPID : "vivo的APPID"
|
||||
]
|
||||
}
|
||||
// sourceSets {
|
||||
// main {
|
||||
// jniLibs.srcDir 'libs'
|
||||
// }
|
||||
// }
|
||||
sourceSets {
|
||||
main {
|
||||
jniLibs.srcDirs = ['libs']
|
||||
@ -111,15 +106,19 @@ android {
|
||||
productFlavors {
|
||||
qa {
|
||||
buildConfigField("String", "OPEN_API_URL", "\"http://192.168.111.244:4009\"")
|
||||
}
|
||||
staging {
|
||||
buildConfigField("String", "OPEN_API_URL", "\"https://oapi-staging.alct56.com\"")
|
||||
buildConfigField("String", "BASE_URL", "\"http://app.dahehuoyun.com/api/\"")
|
||||
}
|
||||
product {
|
||||
buildConfigField("String", "OPEN_API", "\"https://oapi.alct56.com\"")
|
||||
buildConfigField("String", "OPEN_API_URL", "\"https://oapi.alct56.com\"")
|
||||
buildConfigField("String", "BASE_URL", "\"http://app.dahehuoyun.com/api/\"")
|
||||
}
|
||||
|
||||
}
|
||||
// productFlavors.all { flavor ->
|
||||
// flavor.manifestPlaceholders = [CHANNEL_VALUE: name]
|
||||
// }
|
||||
|
||||
|
||||
android.applicationVariants.all { variant ->
|
||||
variant.outputs.all {
|
||||
@ -277,13 +276,6 @@ dependencies {
|
||||
implementation 'com.amap.api:location:5.5.1'
|
||||
implementation 'com.amap.api:search:7.9.0'
|
||||
|
||||
//定位功能
|
||||
// implementation 'com.amap.api:location:latest.integration'
|
||||
// //搜索功能
|
||||
// implementation 'com.amap.api:search:latest.integration'
|
||||
//导航
|
||||
// implementation 'com.amap.api:navi-3dmap:latest.integration'
|
||||
|
||||
// implementation 'com.amap.api:3dmap:latest.integration'
|
||||
implementation project(path: ':mylibrary')
|
||||
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -266,6 +266,10 @@
|
||||
android:name="DOMAIN_PACKAGE_NAME"
|
||||
android:value="com.baifenzhiliu.sixspread.entity" />
|
||||
|
||||
<meta-data
|
||||
android:name="CHANNEL"
|
||||
android:value="${CHANNEL_VALUE}" />
|
||||
|
||||
<!-- 易签宝 -->
|
||||
<activity
|
||||
android:name="com.esign.esignsdk.h5.H5Activity"
|
||||
|
@ -10,6 +10,8 @@ import android.util.Log;
|
||||
|
||||
import com.alct.mdp.MDPLocationCollectionManager;
|
||||
import com.arpa.hndahesudintocctmsdriver.report.JTTProcess;
|
||||
import com.arpa.hndahesudintocctmsdriver.request.net.Api;
|
||||
import com.dahe.mylibrary.CommonBaseLibrary;
|
||||
import com.esign.esignsdk.EsignSdk;
|
||||
import com.arpa.hndahesudintocctmsdriver.util.sp.SPUtil;
|
||||
import com.umeng.commonsdk.UMConfigure;
|
||||
@ -18,67 +20,73 @@ import cn.jiguang.verifysdk.api.JVerificationInterface;
|
||||
|
||||
public class App extends Application {
|
||||
|
||||
String key="f9d35b1133cff1f6e3960c89b249e03f";
|
||||
String license="eQQm7gCZPF58Cy4i9OGkqSdFdDnFF0VSUVpw92WcrNLx7zVbpGJwjQhnKL8b0piApIbOTog5log/S1ZIxoUQogueaG84BQlJfRwKjtvpVWImlmhthQyQd2ogRqGkm3rkVGeG9wK49fzP3g5AtghNF05je2rQWd/Tyy/wutXq0e0rvR/bEckFaZ4BesQaYd0MejFC3lA8BjxNWiuvCKs15e1aRUOU5vwN5wsaTsTHokBIYhioSxOoGgHn6NrX6K9Dsl9uTWZ2dOVK/jEzYsNt6E/1Ww2ck1XmIWdRCQNmCpgikuPT0ACAL/w7UaRoWzM/Pm+akWqyp+bEavHT1Vhug3HAHOSGfOghGw2NerNlyEg8h6cVneMx+TsidnQ0ZG29aqdcLBRsvi26BYJJCA8+0WXjT+73RhS8g97Rfb6h0/W//5Az8UNZ6dp6XvUi2EJXQRhY5hkHiuwWT2W1ik+6wiiURkkrBACKbO1kmZWbVpRIe3Y3pcr3Q/V+oAcyPHRXCxu+JIe/j40/epuRrCyf8yvKsZ2Dnkl4QQmlwNqlW1F/arS+19G6zOG+6VKwtbI01A1R9SU1TYOA5UL/Qpo6Gyi3Ec3/irgQlzkq1rZrOIS4oo6tghul/zcG8rjno3luqHYwIZf8vAVfpwBesIVcANCOIuTRPU3A8vdmUoK/twGIchPapmjlAzLhjZ4KoAbNeMsWu3sN6kF44xofLMghos2X8OtvUA9CMD37v2FpYoM75qavyoivsBAbb6mG0p5TmkZ37BxfaGGP6SYrCa9ygQ==";
|
||||
String key = "f9d35b1133cff1f6e3960c89b249e03f";
|
||||
String license = "eQQm7gCZPF58Cy4i9OGkqSdFdDnFF0VSUVpw92WcrNLx7zVbpGJwjQhnKL8b0piApIbOTog5log/S1ZIxoUQogueaG84BQlJfRwKjtvpVWImlmhthQyQd2ogRqGkm3rkVGeG9wK49fzP3g5AtghNF05je2rQWd/Tyy/wutXq0e0rvR/bEckFaZ4BesQaYd0MejFC3lA8BjxNWiuvCKs15e1aRUOU5vwN5wsaTsTHokBIYhioSxOoGgHn6NrX6K9Dsl9uTWZ2dOVK/jEzYsNt6E/1Ww2ck1XmIWdRCQNmCpgikuPT0ACAL/w7UaRoWzM/Pm+akWqyp+bEavHT1Vhug3HAHOSGfOghGw2NerNlyEg8h6cVneMx+TsidnQ0ZG29aqdcLBRsvi26BYJJCA8+0WXjT+73RhS8g97Rfb6h0/W//5Az8UNZ6dp6XvUi2EJXQRhY5hkHiuwWT2W1ik+6wiiURkkrBACKbO1kmZWbVpRIe3Y3pcr3Q/V+oAcyPHRXCxu+JIe/j40/epuRrCyf8yvKsZ2Dnkl4QQmlwNqlW1F/arS+19G6zOG+6VKwtbI01A1R9SU1TYOA5UL/Qpo6Gyi3Ec3/irgQlzkq1rZrOIS4oo6tghul/zcG8rjno3luqHYwIZf8vAVfpwBesIVcANCOIuTRPU3A8vdmUoK/twGIchPapmjlAzLhjZ4KoAbNeMsWu3sN6kF44xofLMghos2X8OtvUA9CMD37v2FpYoM75qavyoivsBAbb6mG0p5TmkZ37BxfaGGP6SYrCa9ygQ==";
|
||||
|
||||
public final static int APP_STATUS_KILLED = 0; // 表示应用是被杀死后在启动的
|
||||
public final static int APP_STATUS_NORMAL = 1; // 表示应用时正常的启动流程
|
||||
public static int APP_STATUS = APP_STATUS_KILLED; // 记录App的启动状态
|
||||
private Context con;
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
con=getBaseContext();
|
||||
String state= SPUtil.getSP(con,"state_data","authorization_state");
|
||||
if("1".equals(state)){
|
||||
try{
|
||||
Context context = getApplicationContext();
|
||||
Resources res = getResources();
|
||||
Configuration config = new Configuration();
|
||||
config.setToDefaults();
|
||||
res.updateConfiguration(config, res.getDisplayMetrics());
|
||||
//安联初始化
|
||||
if (context.getPackageName().equals(getCurrentProcessName(context))) {
|
||||
//Log.e("--使用的测试环境--",BuildConfig.OPEN_API_URL);
|
||||
MDPLocationCollectionManager.initialize(this,"https://oapi.alct56.com");
|
||||
}
|
||||
//在使用SDK各组件之前初始化context信息,传入ApplicationContext
|
||||
// 路由初始化
|
||||
JVerificationInterface.setDebugMode(true);
|
||||
JVerificationInterface.init(this, 5000, (code, msg) -> Log.d("tag", "code = " + code + " msg = " + msg));
|
||||
//友盟
|
||||
//设置非debug版本开启
|
||||
if(!isDebugVersion(con)){
|
||||
youmenginit();
|
||||
}
|
||||
EsignSdk.getInstance().init(key,license);
|
||||
JTTProcess.init(this);
|
||||
//QupaiHttpFinal.getInstance().initOkHttpFinal();
|
||||
}catch (Exception e){
|
||||
Log.e("-error-","初始化失败sss");
|
||||
public static App mApplication = null;
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
mApplication = this;
|
||||
con = getBaseContext();
|
||||
CommonBaseLibrary.getInstance().init(this, Api.BASE_URL);
|
||||
String state = SPUtil.getSP(con, "state_data", "authorization_state");
|
||||
if ("1".equals(state)) {
|
||||
try {
|
||||
Context context = getApplicationContext();
|
||||
Resources res = getResources();
|
||||
Configuration config = new Configuration();
|
||||
config.setToDefaults();
|
||||
res.updateConfiguration(config, res.getDisplayMetrics());
|
||||
//安联初始化
|
||||
if (context.getPackageName().equals(getCurrentProcessName(context))) {
|
||||
//Log.e("--使用的测试环境--",BuildConfig.OPEN_API_URL);
|
||||
MDPLocationCollectionManager.initialize(this, "https://oapi.alct56.com");
|
||||
}
|
||||
//在使用SDK各组件之前初始化context信息,传入ApplicationContext
|
||||
// 路由初始化
|
||||
JVerificationInterface.setDebugMode(true);
|
||||
JVerificationInterface.init(this, 5000, (code, msg) -> Log.d("tag", "code = " + code + " msg = " + msg));
|
||||
//友盟
|
||||
//设置非debug版本开启
|
||||
if (!isDebugVersion(con)) {
|
||||
youmenginit();
|
||||
}
|
||||
EsignSdk.getInstance().init(key, license);
|
||||
JTTProcess.init(this);
|
||||
//QupaiHttpFinal.getInstance().initOkHttpFinal();
|
||||
} catch (Exception e) {
|
||||
Log.e("-error-", "初始化失败sss");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void youmenginit(){
|
||||
public static App getApp() {
|
||||
return mApplication;
|
||||
}
|
||||
|
||||
public void youmenginit() {
|
||||
//设置LOG开关,默认为false
|
||||
UMConfigure.setLogEnabled(true);
|
||||
//友盟预初始化
|
||||
UMConfigure.preInit(getApplicationContext(),"60fbfe87ff4d74541c81e01a","Umeng");
|
||||
UMConfigure.preInit(getApplicationContext(), "60fbfe87ff4d74541c81e01a", "Umeng");
|
||||
/**
|
||||
* 打开app首次隐私协议授权,以及sdk初始化,判断逻辑请查看SplashTestActivity
|
||||
*/
|
||||
//判断是否同意隐私协议,uminit为1时为已经同意,直接初始化umsdk
|
||||
// if(SPUtil.getSP(getAppContext(),"umeng","uminit").equals("1")){
|
||||
// if(SPUtil.getSP(getAppContext(),"umeng","uminit").equals("1")){
|
||||
//友盟正式初始化
|
||||
UMConfigure.init(getApplicationContext(),UMConfigure.DEVICE_TYPE_PHONE,"");
|
||||
UMConfigure.init(getApplicationContext(), UMConfigure.DEVICE_TYPE_PHONE, "");
|
||||
}
|
||||
|
||||
private static String getCurrentProcessName(Context context) {
|
||||
String currentProcessName = "";
|
||||
int pid = android.os.Process.myPid();
|
||||
ActivityManager mActivityManager = (ActivityManager) context .getSystemService(Context.ACTIVITY_SERVICE);
|
||||
ActivityManager mActivityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
||||
if (mActivityManager.getRunningAppProcesses() != null && mActivityManager.getRunningAppProcesses().size() > 0) {
|
||||
for (ActivityManager.RunningAppProcessInfo appProcess : mActivityManager.getRunningAppProcesses()) {
|
||||
if (appProcess.pid == pid) {
|
||||
|
@ -0,0 +1,21 @@
|
||||
package com.arpa.hndahesudintocctmsdriver.request.net;
|
||||
|
||||
|
||||
import com.arpa.hndahesudintocctmsdriver.BuildConfig;
|
||||
|
||||
/**
|
||||
* Created by Administrator on 2018/8/8 0008.
|
||||
*/
|
||||
|
||||
public interface Api {
|
||||
|
||||
String BASE_URL = "BuildConfig.BASE_URL";
|
||||
|
||||
|
||||
//获取版本
|
||||
String VERSION = BASE_URL + "app/version";
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,60 @@
|
||||
package com.arpa.hndahesudintocctmsdriver.request.net;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.dahe.mylibrary.net.CommonResponseBean;
|
||||
|
||||
import io.reactivex.Observer;
|
||||
import io.reactivex.annotations.NonNull;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
|
||||
|
||||
/**
|
||||
* 自定义观察者
|
||||
*/
|
||||
|
||||
public class BaseObserver<T> implements Observer<CommonResponseBean<T>> {
|
||||
private Context mContext;
|
||||
private RxHttpCallBack<T> mRxHttpCallBack;
|
||||
private Disposable disposable;
|
||||
|
||||
public BaseObserver(Context mContext, RxHttpCallBack<T> mRxHttpCallBack) {
|
||||
this.mContext = mContext;
|
||||
this.mRxHttpCallBack = mRxHttpCallBack;
|
||||
}
|
||||
|
||||
/**
|
||||
* 订阅成功
|
||||
*
|
||||
* @param d
|
||||
*/
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
this.disposable = d;
|
||||
mRxHttpCallBack.onStart();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onNext(CommonResponseBean<T> tCommonResponseBean) {
|
||||
if (200==tCommonResponseBean.getCode()) {
|
||||
mRxHttpCallBack.onSuccess(tCommonResponseBean);
|
||||
} else {
|
||||
mRxHttpCallBack.onCodeError(mContext, tCommonResponseBean);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
mRxHttpCallBack.onFailure(mContext, e);
|
||||
if (disposable!=null&&disposable.isDisposed()){
|
||||
disposable.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,161 @@
|
||||
package com.arpa.hndahesudintocctmsdriver.request.net;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.dahe.mylibrary.net.JsonUtils;
|
||||
import com.dahe.mylibrary.utils.MD5Utils;
|
||||
import com.dahe.mylibrary.utils.StringUtils;
|
||||
import com.dahe.mylibrary.utils.TimeUtil;
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
/**
|
||||
* Created by Administrator on 2017/4/15 0015.
|
||||
*/
|
||||
|
||||
public class CreateJsonUtils {
|
||||
public static CreateJsonUtils utils = null;
|
||||
private static final String TAG = "GetJsonUtils";
|
||||
|
||||
public static CreateJsonUtils getInstance() {
|
||||
if (null == utils) {
|
||||
synchronized (CreateJsonUtils.class) {
|
||||
if (null == utils) {
|
||||
utils = new CreateJsonUtils();
|
||||
}
|
||||
}
|
||||
}
|
||||
return utils;
|
||||
}
|
||||
|
||||
/**
|
||||
* 得到请求体的json数据
|
||||
*
|
||||
* @param key jsonObject的key
|
||||
* @param value jsonObject的value 如果要请求jsonObject里面嵌套jsonObject的value只需要传map 否就传简单的数据类型
|
||||
* @return
|
||||
*/
|
||||
public String getRequest(String[] key, Object[] value) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
for (int i = 0; i < key.length; i++) {
|
||||
if (value[i] instanceof Map) {
|
||||
Map<Object, Object> sonMap = new HashMap<>();
|
||||
Map<Object, Object> sonDateMap = (Map<Object, Object>) value[i];
|
||||
List<String> keyList = getMapKey(sonDateMap);
|
||||
for (int j = 0; j < keyList.size(); j++) {
|
||||
sonMap.put(keyList.get(j), sonDateMap.get(keyList.get(j)));
|
||||
}
|
||||
map.put(key[i], sonMap);
|
||||
} else if (value[i] instanceof List) {
|
||||
map.put(key[i], value[i]);
|
||||
} else if (value[i] instanceof String) {
|
||||
map.put(key[i], value[i].toString());
|
||||
} else {
|
||||
map.put(key[i], value[i]);
|
||||
}
|
||||
}
|
||||
map.put("api_key", "xccdb-power-bank");
|
||||
map.put("sign", MD5Utils.md5(JsonUtils.getInstance().getGson().toJson(map)));
|
||||
map.put("time", TimeUtil.getNowMills());
|
||||
Log.i(TAG, new Gson().toJson(map));
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取map里面的所有值
|
||||
*
|
||||
* @param hashmp
|
||||
* @return
|
||||
*/
|
||||
public List<String> getMapKey(Map hashmp) {
|
||||
List<String> list = new ArrayList<>();
|
||||
Set set = hashmp.keySet();
|
||||
Iterator iter = set.iterator();
|
||||
while (iter.hasNext()) {
|
||||
String key = (String) iter.next();
|
||||
list.add(key);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public Map<String, Integer> getPagerMap(int page, int count) {
|
||||
Map<String, Integer> map = new HashMap<>();
|
||||
map.put("page", page);
|
||||
map.put("count", count);
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* 无参数的请求
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Map<String, RequestBody> createRequestBody() {
|
||||
return createRequestBody(new String[]{}, new String[]{});
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成请求的body
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
public Map<String, RequestBody> createRequestBody(String[] key, Object[] value) {
|
||||
Map<String, RequestBody> requestBodyMap = new HashMap<>();
|
||||
Map<String, Object> requestDataMap = new HashMap<>();
|
||||
String signStr = "";
|
||||
for (int i = 0; i < key.length; i++) {
|
||||
requestDataMap.put(key[i], value[i]);
|
||||
}
|
||||
try {
|
||||
signStr = (sign1(requestDataMap) + "&api_key=xccdb-power-bank").replaceFirst("&", "");
|
||||
Log.i(TAG, "createRequestBody: " + sign1(requestDataMap));
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Log.i(TAG, "createRequestBody: " + signStr);
|
||||
for (String keySet : requestDataMap.keySet()) {
|
||||
requestBodyMap.put(keySet, RequestBody.create(MediaType.parse("multipart/form-data"), requestDataMap.get(keySet) + ""));
|
||||
}
|
||||
Log.i(TAG, "createRequestBody: " + MD5Utils.md5((signStr)));
|
||||
requestBodyMap.put("sign", RequestBody.create(MediaType.parse("multipart/form-data"),
|
||||
MD5Utils.md5((signStr))));
|
||||
requestBodyMap.put("time", RequestBody.create(MediaType.parse("multipart/form-data"), TimeUtil.getNowMills() / 1000 + ""));
|
||||
return requestBodyMap;
|
||||
}
|
||||
|
||||
public String sign1(Map params) throws JSONException {
|
||||
JSONObject header = new JSONObject(JsonUtils.getInstance().getGson().toJson(params));
|
||||
//获取header元素集合
|
||||
Iterator headerIt = header.keys();
|
||||
List<String> list = new ArrayList<String>();
|
||||
//把header元素集合迭代 出 "param=value"形式字符串放入list集合中
|
||||
while (headerIt.hasNext()) {
|
||||
String param = headerIt.next().toString();
|
||||
String value = StringUtils.encode(header.getString(param));
|
||||
list.add(param + "=" + value);
|
||||
}
|
||||
Collections.sort(list);
|
||||
String paramStr = "";
|
||||
//迭代list拼装签名sign
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
paramStr += "&" + list.get(i);
|
||||
}
|
||||
String signStr = paramStr;
|
||||
return signStr;
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
package com.arpa.hndahesudintocctmsdriver.request.net;
|
||||
|
||||
|
||||
import com.dahe.mylibrary.CommonBaseLibrary;
|
||||
import com.dahe.mylibrary.net.JsonInterceptor;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.rxjava3.core.Observable;
|
||||
import io.reactivex.rxjava3.core.ObservableSource;
|
||||
import io.reactivex.rxjava3.core.ObservableTransformer;
|
||||
import io.reactivex.rxjava3.schedulers.Schedulers;
|
||||
import okhttp3.OkHttpClient;
|
||||
|
||||
/**
|
||||
* Created by Administrator on 2018/8/8 0008.
|
||||
*/
|
||||
|
||||
public class DataManager {
|
||||
private volatile static DataManager mInstance;
|
||||
|
||||
public DataManager() {
|
||||
|
||||
}
|
||||
|
||||
public static <T> ObservableTransformer<T, T> setThread() {
|
||||
return new ObservableTransformer<T, T>() {
|
||||
@Override
|
||||
public ObservableSource<T> apply(Observable<T> upstream) {
|
||||
return upstream.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static Api getInstance() {
|
||||
if (null == mInstance) {
|
||||
synchronized (DataManager.class) {
|
||||
if (null == mInstance) {
|
||||
mInstance = new DataManager();
|
||||
}
|
||||
}
|
||||
}
|
||||
return api();
|
||||
}
|
||||
|
||||
public static Api api() {
|
||||
return CommonBaseLibrary.getRetrofit().newBuilder()
|
||||
.client(new OkHttpClient.Builder()
|
||||
.connectTimeout(30, TimeUnit.SECONDS)
|
||||
.readTimeout(30, TimeUnit.SECONDS)
|
||||
.writeTimeout(30, TimeUnit.SECONDS)
|
||||
.addInterceptor(new JsonInterceptor())
|
||||
.addInterceptor(new RequestHeadInterceptor())
|
||||
.build())
|
||||
// .addNetworkInterceptor(new TokenInterceptor())
|
||||
.build().create(Api.class);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package com.arpa.hndahesudintocctmsdriver.request.net;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.arpa.hndahesudintocctmsdriver.App;
|
||||
import com.arpa.hndahesudintocctmsdriver.ui.login.LoginActivity;
|
||||
import com.arpa.hndahesudintocctmsdriver.util.SPUtils;
|
||||
import com.arpa.hndahesudintocctmsdriver.util.sp.SPUtil;
|
||||
import com.dahe.mylibrary.utils.AppUtils;
|
||||
import com.dahe.mylibrary.utils.BaseUtils;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import okhttp3.Interceptor;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
|
||||
/**
|
||||
* 头部Interceptor
|
||||
*/
|
||||
|
||||
public class RequestHeadInterceptor implements Interceptor {
|
||||
private static final String TAG = "RequestHeadInterceptor";
|
||||
|
||||
@Override
|
||||
public Response intercept(Chain chain) throws IOException {
|
||||
Request.Builder builder = chain.request().newBuilder();
|
||||
if (!TextUtils.isEmpty(SPUtil.getSP(App.getApp(), LoginActivity.USER,LoginActivity.USER_TOKEN))) {
|
||||
// builder.addHeader("Authorization", SPUtils.getUserInfo(App.getApp()).getToken());
|
||||
builder.addHeader("Authorization", "Bearer "+SPUtil.getSP(App.getApp(), LoginActivity.USER,LoginActivity.USER_TOKEN));
|
||||
}
|
||||
Request request = builder
|
||||
.addHeader("versionCode", AppUtils.getAppVersionCode() + "")
|
||||
.addHeader("versionValue", AppUtils.getAppVersionName() + "")
|
||||
.addHeader("deviceType", "ANDROID")
|
||||
.addHeader("language", BaseUtils.getLanguage(App.getApp())+"")
|
||||
.build();
|
||||
Log.i(TAG, "intercept: " + request.headers());
|
||||
return chain.proceed(request);
|
||||
}
|
||||
}
|
@ -0,0 +1,132 @@
|
||||
package com.arpa.hndahesudintocctmsdriver.request.net;
|
||||
|
||||
import android.accounts.NetworkErrorException;
|
||||
import android.app.Activity;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.text.TextUtils;
|
||||
import android.view.Window;
|
||||
|
||||
import com.arpa.hndahesudintocctmsdriver.ui.login.LoginActivity;
|
||||
import com.dahe.mylibrary.net.CommonResponseBean;
|
||||
import com.dahe.mylibrary.net.ResultException;
|
||||
import com.dahe.mylibrary.utils.ToastUtils;
|
||||
|
||||
import java.net.ConnectException;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import javax.net.ssl.SSLException;
|
||||
|
||||
/**
|
||||
* 统一的网络回调
|
||||
*/
|
||||
|
||||
public abstract class RxHttpCallBack<T> {
|
||||
private ProgressDialog dialog;
|
||||
|
||||
private void initDialog(Activity activity, String dialogMessage) {
|
||||
dialog = new ProgressDialog(activity);
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setCanceledOnTouchOutside(false);
|
||||
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
|
||||
dialog.setMessage(dialogMessage);
|
||||
}
|
||||
|
||||
public RxHttpCallBack(Activity activity, String dialogMessage) {
|
||||
initDialog(activity, TextUtils.isEmpty(dialogMessage) ? "网络请求中......" : dialogMessage);
|
||||
}
|
||||
|
||||
public RxHttpCallBack(Activity activity) {
|
||||
initDialog(activity, "网络请求中......");
|
||||
}
|
||||
|
||||
public RxHttpCallBack() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 订阅成功
|
||||
*/
|
||||
public void onStart() {
|
||||
if (dialog != null && !dialog.isShowing()) {
|
||||
dialog.show();
|
||||
}
|
||||
}
|
||||
|
||||
public void onStop(){
|
||||
if (dialog != null && dialog.isShowing()) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回成功
|
||||
*
|
||||
* @param t
|
||||
* @throws Exception
|
||||
*/
|
||||
public void onSuccess(CommonResponseBean<T> t) {
|
||||
if (dialog != null && dialog.isShowing()) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回成功了,但是code错误
|
||||
*
|
||||
* @param t
|
||||
* @throws Exception
|
||||
*/
|
||||
public void onCodeError(Context mContext, CommonResponseBean<T> t) {
|
||||
if (dialog != null && dialog.isShowing()) {
|
||||
dialog.dismiss();
|
||||
|
||||
}
|
||||
if (t.getCode() == 401) {
|
||||
// UserUtils.Companion.getInstance().loginOut(mContext);
|
||||
Intent intent = new Intent(mContext, LoginActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
mContext.startActivity(intent);
|
||||
ToastUtils.showToast(mContext,"您的账号再异地登录,请重新登录");
|
||||
}else{
|
||||
ToastUtils.showToast(mContext,t.getMsg());
|
||||
}
|
||||
|
||||
// if (t.getMessage().getMsg_code() == 100 && SPUtils.hasUserInfo(mContext)) {
|
||||
// SPUtils.remove(mContext, SPUtils.USER_INFO_KEY);
|
||||
// } else {
|
||||
// ToastUtils.showToast(mContext, t.getMessage().getMsg_desc());
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回失败
|
||||
*
|
||||
* @param e
|
||||
* @throws Exception
|
||||
*/
|
||||
public void onFailure(Context mContext, Throwable e) {
|
||||
if (dialog != null && dialog.isShowing()) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
if (e instanceof ConnectException
|
||||
|| e instanceof TimeoutException
|
||||
|| e instanceof SocketTimeoutException
|
||||
|| e instanceof SSLException
|
||||
|| e instanceof NetworkErrorException
|
||||
|| e instanceof UnknownHostException) {
|
||||
ToastUtils.showToast(mContext, "请检查您的网络~");
|
||||
} else if (e instanceof ResultException) {
|
||||
e.printStackTrace();
|
||||
//自定义的ResultException
|
||||
//由于返回200,300返回格式不统一的问题,自定义GsonResponseBodyConverter凡是300的直接抛异常
|
||||
// System.out.println("---------errorCode------->"+((ResultException) e).getErrCode());
|
||||
}else if (e instanceof SSLException){
|
||||
ToastUtils.showToast(mContext, "网络连接终端,请检查您的网络~");
|
||||
}else{
|
||||
ToastUtils.showToast(mContext, e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package com.arpa.hndahesudintocctmsdriver.request.net;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import okhttp3.Interceptor;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.ResponseBody;
|
||||
import okio.Buffer;
|
||||
import okio.BufferedSource;
|
||||
|
||||
public class TokenInterceptor implements Interceptor {
|
||||
@Override
|
||||
public Response intercept(Chain chain) throws IOException {
|
||||
Request request = chain.request();
|
||||
Response response = chain.proceed(request);
|
||||
|
||||
ResponseBody responseBody = response.body();
|
||||
if (responseBody != null) {
|
||||
BufferedSource source = responseBody.source();
|
||||
source.request(Long.MAX_VALUE); // Buffer the entire body.
|
||||
Buffer buffer = source.buffer();
|
||||
try {
|
||||
String result = buffer.clone().readString(StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(result);
|
||||
int code = jsonObject.getInt("code");
|
||||
if (code == -1) {//判断返回code
|
||||
|
||||
// SPUtils.cleanUserInfo(App.getApp());
|
||||
// Intent intent = new Intent(App.getApp(), LoginActivity.class);
|
||||
// intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
// App.getApp().startActivity(intent);
|
||||
// ToastUtils.showToast(App.getApp(), "您的账号再异地登录,请重新登录");
|
||||
// ToastUtils.showShort("身份过期,请重新登录");
|
||||
//跳转方式
|
||||
//1.使用MyApplication添加跳转
|
||||
//2.使用路由跳转
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return response;
|
||||
}
|
||||
}
|
@ -0,0 +1,114 @@
|
||||
package com.arpa.hndahesudintocctmsdriver.util;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.arpa.hndahesudintocctmsdriver.bean.UserBean;
|
||||
import com.dahe.mylibrary.net.JsonUtils;
|
||||
import com.dahe.mylibrary.utils.BaseSPUtils;
|
||||
|
||||
|
||||
public class SPUtils extends BaseSPUtils {
|
||||
|
||||
/**
|
||||
* 存用户信息
|
||||
*
|
||||
* @param context
|
||||
* @param json
|
||||
*/
|
||||
public static void setUserInfo(Context context, String json) {
|
||||
put(context, USER_INFO_KEY, json);
|
||||
}
|
||||
|
||||
/**
|
||||
* 拿用户信息
|
||||
*
|
||||
* @param context
|
||||
*/
|
||||
public static UserBean getUserInfo(Context context) {
|
||||
return JsonUtils.getInstance().fromJson((String) get(context, USER_INFO_KEY, ""), UserBean.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 存服务器类型
|
||||
*
|
||||
* @param context
|
||||
* @param isTestService
|
||||
*/
|
||||
public static void setNetServiceType(Context context, boolean isTestService) {
|
||||
put(context, NET_SERVICE_TEST, isTestService);
|
||||
}
|
||||
|
||||
/**
|
||||
* 拿服务器类型
|
||||
*
|
||||
* @param context
|
||||
*/
|
||||
public static boolean geNetServiceType(Context context) {
|
||||
return (boolean) get(context, NET_SERVICE_TEST, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 存搜索数据
|
||||
*
|
||||
* @param context
|
||||
* @param json
|
||||
*/
|
||||
public static void setSearchCache(Context context, String json) {
|
||||
put(context, SEARRH_CACHE, json);
|
||||
}
|
||||
|
||||
public static String getSearchCache(Context context) {
|
||||
return JsonUtils.getInstance().fromJson((String) get(context, SEARRH_CACHE, ""), String.class);
|
||||
}
|
||||
|
||||
public static void removeSearchCache(Context context) {
|
||||
remove(context, SEARRH_CACHE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导航偏好设置
|
||||
*/
|
||||
public static void setNaviPreferenceCache(Context context, String json) {
|
||||
put(context, NAVI_PH_EDIT_CACHE, json);
|
||||
}
|
||||
|
||||
public static String getNaviPreferenceCache(Context context) {
|
||||
return JsonUtils.getInstance().fromJson((String) get(context, NAVI_PH_EDIT_CACHE, ""), String.class);
|
||||
}
|
||||
|
||||
public static void removeNaviPreference(Context context) {
|
||||
remove(context, NAVI_PH_EDIT_CACHE);
|
||||
}
|
||||
|
||||
//第一次登录
|
||||
public static boolean getIsFirstOpen(Context context){
|
||||
boolean b = (boolean) get(context, FIRST_OPEN, true);
|
||||
return b;
|
||||
|
||||
}
|
||||
|
||||
public static void setIsFirstOpen(Context context, boolean json){
|
||||
put(context, FIRST_OPEN, json);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设置隐私协议是否同意
|
||||
*
|
||||
* @param value 是否同意
|
||||
*/
|
||||
public static void setAgreePrivacyAgreement(Context context, boolean value) {
|
||||
put(context, KEY_PRIVACY_AGREEMENT, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否同意了隐私协议
|
||||
*
|
||||
* @return true 已经同意;false 还没有同意
|
||||
*/
|
||||
public static boolean hasAgreePrivacyAgreement(Context context) {
|
||||
boolean b = (boolean) get(context, KEY_PRIVACY_AGREEMENT, false);
|
||||
return b;
|
||||
}
|
||||
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
apply from: "compile.gradle"
|
||||
buildscript {
|
||||
ext.kotlin_version = "1.5.0"
|
||||
repositories {
|
||||
|
88
compile.gradle
Normal file
88
compile.gradle
Normal file
@ -0,0 +1,88 @@
|
||||
def SupportVersion = '28.0.0'
|
||||
def ButterKnifeVersion = '10.0.0'
|
||||
def CrashActivityVersion = '2.2.0'
|
||||
def StatusBarVersion = '2.3.3'
|
||||
def GsonVersion = '2.8.5'
|
||||
def PhotoPickerVersion = 'v2.6.1'
|
||||
//def PhotoPickerVersion = 'v2.7.2'
|
||||
def GlideVersion = '4.12.0'
|
||||
def AgentWebVersion = 'v4.1.9-androidx'
|
||||
def NiceDialogVersion = '1.1.9'
|
||||
def AndPermissionVersion = '2.0.3'
|
||||
def BannerVersion = '1.4.10'
|
||||
def SmartRefreshLayoutVersion = '1.1.0-alpha-12'
|
||||
def MultideXVersion = '2.0.1'
|
||||
def RXJavaVersion = '3.0.12'
|
||||
def RXAndroidVersion = '3.0.0'
|
||||
def RetrofitVersion = '2.9.0'
|
||||
def OkHttpVersion = '4.9.1'
|
||||
def AutoSizeVersion = '1.1.2'
|
||||
def FlycoTabLayoutVersion = '2.1.2@aar'
|
||||
def ZxingVersion = '1.3.8'
|
||||
def BaseRecyclerViewAdapterHelper = '3.0.6'
|
||||
def MagicIndicator = '1.7.0'
|
||||
def PickerView = '4.1.9'
|
||||
def NiceSpinner = '1.4.4'
|
||||
def Countdownview = '2.1.6'
|
||||
def Xpopup = '2.2.23'
|
||||
def CheckVersionLib = '2.4.1_androidx'
|
||||
def GooglePlayVersion = '15.0.1'
|
||||
def Streamsupport = '1.7.3'
|
||||
def NewbieGuideVersion = 'v2.4.0'
|
||||
def CountdownviewVersion = '2.1.6'
|
||||
def JpushVersion = '3.1.8'
|
||||
def JcoreVersion = '1.2.7'
|
||||
def BuglyVersion = 'latest.release'
|
||||
project.ext {
|
||||
android = [
|
||||
compileSdkVersion: 30,
|
||||
buildToolsVersion: "30.0.3",
|
||||
applicationId : "com.dahe.examine",
|
||||
minSdkVersion : 21,
|
||||
targetSdkVersion : 30,
|
||||
versionCode : 5,
|
||||
versionName : "1.0.5",
|
||||
]
|
||||
dependencies = [
|
||||
"appcompat-v7" : "com.android.support:appcompat-v7:${SupportVersion}",
|
||||
"support-v4" : "com.android.support:support-v4:${SupportVersion}",
|
||||
"support-design" : "com.android.support:design:${SupportVersion}",
|
||||
"recyclerview" : "com.android.support:recyclerview-v7:${SupportVersion}",
|
||||
"butterknife" : "com.jakewharton:butterknife:${ButterKnifeVersion}",
|
||||
"butterknife-compiler" : "com.jakewharton:butterknife-compiler:${ButterKnifeVersion}",
|
||||
"customactivityoncrash": "cat.ereza:customactivityoncrash:${CrashActivityVersion}",
|
||||
"gson" : "com.google.code.gson:gson:${GsonVersion}",
|
||||
"PhotoPicker" : "com.github.LuckSiege.PictureSelector:picture_library:${PhotoPickerVersion}",
|
||||
// "PhotoPicker" : "io.github.lucksiege:pictureselector:${PhotoPickerVersion}",
|
||||
"agentweb" : "com.github.Justson.AgentWeb:agentweb-core:${AgentWebVersion}",
|
||||
"statusbaruitl" : "com.github.niorgai:StatusBarCompat:${StatusBarVersion}",
|
||||
"glide" : "com.github.bumptech.glide:glide:${GlideVersion}",
|
||||
"glide-compiler" : "com.github.bumptech.glide:compiler:${GlideVersion}",
|
||||
"glide-okhttps" : "com.github.bumptech.glide:okhttp3-integration:${GlideVersion}",
|
||||
"NiceDialog" : "com.github.Othershe:NiceDialog:${NiceDialogVersion}",
|
||||
"Banner" : "com.youth.banner:banner:${BannerVersion}",
|
||||
"RefreshLayout" : "com.scwang.smartrefresh:SmartRefreshLayout:${SmartRefreshLayoutVersion}",
|
||||
"Multidex" : "androidx.multidex:multidex:${MultideXVersion}",
|
||||
"rxjava" : "io.reactivex.rxjava3:rxjava:${RXJavaVersion}",
|
||||
"rxandroid" : "io.reactivex.rxjava3:rxandroid:${RXAndroidVersion}",
|
||||
"retrofit" : "com.squareup.retrofit2:retrofit:${RetrofitVersion}",
|
||||
"converter-gson" : "com.squareup.retrofit2:converter-gson:${RetrofitVersion}",
|
||||
"adapter-rxjava2" : "com.squareup.retrofit2:adapter-rxjava3:${RetrofitVersion}",
|
||||
"okhttp" : "com.squareup.okhttp3:okhttp:${OkHttpVersion}",
|
||||
"logging-interceptor" : "com.squareup.okhttp3:logging-interceptor:${OkHttpVersion}",
|
||||
"AutoSize" : "me.jessyan:autosize:${AutoSizeVersion}",
|
||||
"FlycoTabLayout" : "com.flyco.tablayout:FlycoTabLayout_Lib:${FlycoTabLayoutVersion}",
|
||||
"AndPermission" : "com.yanzhenjie:permission:${AndPermissionVersion}",
|
||||
// "Zxing" : "cn.bingoogolapple:bga-qrcode-zxing:${ZxingVersion}",
|
||||
"Zxing" : "com.github.bingoogolapple.BGAQRCode-Android:zxing:${ZxingVersion}",
|
||||
"BaseRecyclerViewAdapterHelper" :"com.github.CymChad:BaseRecyclerViewAdapterHelper:${BaseRecyclerViewAdapterHelper}",
|
||||
"MagicIndicator" :"com.github.hackware1993:MagicIndicator:${MagicIndicator}",
|
||||
"NiceSpinner" :"com.github.arcadefire:nice-spinner:${NiceSpinner}",
|
||||
"Countdownview" :"com.github.iwgang:countdownview:${Countdownview}",
|
||||
"Xpopup" :"com.lxj:xpopup:${Xpopup}",
|
||||
"CheckVersionLib" :"com.github.AlexLiuSheng:CheckVersionLib:${CheckVersionLib}",
|
||||
"Bugly" :"com.tencent.bugly:crashreport:${BuglyVersion}",
|
||||
"Streamsupport" :"net.sourceforge.streamsupport:streamsupport:${Streamsupport}",
|
||||
"PickerView" :"com.contrarywind:Android-PickerView:${PickerView}"
|
||||
]
|
||||
}
|
@ -5,3 +5,4 @@ include ':app'
|
||||
include ':record'
|
||||
//include ':ocr_ui'
|
||||
//include ':AliyunListPlayer'
|
||||
include ':mylibrary'
|
||||
|
Loading…
Reference in New Issue
Block a user