From 87c60788aab340ff646025cc9b70bdbd1a3dbdb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=91=A3=E5=AE=8F=E5=AE=87?= Date: Wed, 15 Jan 2020 19:45:05 +0800 Subject: [PATCH] =?UTF-8?q?=20=E5=A2=9E=E5=8A=A0=E4=BA=86=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E5=9C=A8=E7=BA=BF=E7=94=A8=E6=88=B7=E7=9A=84=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/service/network/RefreshBody.java | 13 ++- .../module/service/network/RefreshModel.java | 91 ++++++++++++++----- 2 files changed, 77 insertions(+), 27 deletions(-) diff --git a/modules/mogo-module-service/src/main/java/com/mogo/module/service/network/RefreshBody.java b/modules/mogo-module-service/src/main/java/com/mogo/module/service/network/RefreshBody.java index 2200ed394a..281ecdef93 100644 --- a/modules/mogo-module-service/src/main/java/com/mogo/module/service/network/RefreshBody.java +++ b/modules/mogo-module-service/src/main/java/com/mogo/module/service/network/RefreshBody.java @@ -11,17 +11,20 @@ import java.util.List; */ public class RefreshBody { - public List< String > dataType = new ArrayList<>(); - public int limit = 50;// 请求数量 - public int radius = 2_000; // 地理围栏半径(米) - public LatLon location; + public List dataType = new ArrayList<>(); // 要查询的类型 + public int limit = 50; // 请求数量 + public int radius = 2_000; // 地理围栏半径(米) + public LatLon location; // 坐标 + + public boolean onlyFocus; // 是否仅查询已关注的好友 + public boolean onlySameCity; // 是否仅查询注册城市相同的同城用户 public static class LatLon { private double lat; private double lon; - public LatLon( double lat, double lon ) { + public LatLon(double lat, double lon) { this.lat = lat; this.lon = lon; } diff --git a/modules/mogo-module-service/src/main/java/com/mogo/module/service/network/RefreshModel.java b/modules/mogo-module-service/src/main/java/com/mogo/module/service/network/RefreshModel.java index a30ca0e83b..5a366f4567 100644 --- a/modules/mogo-module-service/src/main/java/com/mogo/module/service/network/RefreshModel.java +++ b/modules/mogo-module-service/src/main/java/com/mogo/module/service/network/RefreshModel.java @@ -7,14 +7,13 @@ import com.mogo.commons.data.BaseData; import com.mogo.commons.debug.DebugConfig; import com.mogo.commons.network.ParamsProvider; import com.mogo.commons.network.SubscribeImpl; -import com.mogo.commons.network.Utils; import com.mogo.map.MogoLatLng; +import com.mogo.module.service.ServiceConst; import com.mogo.service.MogoServicePaths; import com.mogo.service.network.IMogoNetwork; import com.mogo.utils.network.RequestOptions; import com.mogo.utils.network.utils.GsonUtil; -import java.util.HashMap; import java.util.Map; import io.reactivex.android.schedulers.AndroidSchedulers; @@ -36,14 +35,14 @@ public class RefreshModel { private final Context mContext; private RefreshApiService mRefreshApiService; - public RefreshModel( Context context ) { + public RefreshModel(Context context) { this.mContext = context; - IMogoNetwork network = ( IMogoNetwork ) ARouter.getInstance().build( MogoServicePaths.PATH_SERVICES_NETWORK ).navigation( context ); - this.mRefreshApiService = network.create( RefreshApiService.class, getNetHost() ); + IMogoNetwork network = (IMogoNetwork) ARouter.getInstance().build(MogoServicePaths.PATH_SERVICES_NETWORK).navigation(context); + this.mRefreshApiService = network.create(RefreshApiService.class, getNetHost()); } private String getNetHost() { - switch ( DebugConfig.getNetMode() ) { + switch (DebugConfig.getNetMode()) { case DebugConfig.NET_MODE_DEV: return HOST_DEV; case DebugConfig.NET_MODE_QA: @@ -53,34 +52,82 @@ public class RefreshModel { } } - public void refreshData( MogoLatLng latLng, int radius, final RefreshCallback callback ) { - if ( mRefreshApiService != null ) { - final Map< String, Object > query = new ParamsProvider.Builder( mContext ).build(); + public void refreshData(MogoLatLng latLng, int radius, final RefreshCallback callback) { + if (mRefreshApiService != null) { + final Map query = new ParamsProvider.Builder(mContext).build(); final RefreshBody refreshBody = new RefreshBody(); refreshBody.limit = 5; - refreshBody.location = new RefreshBody.LatLon( latLng.lat, latLng.lng ); + refreshBody.location = new RefreshBody.LatLon(latLng.lat, latLng.lng); refreshBody.radius = radius; - query.put( "data", GsonUtil.jsonFromObject( refreshBody ) ); - mRefreshApiService.refreshData( query ) - .subscribeOn( Schedulers.io() ) - .observeOn( AndroidSchedulers.mainThread() ) - .subscribe( new SubscribeImpl< BaseData >( RequestOptions.create( mContext ) ) { + query.put("data", GsonUtil.jsonFromObject(refreshBody)); + mRefreshApiService.refreshData(query) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new SubscribeImpl(RequestOptions.create(mContext)) { @Override - public void onSuccess( BaseData o ) { - super.onSuccess( o ); - if ( callback != null ) { + public void onSuccess(BaseData o) { + super.onSuccess(o); + if (callback != null) { callback.onSuccess(); } } @Override - public void onError( String message, int code ) { - super.onError( message, code ); - if ( callback != null ) { + public void onError(String message, int code) { + super.onError(message, code); + if (callback != null) { callback.onFail(); } } - } ); + }); + } + } + + /** + * 查询在线车辆 + * + * @param latLng 经纬度 + * @param radius 半径 + * @param onlyFocus 是否仅查询已关注的好友 + * @param onlySameCity 是否仅查询注册城市相同的同城用户 + * @param callback + */ + public void queryOnLineCar(MogoLatLng latLng, + int radius, + boolean onlyFocus, + boolean onlySameCity, + final RefreshCallback callback) { + if (mRefreshApiService != null) { + final Map query = new ParamsProvider.Builder(mContext).build(); + final RefreshBody refreshBody = new RefreshBody(); + refreshBody.limit = 5; + refreshBody.location = new RefreshBody.LatLon(latLng.lat, latLng.lng); + refreshBody.radius = radius; + refreshBody.onlyFocus = onlyFocus; + refreshBody.onlySameCity = onlySameCity; + refreshBody.dataType.add(ServiceConst.CARD_TYPE_USER_DATA); + + query.put("data", GsonUtil.jsonFromObject(refreshBody)); + mRefreshApiService.refreshData(query) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new SubscribeImpl(RequestOptions.create(mContext)) { + @Override + public void onSuccess(BaseData o) { + super.onSuccess(o); + if (callback != null) { + callback.onSuccess(); + } + } + + @Override + public void onError(String message, int code) { + super.onError(message, code); + if (callback != null) { + callback.onFail(); + } + } + }); } } }