rm online car module

This commit is contained in:
wangcongtao
2020-06-08 09:45:33 +08:00
parent 62728c227e
commit d6a65d0ca8
22 changed files with 698 additions and 281 deletions

View File

@@ -23,13 +23,11 @@ import com.mogo.map.MogoLatLng;
import com.mogo.map.listener.IMogoMapListener;
import com.mogo.map.location.IMogoLocationListener;
import com.mogo.map.location.MogoLocation;
import com.mogo.map.model.MogoPoi;
import com.mogo.map.navi.IMogoAimlessModeListener;
import com.mogo.map.navi.IMogoCarLocationChangedListener2;
import com.mogo.map.navi.IMogoNavi;
import com.mogo.map.navi.IMogoNaviListener;
import com.mogo.map.navi.MogoCongestionInfo;
import com.mogo.map.navi.MogoNaviInfo;
import com.mogo.map.navi.MogoTraffic;
import com.mogo.map.uicontroller.EnumMapUI;
import com.mogo.map.uicontroller.IMogoMapUIController;
@@ -235,7 +233,6 @@ public class MogoServices implements IMogoMapListener,
mLoopRequest = false;
// 用户手动操作地图刷新成功后,设置状态为 true引发延时策略
mStatusManager.setUserInteractionStatus( ServiceConst.TYPE, true, true );
}
@Override
@@ -316,6 +313,11 @@ public class MogoServices implements IMogoMapListener,
mIntentManager.registerIntentListener( ServiceConst.COMMAND_OPERATION, this );
mIntentManager.registerIntentListener( MogoReceiver.ACTION_VOICE_READY, this );
mIntentManager.registerIntentListener( MogoReceiver.ACTION_MOCK, this );
mIntentManager.registerIntentListener( ServiceConst.COMMAND_ZHIDAO_NEARBY_CAR_ONLINE, this );
mIntentManager.registerIntentListener( ServiceConst.COMMAND_ZHIDAO_NEARBY_FRIEND_ONLINE, this );
mIntentManager.registerIntentListener( ServiceConst.COMMAND_ZHIDAO_NEARBY_FRIEND, this );
mIntentManager.registerIntentListener( ServiceConst.COMMAND_ZHIDAO_NEARBY_USER_ONLINE, this );
mIntentManager.registerIntentListener( ServiceConst.COMMAND_ZHIDAO_NEARBY_FRIEND_BYLOCATION, this );
mADASController = MarkerServiceHandler.getADASController();
mLauncher = MarkerServiceHandler.getLauncher();
@@ -756,94 +758,16 @@ public class MogoServices implements IMogoMapListener,
@Override
public void onIntentReceived( String command, Intent intent ) {
if ( MogoReceiver.ACTIION_ADAS.equals( command ) ) {
if ( intent == null ) {
return;
}
int status = intent.getIntExtra( MogoReceiver.PARAM_ADAS_STATUS, 0 );
mStatusManager.setADASUIShow( ServiceConst.TYPE, status == 1 );
} else if ( Intent.ACTION_POWER_CONNECTED.equals( command ) ) {
mStatusManager.setAccStatus( ServiceConst.TYPE, true );
Logger.d( TAG, "acc status: %s", true );
} else if ( Intent.ACTION_POWER_DISCONNECTED.equals( command ) ) {
mStatusManager.setAccStatus( ServiceConst.TYPE, false );
Logger.d( TAG, "acc status: %s", false );
} else if ( MogoReceiver.ACTION_NWD_ACC.equals( command ) ) {
int state = intent.getByteExtra( MogoReceiver.PARAM_ACC_STATUS, ( byte ) 0 );
Logger.d( TAG, "acc status: %s", state == 1 );
mStatusManager.setAccStatus( ServiceConst.TYPE, state == 1 );
} else if ( MogoReceiver.ACTION_VOICE_UI.equals( command ) ) {
String val = intent.getStringExtra( MogoReceiver.PARRAM_WAKE_STATUS );
if ( TextUtils.equals( val, MogoReceiver.VALUE_DISMISS ) ) {
mStatusManager.setVoiceUIShow( TAG, false );
} else if ( TextUtils.equals( val, MogoReceiver.VALUE_SHOW ) ) {
mStatusManager.setVoiceUIShow( TAG, true );
}
} else if ( ServiceConst.COMMAND_NEXT.equals( command ) ) {
if ( ServiceConst.COMMAND_NEXT.equals( command ) ) {
onActionDone( MogoAction.Next );
} else if ( ServiceConst.COMMAND_PREVIOUS.equals( command ) ) {
onActionDone( MogoAction.Prev );
} else if ( ServiceConst.COMMAND_SWITCH_CARD.equals( command ) ) {
IntentHandlerFactory.getInstance().handle( mContext, command, intent );
} else if ( MogoReceiver.ACTION_ADAS_STATUS.equals( command ) ) {
String msg = intent.getStringExtra( "adasMsg" );
if ( TextUtils.isEmpty( msg ) ) {
return;
}
CarStateInfo stateInfo = GsonUtil.objectFromJson( msg, CarStateInfo.class );
if ( stateInfo != null ) {
changeCarHeadstockDirection( stateInfo.getValues().getHeading() );
// changeMyLocation( stateInfo.getValues() );
}
} else if ( ServiceConst.COMMAND_OPERATION.equals( command ) ) {
IntentHandlerFactory.getInstance().handle( mContext, command, intent );
} else if ( MogoReceiver.ACTION_VOICE_READY.equals( command ) ) {
AIAssist.getInstance( mContext ).flush();
mStatusManager.setAIAssistReady( TAG, true );
} else if ( ServiceConst.COMMAND_MY_LOCATION.equals( command ) ) {
IntentHandlerFactory.getInstance().handle( mContext, command, intent );
} else if ( MogoReceiver.ACTION_MOCK.equals( command ) ) {
} else {
IntentHandlerFactory.getInstance().handle( mContext, command, intent );
}
}
private void changeCarHeadstockDirection( final double degree ) {
if ( mNavi.isNaviing() ) {
return;
}
if ( mStatusManager.isSearchUIShow() ) {
return;
}
if ( !mStatusManager.isMainPageOnResume() ) {
return;
}
if ( mStatusManager.isSeekHelping() ) {
return;
}
if ( mUiController.getCurrentUiMode() != EnumMapUI.NorthUP_2D ) {
return;
}
UiThreadHandler.post( () -> {
mUiController.showMyLocation( inflateCursorView( degree ) );
} );
}
private View inflateCursorView( double degree ) {
View view = View.inflate( mContext, R.layout.map_amap_cursor, null );
view.setRotation( ( float ) degree );
return view;
}
private void changeMyLocation( CarStateInfo.ValuesBean valuesBean ) {
if ( valuesBean == null ) {
return;
}
Location location = new Location( LocationManager.GPS_PROVIDER );
location.setAltitude( valuesBean.getAlt() );
location.setLatitude( valuesBean.getLat() );
location.setLongitude( valuesBean.getLon() );
}
/**
* 注册桌面免唤醒指令
*/

View File

@@ -159,4 +159,39 @@ public class ServiceConst {
public static final String[] CMD_BACK_WORDS = new String[]{"关闭", "返回"};
/**
* 查询附近的人
* "data"="{"op":"查询","location":"附近","obj":"人"}"
*/
public static final String COMMAND_ZHIDAO_NEARBY_CAR_ONLINE = "com.zhidao.nearby.car.online";
/**
* 查询附近的好友
* 搜索当前车机所在位置同城市本人有好友关系
* (如果一期做不了根据车机所在位置同城查询,则根据车机激活城市查询)
* "data"="{"op":"查询","status":"","location":"","obj":"好友"}"
*/
public static final String COMMAND_ZHIDAO_NEARBY_FRIEND_ONLINE = "com.zhidao.nearby.friend.online";
/**
* 查询在线的好友
* "data"="{"op":"查询","status":"在线","obj":"好友"}"
*/
public static final String COMMAND_ZHIDAO_NEARBY_FRIEND = "com.zhidao.nearby.friend";
/**
* 查询在线的人
* <p>
* "data"="{"op":"查询","status":"在线","obj":"车主"}"
*/
public static final String COMMAND_ZHIDAO_NEARBY_USER_ONLINE = "com.zhidao.nearby.user.online";
/**
* 查询指定位置的好友
* <p>
* "data"="{"op":"看看","obj":"好友","location":"中关村"}"
*/
public static final String COMMAND_ZHIDAO_NEARBY_FRIEND_BYLOCATION = "com.zhidao.nearby.friend.bylocation";
}

View File

@@ -0,0 +1,106 @@
package com.mogo.module.service.intent;
import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.location.LocationManager;
import android.text.TextUtils;
import android.view.View;
import com.mogo.map.uicontroller.EnumMapUI;
import com.mogo.module.service.MarkerServiceHandler;
import com.mogo.module.service.R;
import com.mogo.module.service.ServiceConst;
import com.mogo.module.service.carinfo.CarStateInfo;
import com.mogo.module.service.receiver.MogoReceiver;
import com.mogo.utils.UiThreadHandler;
import com.mogo.utils.network.utils.GsonUtil;
public
/**
* @author congtaowang
* @since 2020/6/5
* <p>
* 描述
*/
class ADASStatusIntentHandler implements IntentHandler {
private static volatile ADASStatusIntentHandler sInstance;
private ADASStatusIntentHandler() {
}
public static ADASStatusIntentHandler getInstance() {
if ( sInstance == null ) {
synchronized ( ADASStatusIntentHandler.class ) {
if ( sInstance == null ) {
sInstance = new ADASStatusIntentHandler();
}
}
}
return sInstance;
}
public synchronized void release() {
sInstance = null;
}
@Override
public void handle( Context context, Intent intent ) {
if ( MogoReceiver.ACTIION_ADAS.equals( intent.getAction() ) ) {
if ( intent == null ) {
return;
}
int status = intent.getIntExtra( MogoReceiver.PARAM_ADAS_STATUS, 0 );
MarkerServiceHandler.getMogoStatusManager().setADASUIShow( ServiceConst.TYPE, status == 1 );
} else {
String msg = intent.getStringExtra( "adasMsg" );
if ( TextUtils.isEmpty( msg ) ) {
return;
}
CarStateInfo stateInfo = GsonUtil.objectFromJson( msg, CarStateInfo.class );
if ( stateInfo != null ) {
changeCarHeadstockDirection( context, stateInfo.getValues().getHeading() );
// changeMyLocation( stateInfo.getValues() );
}
}
}
private void changeCarHeadstockDirection( final Context context, final double degree ) {
if ( MarkerServiceHandler.getNavi().isNaviing() ) {
return;
}
if ( MarkerServiceHandler.getMogoStatusManager().isSearchUIShow() ) {
return;
}
if ( !MarkerServiceHandler.getMogoStatusManager().isMainPageOnResume() ) {
return;
}
if ( MarkerServiceHandler.getMogoStatusManager().isSeekHelping() ) {
return;
}
if ( MarkerServiceHandler.getMapUIController().getCurrentUiMode() != EnumMapUI.NorthUP_2D ) {
return;
}
UiThreadHandler.post( () -> {
MarkerServiceHandler.getMapUIController().showMyLocation( inflateCursorView( context, degree ) );
} );
}
private View inflateCursorView( Context context, double degree ) {
View view = View.inflate( context, R.layout.map_amap_cursor, null );
view.setRotation( ( float ) degree );
return view;
}
private void changeMyLocation( CarStateInfo.ValuesBean valuesBean ) {
if ( valuesBean == null ) {
return;
}
Location location = new Location( LocationManager.GPS_PROVIDER );
location.setAltitude( valuesBean.getAlt() );
location.setLatitude( valuesBean.getLat() );
location.setLongitude( valuesBean.getLon() );
}
}

View File

@@ -0,0 +1,25 @@
package com.mogo.module.service.intent;
import android.content.Context;
import android.content.Intent;
import com.mogo.commons.voice.AIAssist;
import com.mogo.module.service.MarkerServiceHandler;
public
/**
* @author congtaowang
* @since 2020/6/5
* <p>
* 描述
*/
class AIAssistIntentHandler implements IntentHandler {
private static final String TAG = "AIAssistIntentHandler";
@Override
public void handle( Context context, Intent intent ) {
AIAssist.getInstance( context ).flush();
MarkerServiceHandler.getMogoStatusManager().setAIAssistReady( TAG, true );
}
}

View File

@@ -0,0 +1,56 @@
package com.mogo.module.service.intent;
import android.content.Context;
import android.content.Intent;
import com.mogo.module.service.MarkerServiceHandler;
import com.mogo.module.service.ServiceConst;
import com.mogo.module.service.receiver.MogoReceiver;
import com.mogo.utils.logger.Logger;
public
/**
* @author congtaowang
* @since 2020/6/5
*
* 描述
*/
class AccStatusIntentHandler implements IntentHandler {
private static final String TAG = "AccStatusIntentHandler";
private static volatile AccStatusIntentHandler sInstance;
private AccStatusIntentHandler(){}
public static AccStatusIntentHandler getInstance(){
if( sInstance == null ){
synchronized( AccStatusIntentHandler.class ) {
if( sInstance == null ){
sInstance = new AccStatusIntentHandler();
}
}
}
return sInstance;
}
public synchronized void release(){
sInstance = null;
}
@Override
public void handle( Context context, Intent intent ) {
String action = intent.getAction();
if ( Intent.ACTION_POWER_CONNECTED.equals( action ) ) {
MarkerServiceHandler.getMogoStatusManager().setAccStatus( ServiceConst.TYPE, true );
Logger.d( TAG, "acc status: %s", true );
} else if ( Intent.ACTION_POWER_DISCONNECTED.equals( action ) ) {
MarkerServiceHandler.getMogoStatusManager().setAccStatus( ServiceConst.TYPE, false );
Logger.d( TAG, "acc status: %s", false );
} else if ( MogoReceiver.ACTION_NWD_ACC.equals( action ) ) {
int state = intent.getByteExtra( MogoReceiver.PARAM_ACC_STATUS, ( byte ) 0 );
Logger.d( TAG, "acc status: %s", state == 1 );
MarkerServiceHandler.getMogoStatusManager().setAccStatus( ServiceConst.TYPE, state == 1 );
}
}
}

View File

@@ -23,6 +23,18 @@ public class IntentHandlerFactory {
mHandlers.put( ServiceConst.COMMAND_SWITCH_CARD, new SwitchCardIntentHandler() );
mHandlers.put( ServiceConst.COMMAND_OPERATION, new AppOperationIntentHandler() );
mHandlers.put( ServiceConst.COMMAND_MY_LOCATION, new MyLocationHandler() );
mHandlers.put( ServiceConst.COMMAND_ZHIDAO_NEARBY_CAR_ONLINE, OnlineCarSearchIntentHandler.getInstance() );
mHandlers.put( ServiceConst.COMMAND_ZHIDAO_NEARBY_FRIEND_ONLINE, OnlineCarSearchIntentHandler.getInstance() );
mHandlers.put( ServiceConst.COMMAND_ZHIDAO_NEARBY_FRIEND, OnlineCarSearchIntentHandler.getInstance() );
mHandlers.put( ServiceConst.COMMAND_ZHIDAO_NEARBY_USER_ONLINE, OnlineCarSearchIntentHandler.getInstance() );
mHandlers.put( ServiceConst.COMMAND_ZHIDAO_NEARBY_FRIEND_BYLOCATION, OnlineCarSearchIntentHandler.getInstance() );
mHandlers.put( MogoReceiver.ACTION_VOICE_UI, new VoiceUiIntentHandler() );
mHandlers.put( Intent.ACTION_POWER_CONNECTED, AccStatusIntentHandler.getInstance() );
mHandlers.put( Intent.ACTION_POWER_DISCONNECTED, AccStatusIntentHandler.getInstance() );
mHandlers.put( MogoReceiver.ACTION_NWD_ACC, AccStatusIntentHandler.getInstance() );
mHandlers.put( MogoReceiver.ACTION_ADAS_STATUS, ADASStatusIntentHandler.getInstance() );
mHandlers.put( MogoReceiver.ACTIION_ADAS, ADASStatusIntentHandler.getInstance() );
mHandlers.put( MogoReceiver.ACTION_VOICE_READY, new AIAssistIntentHandler() );
}
private static final class InstanceHolder {

View File

@@ -26,6 +26,7 @@ import com.mogo.module.service.MogoServiceProvider;
import com.mogo.module.service.R;
import com.mogo.service.entrance.ButtonIndex;
import com.mogo.utils.TipToast;
import com.mogo.utils.WorkThreadHandler;
import com.mogo.utils.logger.Logger;
import com.mogo.utils.network.utils.GsonUtil;
@@ -268,9 +269,16 @@ public class MockIntentHandler implements IntentHandler {
MogoMarkerOptions options = new MogoMarkerOptions();
options.icon( BitmapFactory.decodeResource( AbsMogoApplication.getApp().getResources(), R.drawable.icon_map_marker_car_gray ) )
.position( mogoLatLngs.get( 0 ) )
.owner( TAG )
.autoManager( false );
int duration = intent.getIntExtra( "duration", 30 );
MarkerServiceHandler.getApis().getRefreshStrategyControllerApi().restartAutoRefreshAtTime( duration );
IMogoMarker marker = MarkerServiceHandler.getMarkerManager().addMarker( TAG, options );
marker.startSmooth( mogoLatLngs, intent.getIntExtra( "duration", 30 ) );
MarkerServiceHandler.getMogoStatusManager().setUserInteractionStatus( TAG, true, false );
MarkerServiceHandler.getMapUIController().moveToCenter( mogoLatLngs.get( 0 ) );
WorkThreadHandler.getInstance().post( ()->{
marker.startSmooth( mogoLatLngs, duration );
} );
}
break;
}

View File

@@ -0,0 +1,167 @@
package com.mogo.module.service.intent;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import com.mogo.map.MogoLatLng;
import com.mogo.map.location.MogoLocation;
import com.mogo.map.search.geo.IMogoGeoSearch;
import com.mogo.map.search.geo.IMogoGeoSearchListener;
import com.mogo.map.search.geo.MogoGeocodeAddress;
import com.mogo.map.search.geo.MogoGeocodeResult;
import com.mogo.map.search.geo.query.MogoGeocodeQuery;
import com.mogo.module.service.MarkerServiceHandler;
import com.mogo.module.service.ServiceConst;
import com.mogo.module.service.marker.MapMarkerManager;
import com.mogo.module.service.receiver.MogoReceiver;
import com.mogo.utils.logger.Logger;
import org.json.JSONObject;
public
/**
* @author congtaowang
* @since 2020/6/5
* <p>
* 描述
*/
class OnlineCarSearchIntentHandler implements IntentHandler {
private static final String TAG = "OnlineCarSearchIntentHandler";
private static volatile OnlineCarSearchIntentHandler sInstance;
private OnlineCarSearchIntentHandler() {
}
public static OnlineCarSearchIntentHandler getInstance() {
if ( sInstance == null ) {
synchronized ( OnlineCarSearchIntentHandler.class ) {
if ( sInstance == null ) {
sInstance = new OnlineCarSearchIntentHandler();
}
}
}
return sInstance;
}
public synchronized void release() {
sInstance = null;
}
@Override
public void handle( Context context, Intent intent ) {
String command = intent.getStringExtra( MogoReceiver.PARAM_COMMAND );
if ( TextUtils.isEmpty( command ) ) {
return;
}
MogoLocation location = MarkerServiceHandler.getMogoLocationClient().getLastKnowLocation();
MogoLatLng target = null;
if ( location != null ) {
target = new MogoLatLng( location.getLatitude(), location.getLongitude() );
}
boolean isFocus = false;
boolean isSameCity = false;
int limit = 50;
int radius = 5_000;
switch ( command ) {
case ServiceConst.COMMAND_ZHIDAO_NEARBY_FRIEND:
case ServiceConst.COMMAND_ZHIDAO_NEARBY_USER_ONLINE:
isFocus = true;
isSameCity = true;
case ServiceConst.COMMAND_ZHIDAO_NEARBY_CAR_ONLINE:
case ServiceConst.COMMAND_ZHIDAO_NEARBY_FRIEND_ONLINE:
MarkerServiceHandler.getMogoStatusManager().setUserInteractionStatus( TAG, true, false );
MarkerServiceHandler.getMapUIController().moveToCenter( target );
MapMarkerManager.getInstance().getOnlineCarData(
target,
isFocus,
isSameCity,
limit,
radius );
break;
case ServiceConst.COMMAND_ZHIDAO_NEARBY_FRIEND_BYLOCATION:
handleAreaSearch( intent, context, target );
break;
}
}
private void handleAreaSearch( Intent intent, Context context, MogoLatLng target ) {
String data = intent.getStringExtra( "data" );
if ( TextUtils.isEmpty( data ) ) {
Logger.e( TAG, "语音没有携带数据!!!!!" );
return;
}
String keyword = null;
try {
JSONObject jsonObject = new JSONObject( data );
keyword = jsonObject.get( "location" ).toString();
Logger.d( TAG, "location 查询指定位置的好友 keyword = " + keyword );
} catch ( Exception e ) {
Logger.e( TAG, "语音携带数据异常!!!!!" );
return;
}
if ( TextUtils.isEmpty( keyword ) ) {
Logger.e( TAG, "语音携带数据为空!!!!!" );
return;
}
if ( TextUtils.equals( "附近", keyword ) ) {
MarkerServiceHandler.getMogoStatusManager().setUserInteractionStatus( TAG, true, false );
MarkerServiceHandler.getMapUIController().moveToCenter( target );
MapMarkerManager.getInstance().getOnlineCarData(
target,
false,
false,
50,
5_000 );
} else {
String cityCode = MarkerServiceHandler.getMogoLocationClient().getLastKnowLocation().getCityCode();
IMogoGeoSearch search = MarkerServiceHandler.getMapService().getGeoSearch( context );
search.setGeoSearchListener( new IMogoGeoSearchListener() {
@Override
public void onGeocodeSearched( MogoGeocodeResult geocodeResult ) {
MogoLatLng target = getGeoTargetAddress( geocodeResult );
if ( target == null ) {
Logger.e( TAG, "geo 检索位置错误" );
return;
}
MarkerServiceHandler.getMogoStatusManager().setUserInteractionStatus( TAG, true, false );
MarkerServiceHandler.getMapUIController().moveToCenter( geocodeResult.getAddresses().get( 0 ).getLatlng() );
MapMarkerManager.getInstance().getOnlineCarData(
target,
false,
false,
50,
5_000 );
}
} );
MogoGeocodeQuery mogoGeocodeQuery = new MogoGeocodeQuery();
mogoGeocodeQuery.setCity( cityCode );
mogoGeocodeQuery.setLocationName( keyword );
search.getFromLocationNameAsyn( mogoGeocodeQuery );
}
}
private MogoLatLng getGeoTargetAddress( MogoGeocodeResult geocodeResult ) {
if ( geocodeResult == null
|| geocodeResult.getAddresses() == null
|| geocodeResult.getAddresses().isEmpty() ) {
return null;
}
for ( MogoGeocodeAddress address : geocodeResult.getAddresses() ) {
if ( address == null ) {
continue;
}
if ( address.getLatlng() == null ) {
continue;
}
return address.getLatlng();
}
return null;
}
}

View File

@@ -0,0 +1,30 @@
package com.mogo.module.service.intent;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import com.mogo.module.service.MarkerServiceHandler;
import com.mogo.module.service.receiver.MogoReceiver;
public
/**
* @author congtaowang
* @since 2020/6/5
*
* 描述
*/
class VoiceUiIntentHandler implements IntentHandler {
private static final String TAG = "VoiceUiIntentHandler";
@Override
public void handle( Context context, Intent intent ) {
String val = intent.getStringExtra( MogoReceiver.PARRAM_WAKE_STATUS );
if ( TextUtils.equals( val, MogoReceiver.VALUE_DISMISS ) ) {
MarkerServiceHandler.getMogoStatusManager().setVoiceUIShow( TAG, false );
} else if ( TextUtils.equals( val, MogoReceiver.VALUE_SHOW ) ) {
MarkerServiceHandler.getMogoStatusManager().setVoiceUIShow( TAG, true );
}
}
}

View File

@@ -4,6 +4,7 @@ import android.content.Context;
import android.text.TextUtils;
import com.mogo.map.MogoLatLng;
import com.mogo.map.location.MogoLocation;
import com.mogo.map.marker.IMogoMarker;
import com.mogo.map.marker.IMogoMarkerClickListener;
import com.mogo.map.marker.IMogoMarkerManager;
@@ -621,28 +622,40 @@ public class MapMarkerManager implements IMogoMarkerClickListener,
}
public void getOnlineCarData( MogoLatLng latlng ) {
mCarLatLng = latlng;
getOnlineCarList();
getOnlineCarData( latlng, false, false, 50, 2_000 );
}
public void getOnlineCarData( MogoLatLng latLng,
boolean onlyFocus,
boolean onlySameCity,
int limit,
int radius ) {
UiThreadHandler.removeCallbacks( runnable );
UiThreadHandler.postDelayed( runnable, SMOOTH_DURATION * 1000 );
getOnlineCarList( latLng, onlyFocus, onlySameCity, limit, radius );
}
private Runnable runnable = new Runnable() {
@Override
public void run() {
getOnlineCarList();
getOnlineCarList( mCarLatLng, false, false, 2_000, 50 );
UiThreadHandler.postDelayed( this, SMOOTH_DURATION * 1000 );
}
};
private void getOnlineCarList() {
private void getOnlineCarList(
MogoLatLng latLng,
boolean onlyFocus,
boolean onlySameCity,
int limit,
int radius ) {
if ( ignoreOnlineCarRequest() ) {
removeCarMarkers();
return;
}
mRefreshModel.queryOnLineCarWithRoute( mCarLatLng, false, false, new RefreshCallback() {
mRefreshModel.queryOnLineCarWithRoute( latLng, onlyFocus, onlySameCity, limit, radius, new RefreshCallback() {
@Override
public void onSuccess( Object o ) {
MarkerResponse data = ( MarkerResponse ) o;

View File

@@ -38,14 +38,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() );
}
public static String getNetHost() {
switch (DebugConfig.getNetMode()) {
switch ( DebugConfig.getNetMode() ) {
case DebugConfig.NET_MODE_DEV:
return HOST_DEV;
case DebugConfig.NET_MODE_QA:
@@ -57,47 +57,47 @@ public class RefreshModel {
}
}
public void refreshData(MogoLatLng latLng, int radius, int limit, final RefreshCallback callback) {
if (mRefreshApiService != null) {
final Map<String, Object> query = new ParamsProvider.Builder(mContext).build();
public void refreshData( MogoLatLng latLng, int radius, int limit, final RefreshCallback callback ) {
if ( mRefreshApiService != null ) {
final Map< String, Object > query = new ParamsProvider.Builder( mContext ).build();
final RefreshBody refreshBody = new RefreshBody();
refreshBody.limit = limit;
refreshBody.location = new RefreshBody.LatLon(latLng.lat, latLng.lng);
refreshBody.location = new RefreshBody.LatLon( latLng.lat, latLng.lng );
refreshBody.radius = radius;
refreshBody.dataType.add(ServiceConst.CARD_TYPE_CARS_CHATTING);
refreshBody.dataType.add(ServiceConst.CARD_TYPE_ROAD_CONDITION);
refreshBody.dataType.add(ServiceConst.CARD_TYPE_SHARE_MUSIC);
refreshBody.dataType.add( ServiceConst.CARD_TYPE_CARS_CHATTING );
refreshBody.dataType.add( ServiceConst.CARD_TYPE_ROAD_CONDITION );
refreshBody.dataType.add( ServiceConst.CARD_TYPE_SHARE_MUSIC );
// refreshBody.dataType.add(ServiceConst.CARD_TYPE_USER_DATA);
refreshBody.dataType.add(ServiceConst.CARD_TYPE_NOVELTY);
query.put("data", GsonUtil.jsonFromObject(refreshBody));
mRefreshApiService.refreshData(query)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new SubscribeImpl<BaseData>(RequestOptions.create(mContext)) {
refreshBody.dataType.add( ServiceConst.CARD_TYPE_NOVELTY );
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(o);
public void onSuccess( BaseData o ) {
super.onSuccess( o );
if ( callback != null ) {
callback.onSuccess( o );
}
}
@Override
public void onError( Throwable e ) {
super.onError( e );
if (callback != null) {
if ( callback != null ) {
callback.onFail();
}
}
@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();
}
}
});
} );
}
}
@@ -110,42 +110,42 @@ public class RefreshModel {
* @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();
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 = 100;
refreshBody.location = new RefreshBody.LatLon(latLng.lat, latLng.lng);
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);
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)) {
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(o);
public void onSuccess( BaseData o ) {
super.onSuccess( o );
if ( callback != null ) {
callback.onSuccess( o );
}
}
@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();
}
}
});
} );
}
}
@@ -153,47 +153,52 @@ public class RefreshModel {
/**
* 查询车辆 及路线
*
* @param latLng 经纬度
* @param onlyFocus 是否仅查询已关注的好友
* @param onlySameCity 是否仅查询注册城市相同的同城用户
* @param latLng 经纬度
* @param onlyFocus 是否仅查询已关注的好友
* @param onlySameCity 是否仅查询注册城市相同的同城用户
* @param callback
*/
public void queryOnLineCarWithRoute(MogoLatLng latLng,
boolean onlyFocus,
boolean onlySameCity,
final RefreshCallback callback){
if (mRefreshApiService != null) {
final Map<String, Object> query = new ParamsProvider.Builder(mContext).build();
public void queryOnLineCarWithRoute( MogoLatLng latLng,
boolean onlyFocus,
boolean onlySameCity,
int radius,
int limit,
final RefreshCallback callback ) {
if ( mRefreshApiService != null ) {
final Map< String, Object > query = new ParamsProvider.Builder( mContext ).build();
final RefreshBody refreshBody = new RefreshBody();
refreshBody.sn = Utils.getSn();
refreshBody.location = new RefreshBody.LatLon(latLng.lat, latLng.lng);
if ( limit > 0 ) {
refreshBody.limit = limit;
}
refreshBody.location = new RefreshBody.LatLon( latLng.lat, latLng.lng );
refreshBody.onlyFocus = onlyFocus;
refreshBody.onlySameCity = onlySameCity;
refreshBody.dataType.add( ServiceConst.CARD_TYPE_USER_DATA );
query.put("data", GsonUtil.jsonFromObject(refreshBody));
mRefreshApiService.queryOnLineCarWithRoute(query)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new SubscribeImpl<MarkerResponse>(RequestOptions.create(mContext)){
query.put( "data", GsonUtil.jsonFromObject( refreshBody ) );
mRefreshApiService.queryOnLineCarWithRoute( query )
.subscribeOn( Schedulers.io() )
.observeOn( AndroidSchedulers.mainThread() )
.subscribe( new SubscribeImpl< MarkerResponse >( RequestOptions.create( mContext ) ) {
@Override
public void onSuccess(MarkerResponse o) {
super.onSuccess(o);
if (callback != null) {
callback.onSuccess(o);
public void onSuccess( MarkerResponse o ) {
super.onSuccess( o );
if ( callback != null ) {
callback.onSuccess( o );
}
}
@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();
}
}
});
} );
}
}
}