httpdns singleton

This commit is contained in:
tongchenfei
2021-01-05 14:02:48 +08:00
parent 61c380ff23
commit a121f3d2bd
9 changed files with 91 additions and 10 deletions

1
.idea/gradle.xml generated
View File

@@ -85,6 +85,7 @@
</set>
</option>
<option name="resolveModulePerSourceSet" value="false" />
<option name="useQualifiedModuleNames" value="true" />
</GradleProjectSettings>
</option>
</component>

View File

@@ -12,6 +12,7 @@ import com.bytedance.boost_multidex.BoostMultiDex;
import com.mogo.commons.AbsMogoApplication;
import com.mogo.commons.debug.DebugConfig;
import com.mogo.commons.network.Utils;
import com.mogo.map.location.MogoLocation;
import com.mogo.module.authorize.authprovider.invoke.AuthorizeConstant;
import com.mogo.module.carchatting.card.CallChatConstant;
import com.mogo.module.common.MogoApisHandler;
@@ -30,6 +31,7 @@ import com.mogo.service.passport.IMogoTicketCallback;
import com.mogo.test.crashreport.ITestCrashReportProvider;
import com.mogo.utils.ProcessUtils;
import com.mogo.utils.UiThreadHandler;
import com.mogo.utils.httpdns.HttpSimpleLocation;
import com.mogo.utils.logger.LogLevel;
import com.mogo.utils.logger.Logger;
import com.mogo.utils.storage.SharedPrefsMgr;
@@ -157,6 +159,16 @@ public class MogoApplication extends AbsMogoApplication {
prepareBaseService( apis, 2_000L );
}
@Override
protected HttpSimpleLocation getCurrentLocation() {
MogoLocation location = MogoApisHandler.getInstance().getApis().getMapServiceApi().getSingletonLocationClient(this).getLastKnowLocation();
if (location == null) {
return null;
}else {
return new HttpSimpleLocation(location.getCityCode(), location.getLatitude(), location.getLongitude());
}
}
/**
* 基础服务passport、location、socket
*/

View File

@@ -0,0 +1,13 @@
package com.mogo.httpdns;
import android.location.Location;
import com.mogo.utils.httpdns.HttpSimpleLocation;
public interface IHttpDnsLocationChanged {
/**
* 获取当前定位
* @return 当前定位
*/
HttpSimpleLocation getLocation();
}

View File

@@ -1,5 +1,7 @@
package com.mogo.httpdns;
import android.content.Context;
import androidx.annotation.Keep;
import androidx.annotation.Nullable;
@@ -95,4 +97,12 @@ interface IMogoHttpDns extends IProvider {
*/
@Keep
void removeHttpDnsTtlCallback(String host,int type);
/**
* 初始化
*
* @param context 上下文
* @param locationChanged 定位发生变化
*/
void init(Context context, IHttpDnsLocationChanged locationChanged);
}

View File

@@ -37,11 +37,9 @@ dependencies {
if (Boolean.valueOf(RELEASE)) {
implementation rootProject.ext.dependencies.httpdnsbase
implementation rootProject.ext.dependencies.mogocommons
implementation rootProject.ext.dependencies.modulecommon
} else {
implementation project(':foudations:httpdns-base')
implementation project(':foudations:mogo-commons')
implementation project(':modules:mogo-module-common')
}
}

View File

@@ -1,7 +1,6 @@
package com.mogo.httpdns.mogo;
import android.content.Context;
import android.os.Debug;
import android.text.TextUtils;
import android.util.ArrayMap;
@@ -12,14 +11,14 @@ import com.mogo.commons.debug.DebugConfig;
import com.mogo.commons.network.Utils;
import com.mogo.httpdns.HttpDnsConst;
import com.mogo.httpdns.IHttpDnsCallback;
import com.mogo.httpdns.IHttpDnsLocationChanged;
import com.mogo.httpdns.IHttpDnsTtlCallback;
import com.mogo.httpdns.IMogoHttpDns;
import com.mogo.httpdnshelper.sdk.HttpDnsHelper;
import com.mogo.httpdnshelper.sdk.bean.HttpDnsSimpleLocation;
import com.mogo.httpdnshelper.sdk.listener.IHttpDnsCurrentLocation;
import com.mogo.httpdnshelper.sdk.listener.OnAddressChangedListener;
import com.mogo.map.location.MogoLocation;
import com.mogo.module.common.MogoApisHandler;
import com.mogo.utils.httpdns.HttpSimpleLocation;
import com.mogo.utils.logger.Logger;
import com.mogo.utils.network.HttpDns;
@@ -83,13 +82,18 @@ public class MogoHttpDns implements IMogoHttpDns, HttpDns, OnAddressChangedListe
@Override
public void init(final Context context) {
}
@Override
public void init(Context context, final IHttpDnsLocationChanged locationChanged) {
httpDnsHelper = new HttpDnsHelper.Builder().setContext(context).setEnv(DebugConfig.getNetMode()).setSn(Utils.getSn()).setShowDebugLog(true).setLoopCheckDelay(15 * 60 * 1000).setCurrentLocation(new IHttpDnsCurrentLocation() {
@org.jetbrains.annotations.Nullable
@Override
public HttpDnsSimpleLocation getCurrentLocation() {
MogoLocation last = MogoApisHandler.getInstance().getApis().getMapServiceApi().getSingletonLocationClient(context).getLastKnowLocation();
if (last != null) {
return new HttpDnsSimpleLocation(last.getCityCode(), last.getLatitude(), last.getLongitude());
HttpSimpleLocation simpleLocation = locationChanged.getLocation();
if (simpleLocation != null) {
return new HttpDnsSimpleLocation("0734", simpleLocation.getLat(), simpleLocation.getLon());
}
return null;
}
@@ -121,7 +125,7 @@ public class MogoHttpDns implements IMogoHttpDns, HttpDns, OnAddressChangedListe
}
@Override
public void onAddressChanged(@org.jetbrains.annotations.Nullable Map<String, String> map) {
public void onAddressChanged(Map<String, String> map) {
if (map != null) {
for (String key : map.keySet()) {
if (ttlCallbackMap.get(key) != null) {

View File

@@ -28,7 +28,7 @@ public class WebSocketDnsManager {
public void getHttpDnsIp(WebSocketDns webSocketDns) {
this.webSocketDns = webSocketDns;
IMogoHttpDns mogoHttpDns = ARouter.getInstance().navigation(IMogoHttpDns.class);
IMogoHttpDns mogoHttpDns = MogoHttpDnsHandler.getHttpDnsApi();
ThreadPoolService.execute(() -> mogoHttpDns.getHttpDnsIp(WebSocketConstant.getDomain(), HttpDnsConst.HTTP_DNS_ADDRESS_TYPE_WS,false, ip -> {
Logger.d(TAG, "getHttpDnsIp ip : " + ip + " , 得到Dns IP,准备回调 初始化webSocket");
this.cacheIp = ip;

View File

@@ -24,6 +24,7 @@ import com.mogo.httpdns.MogoHttpDnsHandler;
import com.mogo.utils.ThreadPoolService;
import com.mogo.utils.TipDrawable;
import com.mogo.utils.TipToast;
import com.mogo.utils.httpdns.HttpSimpleLocation;
import com.mogo.utils.network.NetConfig;
import java.security.SecureRandom;
@@ -87,6 +88,7 @@ public abstract class AbsMogoApplication extends Application {
}
private void syncInit() {
MogoHttpDnsHandler.getHttpDnsApi().init(this, this::getCurrentLocation);
TipToast.init( this, ( ( context, message, tipDrawable ) -> {
if ( TextUtils.isEmpty( message ) ) {
return null;
@@ -100,6 +102,10 @@ public abstract class AbsMogoApplication extends Application {
} ) );
}
protected HttpSimpleLocation getCurrentLocation(){
return null;
}
private View generateToastView( Context context, String message, TipDrawable tipDrawable){
View contentView;
if(tipDrawable==null) {

View File

@@ -0,0 +1,37 @@
package com.mogo.utils.httpdns;
public class HttpSimpleLocation {
private String cityCode;
private double lat;
private double lon;
public HttpSimpleLocation(String cityCode, double lat, double lon) {
this.cityCode = cityCode;
this.lat = lat;
this.lon = lon;
}
public String getCityCode() {
return cityCode;
}
public void setCityCode(String cityCode) {
this.cityCode = cityCode;
}
public double getLat() {
return lat;
}
public void setLat(double lat) {
this.lat = lat;
}
public double getLon() {
return lon;
}
public void setLon(double lon) {
this.lon = lon;
}
}