Merge branch 'qa_hengyang_base' into dev_hengyang_base
This commit is contained in:
@@ -9,6 +9,7 @@ import androidx.annotation.Nullable;
|
||||
|
||||
import com.alibaba.android.arouter.facade.annotation.Route;
|
||||
import com.mogo.cloud.passport.MoGoAiCloudClientConfig;
|
||||
import com.mogo.commons.constants.SharedPrefsConstants;
|
||||
import com.mogo.commons.debug.DebugConfig;
|
||||
import com.mogo.commons.network.Utils;
|
||||
import com.mogo.httpdns.HttpDnsConst;
|
||||
@@ -23,6 +24,7 @@ import com.mogo.httpdnshelper.sdk.listener.OnAddressChangedListener;
|
||||
import com.mogo.utils.httpdns.HttpSimpleLocation;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
import com.mogo.utils.network.HttpDns;
|
||||
import com.mogo.utils.storage.SharedPrefsMgr;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
@@ -37,6 +39,7 @@ import static com.mogo.httpdns.HttpDnsConst.HTTP_DNS_ADDRESS_TYPE_HTTP;
|
||||
@Keep
|
||||
@Route(path = HttpDnsConst.PATH)
|
||||
public class MogoHttpDns implements IMogoHttpDns, HttpDns, OnAddressChangedListener {
|
||||
private static final String TAG = "MogoHttpDns";
|
||||
private HttpDnsHelper httpDnsHelper;
|
||||
|
||||
@Nullable
|
||||
@@ -52,7 +55,7 @@ public class MogoHttpDns implements IMogoHttpDns, HttpDns, OnAddressChangedListe
|
||||
|
||||
@Override
|
||||
public String syncGetHttpDns(String host, int type, boolean useCache) {
|
||||
Logger.d("MogoHttpDns", "getHttpDnsIp host: " + host + " type: " + type);
|
||||
Logger.d(TAG, "getHttpDnsIp host: " + host + " type: " + type);
|
||||
Map<String, String> map = httpDnsHelper.getAllAddress();
|
||||
if (useCache) {
|
||||
String address = httpDnsHelper.getHttpDnsCachedAddress(type, host);
|
||||
@@ -68,7 +71,7 @@ public class MogoHttpDns implements IMogoHttpDns, HttpDns, OnAddressChangedListe
|
||||
|
||||
@Override
|
||||
public void getHttpDnsIp(String host, int type, boolean useCache, IHttpDnsCallback callback) {
|
||||
Logger.d("MogoHttpDns", "getHttpDnsIp host: " + host + " type: " + type);
|
||||
Logger.d(TAG, "getHttpDnsIp host: " + host + " type: " + type);
|
||||
Map<String, String> map = httpDnsHelper.getAllAddress();
|
||||
if (useCache) {
|
||||
String address = httpDnsHelper.getHttpDnsCachedAddress(type, host);
|
||||
@@ -86,7 +89,7 @@ public class MogoHttpDns implements IMogoHttpDns, HttpDns, OnAddressChangedListe
|
||||
|
||||
@Override
|
||||
public void addHttpDnsTtlCallback(String host, int type, IHttpDnsTtlCallback callback) {
|
||||
Logger.d("MogoHttpDns", "addHttpDnsTtlCallback: host: " + host + " type: " + type);
|
||||
Logger.d(TAG, "addHttpDnsTtlCallback: host: " + host + " type: " + type);
|
||||
if (ttlCallbackMap.get(type + "-" + host) == null) {
|
||||
ttlCallbackMap.put(type + "-" + host, new ArrayList<IHttpDnsTtlCallback>());
|
||||
}
|
||||
@@ -105,17 +108,42 @@ public class MogoHttpDns implements IMogoHttpDns, HttpDns, OnAddressChangedListe
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(Context context, final IHttpDnsLocationChanged locationChanged) {
|
||||
// .setDefaultUrl("dzt.zhidaozhixing.com")
|
||||
public void init(final Context context, final IHttpDnsLocationChanged locationChanged) {
|
||||
httpDnsHelper = new HttpDnsHelper.Builder().setContext(context).setEnv(DebugConfig.getNetMode()).setSn(MoGoAiCloudClientConfig.getInstance().getSn()).setShowDebugLog(true).setLoopCheckDelay(15 * 60 * 1000).setCurrentLocation(new IHttpDnsCurrentLocation() {
|
||||
@org.jetbrains.annotations.Nullable
|
||||
@Override
|
||||
public HttpDnsSimpleLocation getCurrentLocation() {
|
||||
HttpSimpleLocation simpleLocation = locationChanged.getLocation();
|
||||
if (simpleLocation != null) {
|
||||
return new HttpDnsSimpleLocation("010", simpleLocation.getLat(), simpleLocation.getLon());
|
||||
|
||||
|
||||
HttpDnsSimpleLocation httpDnsSimpleLocation;
|
||||
if (simpleLocation != null
|
||||
&& simpleLocation.getLat() != 0
|
||||
&& simpleLocation.getLon() != 0) {
|
||||
httpDnsSimpleLocation = new HttpDnsSimpleLocation(
|
||||
simpleLocation.getCityCode(),
|
||||
simpleLocation.getLat(),
|
||||
simpleLocation.getLon());
|
||||
Logger.i(TAG, "使用实时GPS信息:" + httpDnsSimpleLocation);
|
||||
} else {
|
||||
String ciyCode = SharedPrefsMgr.getInstance(context)
|
||||
.getString(SharedPrefsConstants.LOCATION_CITY_CODE);
|
||||
String latitude = SharedPrefsMgr.getInstance(context)
|
||||
.getString(SharedPrefsConstants.LOCATION_LATITUDE);
|
||||
String longitude = SharedPrefsMgr.getInstance(context)
|
||||
.getString(SharedPrefsConstants.LOCATION_LONGITUDE);
|
||||
try {
|
||||
httpDnsSimpleLocation = new HttpDnsSimpleLocation(
|
||||
ciyCode,
|
||||
Double.parseDouble(latitude),
|
||||
Double.parseDouble(longitude));
|
||||
} catch (NumberFormatException e) {
|
||||
e.printStackTrace();
|
||||
httpDnsSimpleLocation = new HttpDnsSimpleLocation("010", 1, 1);
|
||||
}
|
||||
Logger.i(TAG, "使用缓存GPS信息:" + httpDnsSimpleLocation);
|
||||
}
|
||||
return null;
|
||||
return httpDnsSimpleLocation;
|
||||
}
|
||||
}).build();
|
||||
httpDnsHelper.setAddressChangedListener(this);
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.mogo.commons.constants;
|
||||
|
||||
/**
|
||||
* @author xiaoyuzhou
|
||||
* @date 2021/6/24 5:09 下午
|
||||
* <p>
|
||||
* 本地存储使用的常量
|
||||
*/
|
||||
public class SharedPrefsConstants {
|
||||
|
||||
// 当前城市编码
|
||||
public static final String LOCATION_CITY_CODE = "location_city_code";
|
||||
// 当前城市经纬度
|
||||
public static final String LOCATION_LATITUDE = "location_latitude";
|
||||
public static final String LOCATION_LONGITUDE = "location_longitude";
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user