增加了查询在线用户的接口调用

This commit is contained in:
董宏宇
2020-01-15 19:45:05 +08:00
parent 75f4d373a9
commit 87c60788aa
2 changed files with 77 additions and 27 deletions

View File

@@ -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<String> 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;
}

View File

@@ -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<String, Object> 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<BaseData>(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<String, Object> 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<BaseData>(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();
}
}
});
}
}
}