1. 增加延时检测空接口访问

2. opt TopViewAnimHelper
This commit is contained in:
tongchenfei
2020-12-24 15:45:24 +08:00
parent bf05411d3d
commit ceaa1cd33a
12 changed files with 483 additions and 170 deletions

View File

@@ -1,26 +0,0 @@
package com.mogo.module.extensions.net;
import com.mogo.commons.data.BaseData;
import java.util.Map;
import io.reactivex.Observable;
import retrofit2.http.FieldMap;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.GET;
import retrofit2.http.POST;
/**
* 时延验证相关接口
*
* @author tongchenfei
*/
public interface DelayCheckApiServices {
@GET("/yycp-test-service/net/delay/heartbeat")
Observable<BaseData> emptyInterface();
@POST("/yycp-test-service/net/delay/log")
@FormUrlEncoded
Observable<BaseData> uploadDelayCheckData(@FieldMap Map<String, Object> params);
}

View File

@@ -1,142 +0,0 @@
package com.mogo.module.extensions.utils;
import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.os.SystemClock;
import com.mogo.commons.data.BaseData;
import com.mogo.commons.network.SubscribeImpl;
import com.mogo.commons.network.Utils;
import com.mogo.map.location.MogoLocation;
import com.mogo.module.common.MogoApisHandler;
import com.mogo.module.extensions.net.DelayCheckApiServices;
import com.mogo.module.extensions.net.DztHttpConstant;
import com.mogo.utils.NetworkUtils;
import com.mogo.utils.network.RequestOptions;
import java.util.HashMap;
import java.util.Map;
import io.reactivex.schedulers.Schedulers;
/**
* 延时验证工具类
*
* @author tongchenfei
*/
public class DelayCheckUtil implements Handler.Callback {
private final Handler handler = new Handler(this);
private static final int MSG_CHECK_NET_CONNECT_STATUS = 1001;
private static final long FIRST_CHECK_NET_CONNECT_STATUS_DELAY = 10 * 60 * 1000;
private static final long CHECK_NET_CONNECT_STATUS_DELAY = 5000L;
private static final int MSG_START_DELAY_CHECK = 1002;
private static final long DELAY_CHECK_DELAY = 10 * 60 * 1000;
private final Context context;
public DelayCheckUtil(Context context) {
this.context = context;
}
/**
* 每5s检查一下网络状态网络状态为连接状态时开始空接口请求以及后续的参数上报
*/
public void waitingForCheck() {
handler.sendEmptyMessageDelayed(MSG_CHECK_NET_CONNECT_STATUS, FIRST_CHECK_NET_CONNECT_STATUS_DELAY);
}
private long requestTime, netDelay, requestSystemTime;
@Override
public boolean handleMessage(Message msg) {
switch (msg.what) {
case MSG_CHECK_NET_CONNECT_STATUS:
if (NetworkUtils.isConnected(context)) {
handler.sendEmptyMessage(MSG_START_DELAY_CHECK);
} else {
handler.sendEmptyMessageDelayed(MSG_CHECK_NET_CONNECT_STATUS, CHECK_NET_CONNECT_STATUS_DELAY);
}
return true;
case MSG_START_DELAY_CHECK:
// 请求空接口
startEmptyRequest();
return true;
default:
return false;
}
}
private void startEmptyRequest() {
requestTime = SystemClock.elapsedRealtime();
requestSystemTime = System.currentTimeMillis();
MogoApisHandler.getInstance().getApis().getNetworkApi()
.create(DelayCheckApiServices.class, DztHttpConstant.getBaseUrl())
.emptyInterface().subscribeOn(Schedulers.io()).observeOn(Schedulers.io())
.subscribe(new SubscribeImpl<BaseData>(RequestOptions.create(context)) {
@Override
public void onSuccess(BaseData o) {
super.onSuccess(o);
netDelay = SystemClock.elapsedRealtime() - requestTime;
startUpload();
}
@Override
public void onError(Throwable e) {
super.onError(e);
handler.sendEmptyMessageDelayed(MSG_CHECK_NET_CONNECT_STATUS, CHECK_NET_CONNECT_STATUS_DELAY);
}
@Override
public void onError(String message, int code) {
super.onError(message, code);
handler.sendEmptyMessageDelayed(MSG_CHECK_NET_CONNECT_STATUS, CHECK_NET_CONNECT_STATUS_DELAY);
}
});
}
private void startUpload() {
MogoLocation lastLocation = MogoApisHandler.getInstance().getApis().getMapServiceApi().getSingletonLocationClient(context).getLastKnowLocation();
if (lastLocation == null) {
handler.sendEmptyMessageDelayed(MSG_START_DELAY_CHECK, DELAY_CHECK_DELAY);
return;
}
Map<String, Object> params = new HashMap<>(8);
params.put("sn", Utils.getSn());
params.put("startTime", requestSystemTime);
params.put("endTime", System.currentTimeMillis());
params.put("netState", NetworkUtils.netStrengthLevel);
params.put("place", lastLocation.getAddress());
params.put("cityCode", lastLocation.getCityCode());
params.put("lat", lastLocation.getLatitude());
params.put("lon", lastLocation.getLongitude());
MogoApisHandler.getInstance().getApis().getNetworkApi()
.create(DelayCheckApiServices.class, DztHttpConstant.getBaseUrl())
.uploadDelayCheckData(params).observeOn(Schedulers.io()).subscribeOn(Schedulers.io())
.subscribe(new SubscribeImpl<BaseData>(RequestOptions.create(context)) {
@Override
public void onSuccess(BaseData o) {
super.onSuccess(o);
handler.sendEmptyMessageDelayed(MSG_START_DELAY_CHECK, DELAY_CHECK_DELAY);
}
@Override
public void onError(String message, int code) {
super.onError(message, code);
handler.sendEmptyMessageDelayed(MSG_CHECK_NET_CONNECT_STATUS, CHECK_NET_CONNECT_STATUS_DELAY);
}
@Override
public void onError(Throwable e) {
super.onError(e);
handler.sendEmptyMessageDelayed(MSG_CHECK_NET_CONNECT_STATUS, CHECK_NET_CONNECT_STATUS_DELAY);
}
});
}
}

View File

@@ -292,12 +292,12 @@ public class TopViewAnimHelper {
int scene = 0;
if (animNavInfoView.isVisible()) {
scene = Scene.NAVI_WITH_ROAD_EVENT;
animNavInfoView.animate().translationY(computeNaviMarginTop(child.getHeight())).start();
animNavInfoView.animate().translationY(computeNaviMarginTop(params.height)).start();
animNavInfoView.exchangeToSmall(true);
} else {
scene = Scene.AIMLESS_WITH_ROAD_EVENT;
}
topContainer.animate().translationY(child.getHeight()).setListener(mainAnimListener).start();
topContainer.animate().translationY(params.height).setListener(mainAnimListener).start();
Logger.d(TAG, "show top setMapCenterPointByScene: " + scene);
MapCenterPointStrategy.setMapCenterPointByScene(mogoMapUIController, scene);
} catch (Exception e) {