Merge branch 'dev' into demo/shunyi_v2v_merge

# Conflicts:
#	app/src/main/java/com/mogo/launcher/MogoApplication.java
#	config.gradle
#	foudations/mogo-commons/src/main/java/com/mogo/commons/debug/DebugConfig.java
#	modules/mogo-module-extensions/src/main/java/com/mogo/module/extensions/entrance/EntranceFragment.java
#	modules/mogo-module-extensions/src/main/res/values-mdpi/dimens.xml
#	modules/mogo-module-extensions/src/main/res/values-xhdpi/dimens.xml
#	modules/mogo-module-extensions/src/main/res/values/dimens.xml
#	modules/mogo-module-media/src/main/java/com/mogo/module/media/window/MediaWindow2.java
#	modules/mogo-module-v2x/src/main/res/layout/item_v2x_fault_help.xml
#	modules/mogo-module-v2x/src/main/res/values-xhdpi/dimens.xml
#	modules/mogo-module-v2x/src/main/res/values/dimens.xml
#	services/mogo-service-api/src/main/java/com/mogo/service/IMogoServiceApis.java
#	services/mogo-service/src/main/java/com/mogo/service/impl/MogoServiceApis.java
#	upload.sh
This commit is contained in:
wangcongtao
2020-10-18 16:40:27 +08:00
479 changed files with 7101 additions and 8317 deletions

View File

@@ -9,15 +9,14 @@ import com.mogo.map.marker.IMogoMarkerManager;
import com.mogo.map.navi.IMogoNavi;
import com.mogo.map.uicontroller.IMogoMapUIController;
import com.mogo.module.carchattingprovider.ICarsChattingProvider;
import com.mogo.module.common.MogoApisHandler;
import com.mogo.module.common.entity.MarkerResponse;
import com.mogo.module.common.entity.MarkerShowEntity;
import com.mogo.module.gps.simulator.IMogoGpsSimulatorManager;
import com.mogo.module.service.marker.MapMarkerManager;
import com.mogo.service.IMogoServiceApis;
import com.mogo.service.MogoServicePaths;
import com.mogo.service.adas.IMogoADASController;
import com.mogo.service.analytics.IMogoAnalytics;
import com.mogo.service.cardmanager.IMogoCardManager;
import com.mogo.service.connection.IMogoSocketManager;
import com.mogo.service.datamanager.IMogoDataManager;
import com.mogo.service.fragmentmanager.IMogoFragmentManager;
@@ -51,7 +50,6 @@ public class MarkerServiceHandler {
private static IMogoStatusManager sMogoStatusManager;
private static IMogoImageloader sImageloader;
private static IMogoSocketManager sMogoSocketManager;
private static IMogoCardManager sMogoCardManager;
private static IMogoAnalytics sMogoAnalytics;
private static IMogoRegisterCenter sRegisterCenter;
private static IMogoActionManager sActionManager;
@@ -69,12 +67,11 @@ public class MarkerServiceHandler {
return;
}
sApis = ( IMogoServiceApis ) ARouter.getInstance().build( MogoServicePaths.PATH_SERVICE_APIS ).navigation( context );
sApis = MogoApisHandler.getInstance().getApis();
sMapService = sApis.getMapServiceApi();
sImageloader = sApis.getImageLoaderApi();
sMogoStatusManager = sApis.getStatusManagerApi();
sMogoSocketManager = sApis.getSocketManagerApi( context );
sMogoCardManager = sApis.getCardManagerApi();
sMogoAnalytics = sApis.getAnalyticsApi();
sMarkerManager = sMapService.getMarkerManager( context );
sNavi = sMapService.getNavi( context );
@@ -127,10 +124,6 @@ public class MarkerServiceHandler {
return sMogoStatusManager;
}
public static IMogoCardManager getMogoCardManager() {
return sMogoCardManager;
}
public static IMogoAnalytics getMogoAnalytics() {
return sMogoAnalytics;
}

View File

@@ -100,4 +100,9 @@ public class MogoServiceProvider implements IMogoModuleProvider {
MogoServices.getInstance().init( AbsMogoApplication.getApp() );
}, 5_000L );
}
@Override
public void onDestroy() {
MogoServices.getInstance().destroy();
}
}

View File

@@ -5,6 +5,8 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.location.Location;
import android.net.ConnectivityManager;
import android.net.wifi.WifiManager;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
@@ -15,8 +17,12 @@ import android.view.MotionEvent;
import androidx.annotation.NonNull;
import com.mogo.commons.debug.DebugConfig;
import com.mogo.commons.network.ParamsProvider;
import com.mogo.commons.network.SubscribeImpl;
import com.mogo.commons.storage.SpStorage;
import com.mogo.commons.voice.AIAssist;
import com.mogo.commons.voice.IMogoVoiceCmdCallBack;
import com.mogo.map.IDestroyable;
import com.mogo.map.MogoLatLng;
import com.mogo.map.listener.IMogoMapListener;
import com.mogo.map.location.IMogoLocationListener;
@@ -33,11 +39,15 @@ import com.mogo.module.common.MogoModulePaths;
import com.mogo.module.common.entity.MarkerResponse;
import com.mogo.module.common.map.MapCenterPointStrategy;
import com.mogo.module.common.map.Scene;
import com.mogo.module.service.autopilot.AutoPilotRemoteController;
import com.mogo.module.service.intent.IntentHandlerFactory;
import com.mogo.module.service.launchercard.LauncherCardRefresher;
import com.mogo.module.service.marker.MapMarkerManager;
import com.mogo.module.service.network.RefreshCallback;
import com.mogo.module.service.network.RefreshModel;
import com.mogo.module.service.network.bean.HomeCompanyDistanceForPushData;
import com.mogo.module.service.network.bean.HomeCompanyDistanceForPushResponse;
import com.mogo.module.service.onlinecar.panel.NavigationTargetInfo;
import com.mogo.module.service.receiver.MogoReceiver;
import com.mogo.module.service.refresh.AutoRefreshStrategy;
import com.mogo.module.service.refresh.CustomRefreshStrategy;
@@ -45,6 +55,7 @@ import com.mogo.module.service.refresh.RefreshObject;
import com.mogo.module.service.strategy.CarIconDisplayStrategy;
import com.mogo.service.adas.IMogoADASController;
import com.mogo.service.cardmanager.IMogoCardManager;
import com.mogo.service.connection.IMogoOnMessageListener;
import com.mogo.service.fragmentmanager.FragmentStackTransactionListener;
import com.mogo.service.fragmentmanager.IMogoFragmentManager;
import com.mogo.service.intent.IMogoIntentListener;
@@ -57,13 +68,20 @@ import com.mogo.service.module.MogoAction;
import com.mogo.service.statusmanager.IMogoStatusChangedListener;
import com.mogo.service.statusmanager.IMogoStatusManager;
import com.mogo.service.statusmanager.StatusDescriptor;
import com.mogo.utils.NetworkUtils;
import com.mogo.utils.UiThreadHandler;
import com.mogo.utils.WorkThreadHandler;
import com.mogo.utils.logger.Logger;
import com.mogo.utils.network.RequestOptions;
import com.mogo.utils.network.utils.GsonUtil;
import org.json.JSONObject;
import java.util.List;
import java.util.Map;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
/**
* @author congtaowang
@@ -83,7 +101,8 @@ public class MogoServices implements IMogoMapListener,
IMogoAimlessModeListener,
IMogoVoiceCmdCallBack,
FragmentStackTransactionListener,
IMogoCarLocationChangedListener2 {
IMogoCarLocationChangedListener2,
IDestroyable {
private boolean mInternalUnWakeupRegisterStatus = false;
@@ -114,8 +133,6 @@ public class MogoServices implements IMogoMapListener,
private IMogoMapUIController mUiController;
private IMogoCardManager mCardManager;
/**
* 是否已计算出地图显示状态
*/
@@ -188,6 +205,9 @@ public class MogoServices implements IMogoMapListener,
invokeAutoRefresh();
}
break;
case ServiceConst.MSG_SCHEDULE_CALCULATE_NOT_HOME_COMPANY_DISTANCE_FOR_PUSH:
handleCalculationNotHomeCompanyDistanceForPush( msg.arg1 );
break;
}
}
@@ -243,7 +263,7 @@ public class MogoServices implements IMogoMapListener,
/**
* 自动刷新回调
*/
private RefreshCallback mAutoRefreshCallback = new RefreshCallback<MarkerResponse>() {
private RefreshCallback mAutoRefreshCallback = new RefreshCallback< MarkerResponse >() {
@Override
public void onSuccess( MarkerResponse o ) {
MapMarkerManager.getInstance().onSyncMarkerResponse( o );
@@ -390,11 +410,12 @@ public class MogoServices implements IMogoMapListener,
mIntentManager.registerIntentListener( MogoReceiver.ACTION_AUTO_NAVI_RECEIVER, this );
mIntentManager.registerIntentListener( MogoReceiver.ACTION_AUTO_NAVI_SEND, this );
mIntentManager.registerIntentListener( MogoReceiver.ACTION_MOGO, this );
mIntentManager.registerIntentListener( ServiceConst.COMMAND_ONLINE_CAR_PANEL, this );
mIntentManager.registerIntentListener( ConnectivityManager.CONNECTIVITY_ACTION, this );
mADASController = MarkerServiceHandler.getADASController();
mLauncher = MarkerServiceHandler.getLauncher();
mFragmentManager = MarkerServiceHandler.getFragmentManager();
mCardManager = MarkerServiceHandler.getMogoCardManager();
mFragmentManager.addMainFragmentStackTransactionListener( this );
@@ -403,6 +424,8 @@ public class MogoServices implements IMogoMapListener,
if ( DebugConfig.isLaunchLocationService() ) {
initLocationServiceProcess( context );
}
AutoPilotRemoteController.getInstance().start();
}
private void initLocationServiceProcess( Context context ) {
@@ -484,7 +507,8 @@ public class MogoServices implements IMogoMapListener,
filter.addAction( MogoReceiver.ACTION_AUTO_NAVI_RECEIVER );
filter.addAction( MogoReceiver.ACTION_AUTO_NAVI_SEND );
filter.addAction( MogoReceiver.ACTION_MOGO );
filter.addAction(MogoReceiver.ACTION_TXZ_BLOCK_SEARCH);
filter.addAction( MogoReceiver.ACTION_TXZ_BLOCK_SEARCH );
filter.addAction( ConnectivityManager.CONNECTIVITY_ACTION );
try {
context.getApplicationContext().registerReceiver( mAIAssistReceiver, filter );
Logger.i( TAG, "register voice receiver." );
@@ -752,7 +776,7 @@ public class MogoServices implements IMogoMapListener,
return;
}
Logger.d( TAG, mAutoRefreshCallback == callback ? "触发自动刷新" : "触发手动刷新" );
int amount = 10;
int amount = 20;
Message msg = Message.obtain();
msg.what = ServiceConst.MSG_REQUEST_DATA;
@@ -847,6 +871,10 @@ public class MogoServices implements IMogoMapListener,
} else if ( ServiceConst.COMMAND_PREVIOUS.equals( command ) ) {
onActionDone( MogoAction.Prev );
} else {
if ( TextUtils.equals( command, ConnectivityManager.CONNECTIVITY_ACTION )
&& NetworkUtils.isConnected( mContext ) ) {
mIntentManager.unregisterIntentListener( ConnectivityManager.CONNECTIVITY_ACTION, this );
}
IntentHandlerFactory.getInstance().handle( mContext, command, intent );
}
}
@@ -925,4 +953,90 @@ public class MogoServices implements IMogoMapListener,
AIAssist.getInstance( mContext ).registerUnWakeupCommand( ServiceConst.CMD_BACK, ServiceConst.CMD_BACK_WORDS, this );
}
}
@Override
public void onStartNavi() {
if ( DebugConfig.isIsScheduleCalculateNotHomeCompanyDistanceForPush() ) {
Logger.d( TAG, "onStartNavi: scheduleCalculationNotHomeCompanyDistanceForPush" );
scheduleCalculationNotHomeCompanyDistanceForPush( 1, ServiceConst.INTERVAL_SCHEDULE_CALCULATE_NOT_HOME_COMPANY_DISTANCE_FOR_PUSH );
} else {
Logger.d( TAG, "onStartNavi: scheduleCalculationNotHomeCompanyDistanceForPush un support" );
}
}
@Override
public void onStopNavi() {
SpStorage.setNavigationTarget( "" );
Logger.d( TAG, "onStopNavi: remove MSG_SCHEDULE_CALCULATE_NOT_HOME_COMPANY_DISTANCE_FOR_PUSH msg" );
mHandler.removeMessages( ServiceConst.MSG_SCHEDULE_CALCULATE_NOT_HOME_COMPANY_DISTANCE_FOR_PUSH );
}
/**
* 延时一分钟发起计算导航目的地推送策略
*/
private void scheduleCalculationNotHomeCompanyDistanceForPush( int time, long delay ) {
Message msg = Message.obtain();
msg.what = ServiceConst.MSG_SCHEDULE_CALCULATE_NOT_HOME_COMPANY_DISTANCE_FOR_PUSH;
msg.arg1 = time;
mHandler.sendMessageDelayed( msg, delay );
}
/**
* 发起计算导航目的地推送策略
*
* @param time 第x次重试
*/
private void handleCalculationNotHomeCompanyDistanceForPush( final int time ) {
if ( time > 3 ) {
return;
}
String json = SpStorage.getNavigationTarget();
if ( !TextUtils.isEmpty( json ) ) {
try {
NavigationTargetInfo info = GsonUtil.objectFromJson( json, NavigationTargetInfo.class );
Logger.d( TAG, "info = %s", info );
HomeCompanyDistanceForPushData data = new HomeCompanyDistanceForPushData();
data.lat = Double.valueOf( info.getToPoiLatitude() );
data.lon = Double.valueOf( info.getToPoiLongitude() );
final Map< String, Object > query = new ParamsProvider.Builder( mContext ).build();
query.put( "data", GsonUtil.jsonFromObject( data ) );
mRefreshModel.getRefreshApiService().calculationNotHomeCompanyDistanceForPush( query )
.subscribeOn( Schedulers.io() )
.observeOn( AndroidSchedulers.mainThread() )
.subscribe( new SubscribeImpl< HomeCompanyDistanceForPushResponse >( RequestOptions.create( mContext ) ) {
@Override
public void onSuccess( HomeCompanyDistanceForPushResponse o ) {
super.onSuccess( o );
if ( o != null && o.result != null ) {
Logger.d( TAG, "calculationNotHomeCompanyDistanceForPush result %s", o.result.pushFlag );
}
}
@Override
public void onError( Throwable e ) {
super.onError( e );
Logger.d( TAG, "re scheduleCalculationNotHomeCompanyDistanceForPush after 30s" );
// 延时30s重试
scheduleCalculationNotHomeCompanyDistanceForPush( time + 1, 30_000L );
}
@Override
public void onError( String message, int code ) {
super.onError( message, code );
}
} );
} catch ( Exception e ) {
Logger.e( TAG, e, "handleCalculationNotHomeCompanyDistanceForPush" );
}
}
}
@Override
public void destroy() {
Logger.d( TAG, "MogoServices do nothings." );
}
}

View File

@@ -108,7 +108,6 @@ public class ServiceConst {
public static final int MSG_REQUEST_DATA = 0x201;
/**
*
* 锁车消息
*/
public static final int MSG_LOCK_CAR = 0x202;
@@ -159,7 +158,7 @@ public class ServiceConst {
};
public static final String CMD_BACK = "back";
public static final String[] CMD_BACK_WORDS = new String[]{"关闭", "返回"};
public static final String[] CMD_BACK_WORDS = new String[]{"关闭", "返回"};
/**
@@ -203,4 +202,20 @@ public class ServiceConst {
public static final int ONLINE_SEARCH_LIMIT = 20;
public static final int ONLINE_SEARCH_RADIUS = 2_000;
/**
* 查找目的地车友
*/
public static final String COMMAND_ONLINE_CAR_PANEL = "com.zhidao.search.riders";
/**
* 导航开始后延时1分钟开启推送策略
*/
public static final int MSG_SCHEDULE_CALCULATE_NOT_HOME_COMPANY_DISTANCE_FOR_PUSH = 0x301;
/**
* 延时1分钟开启推送策略
*/
public static final long INTERVAL_SCHEDULE_CALCULATE_NOT_HOME_COMPANY_DISTANCE_FOR_PUSH = 60 * 1_000L;
}

View File

@@ -0,0 +1,23 @@
package com.mogo.module.service.autopilot;
import java.util.List;
public
/**
* @author congtaowang
* @since 2020/10/16
*
* 自动驾驶参数
*/
class AutoPilotParameters {
public AutoPilotLonLat startLatLon;
public List< AutoPilotLonLat > wayLatLons;
public AutoPilotLonLat endLatLon;
public float speedLimit;
public static class AutoPilotLonLat {
public double lat;
public double lon;
}
}

View File

@@ -0,0 +1,81 @@
package com.mogo.module.service.autopilot;
import com.mogo.commons.AbsMogoApplication;
import com.mogo.module.common.MogoApisHandler;
import com.mogo.service.connection.IMogoOnMessageListener;
import com.mogo.service.connection.IMogoSocketManager;
import com.mogo.utils.logger.Logger;
import com.mogo.utils.network.utils.GsonUtil;
public
/**
* @author congtaowang
* @since 2020/10/16
*
* 远端控制自动驾驶
*/
class AutoPilotRemoteController {
private static final String TAG = "AutoPilotRemoteController";
private static volatile AutoPilotRemoteController sInstance;
private IMogoSocketManager mMogoSocketManager;
private IMogoOnMessageListener< AutoPilotParameters > mParametersListener = new IMogoOnMessageListener< AutoPilotParameters >() {
@Override
public Class< AutoPilotParameters > target() {
return AutoPilotParameters.class;
}
@Override
public void onMsgReceived( AutoPilotParameters obj ) {
if ( obj == null ) {
Logger.e( TAG, "远端控制参数为null", new NullPointerException() );
return;
}
String json = GsonUtil.jsonFromObject( obj );
Logger.d( TAG, json );
MogoApisHandler.getInstance().getApis().getAdasControllerApi().notifyAdas( json );
}
};
/**
* 远端控制自动驾驶的消息类型
*/
public static final int MSG_TYPE_REMOTE_CONTROL_AUTOPILOT = 401014;
private AutoPilotRemoteController() {
mMogoSocketManager = MogoApisHandler.getInstance().getApis().getSocketManagerApi( AbsMogoApplication.getApp() );
}
public static AutoPilotRemoteController getInstance() {
if ( sInstance == null ) {
synchronized ( AutoPilotRemoteController.class ) {
if ( sInstance == null ) {
sInstance = new AutoPilotRemoteController();
}
}
}
return sInstance;
}
public void start() {
mMogoSocketManager.registerOnMessageListener( MSG_TYPE_REMOTE_CONTROL_AUTOPILOT, mParametersListener );
}
public synchronized void release() {
sInstance = null;
if ( mMogoSocketManager != null ) {
mMogoSocketManager.unregisterOnMessageListener( MSG_TYPE_REMOTE_CONTROL_AUTOPILOT, mParametersListener );
}
mMogoSocketManager = null;
mParametersListener = null;
}
private Object readResolve() {
// 阻止反序列化,必须实现 Serializable 接口
return sInstance;
}
}

View File

@@ -2,6 +2,7 @@ package com.mogo.module.service.intent;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import com.mogo.module.service.ServiceConst;
import com.mogo.module.service.receiver.AccStatusReceiver;
@@ -21,7 +22,6 @@ public class IntentHandlerFactory {
private IntentHandlerFactory() {
// private constructor
mHandlers.put( MogoReceiver.ACTION_MOCK, new MockIntentHandler() );
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() );
@@ -38,6 +38,8 @@ public class IntentHandlerFactory {
mHandlers.put( MogoReceiver.ACTION_VOICE_READY, new AIAssistIntentHandler() );
mHandlers.put( ServiceConst.COMMAND_BACK, WholeVoiceCommandIntentHandler.getInstance() );
mHandlers.put( MogoReceiver.ACTION_MOGO, new MogoControllerIntentHandler() );
mHandlers.put( ServiceConst.COMMAND_ONLINE_CAR_PANEL, new OnlineCarPanelIntentHandler() );
mHandlers.put( ConnectivityManager.CONNECTIVITY_ACTION, new NetworkChangedIntentHandler() );
}
private static final class InstanceHolder {

View File

@@ -12,6 +12,7 @@ import android.widget.TextView;
import com.mogo.commons.AbsMogoApplication;
import com.mogo.commons.debug.DebugConfig;
import com.mogo.commons.voice.AIAssist;
import com.mogo.map.MogoLatLng;
import com.mogo.map.marker.IMogoMarker;
import com.mogo.map.marker.MogoMarkerOptions;
@@ -338,6 +339,19 @@ public class MockIntentHandler implements IntentHandler {
case 30:
MarkerServiceHandler.getMapService().getMapUIController().forceRender();
break;
case 31:
Intent intent3 = new Intent();
intent3.setAction( "AUTONAVI_STANDARD_BROADCAST_RECV" );
intent3.putExtra( "KEY_TYPE", 12404 );
intent3.putExtra( "EXTRA_REQUEST_AUTO_STATE", 0 );
context.sendBroadcast( intent3 );
break;
case 32:
MarkerServiceHandler.getMapService().getMapUIController().setTrafficEnabled( true );
break;
case 33:
AIAssist.getInstance( context ).speakTTSVoice( "庞帆说这个是一个 hard coding." );
break;
}
}

View File

@@ -0,0 +1,38 @@
package com.mogo.module.service.intent;
import android.content.Context;
import android.content.Intent;
import com.mogo.module.common.MogoApisHandler;
import com.mogo.utils.NetworkUtils;
import com.mogo.utils.logger.LogLevel;
import com.mogo.utils.logger.Logger;
import com.mogo.utils.network.NetConfig;
public
/**
* @author congtaowang
* @since 2020/8/17
*
* 描述
*/
class NetworkChangedIntentHandler implements IntentHandler {
private static final String TAG = "NetworkChangedIntentHandler";
@Override
public void handle( Context context, Intent intent ) {
if ( NetworkUtils.isConnected( context ) ) {
try {
Logger.d( TAG, "setTrafficEnabled" );
MogoApisHandler.getInstance()
.getApis()
.getMapServiceApi()
.getMapUIController()
.setTrafficEnabled( true );
} catch ( Exception e ) {
e.printStackTrace();
}
}
}
}

View File

@@ -0,0 +1,38 @@
package com.mogo.module.service.intent;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.text.TextUtils;
import com.mogo.commons.storage.SpStorage;
import com.mogo.commons.voice.AIAssist;
import com.mogo.module.service.MarkerServiceHandler;
public
/**
* @author congtaowang
* @since 2020/9/21
*
* 描述
*/
class OnlineCarPanelIntentHandler implements IntentHandler {
@Override
public void handle( Context context, Intent intent ) {
String json = SpStorage.getNavigationTarget();
if ( TextUtils.isEmpty( json ) ) {
AIAssist.getInstance( context ).speakTTSVoice( "没有导航目的地" );
return;
}
AIAssist.getInstance( context ).speakTTSVoice( "正在查询" );
if ( MarkerServiceHandler.getMogoStatusManager().isMainPageOnResume() ) {
MarkerServiceHandler.getApis().getOnlineCarPanelApi().showPanel();
} else {
Intent start = new Intent( Intent.ACTION_VIEW );
start.addFlags( Intent.FLAG_ACTIVITY_NEW_TASK );
start.setData( Uri.parse( "mogo://launcher/main/switch2?type=showOnlineCarPanel" ) );
context.startActivity( start );
}
}
}

View File

@@ -1,65 +0,0 @@
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.ServiceConst;
import com.mogo.utils.AppUtils;
import com.mogo.utils.UiThreadHandler;
import org.json.JSONException;
import org.json.JSONObject;
/**
* @author congtaowang
* @since 2020-04-17
* <p>
* 描述
*/
public class SwitchCardIntentHandler implements IntentHandler {
@Override
public void handle( Context context, Intent intent ) {
String data = intent.getStringExtra( "data" );
try {
JSONObject jsonObject = new JSONObject( data );
String card = jsonObject.getString( "card" );
if ( TextUtils.equals( "多媒体卡片", card )
|| TextUtils.equals( "媒体中心卡片", card )
|| TextUtils.equals( "音乐卡片", card ) ) {
switchCard2( context, ServiceConst.CARD_TYPE_SHARE_MUSIC );
} else if ( TextUtils.equals( "探路卡片", card ) ) {
switchCard2( context, ServiceConst.CARD_TYPE_ROAD_CONDITION );
} else if ( TextUtils.equals( "在线车辆卡片", card ) ) {
switchCard2( context, ServiceConst.CARD_TYPE_USER_DATA );
} else if ( TextUtils.equals( "新鲜事卡片", card ) ) {
switchCard2( context, ServiceConst.CARD_TYPE_NOVELTY );
}
} catch ( JSONException e ) {
e.printStackTrace();
}
}
/**
* 切换卡片
*/
public static void switchCard2( Context context, String card ) {
if ( AppUtils.isApplicationBroughtToBackground( context ) ) {
MarkerServiceHandler.getLauncher().backToLauncher( context );
UiThreadHandler.postDelayed( () -> {
if ( MarkerServiceHandler.getMogoStatusManager().isADASShow() ) {
MarkerServiceHandler.getADASController().closeADAS();
}
MarkerServiceHandler.getMogoCardManager().switch2( card, true );
}, 2000L );
} else {
MarkerServiceHandler.getFragmentManager().clearAll();
if ( MarkerServiceHandler.getMogoStatusManager().isADASShow() ) {
MarkerServiceHandler.getADASController().closeADAS();
}
MarkerServiceHandler.getMogoCardManager().switch2( card, true );
}
}
}

View File

@@ -76,6 +76,11 @@ class LauncherCardRefresher {
*/
private int mDefaultConfigCounter = 0;
/**
* 事件/车友播报次数
*/
private int mMsgExplorerWayOrOnlineCarDataCounter = 0;
/**
* 因为缓存ticket失效导致失败的情况需要重新请求ticket然后再次获取数据这里重试3次
*/
@@ -151,18 +156,18 @@ class LauncherCardRefresher {
private ZhidaoRefreshModel mZhidaoRefreshModel;
private LauncherCardRefreshStrategy mExplorerWayOrOnlineCarDataStrategy = new LauncherCardRefreshStrategy(
20 * ONE_MINUTE,null, MSG_EXPLORER_WAY_OR_ONLINE_CAR_DATA
40 * ONE_MINUTE, null, MSG_EXPLORER_WAY_OR_ONLINE_CAR_DATA
);
private LauncherCardRefreshStrategy mInduceStrategy = new LauncherCardRefreshStrategy(
3 * ONE_MINUTE,mExplorerWayOrOnlineCarDataStrategy, MSG_INDUCE
3 * ONE_MINUTE, mExplorerWayOrOnlineCarDataStrategy, MSG_INDUCE
);
private LauncherCardRefreshStrategy mLauncherCardConfigStrategy = new LauncherCardRefreshStrategy(
2 * ONE_MINUTE,mInduceStrategy, MSG_REFRESH_DEFAULT_CARD
2 * ONE_MINUTE, mInduceStrategy, MSG_REFRESH_DEFAULT_CARD
);
private LauncherCardRefreshStrategy mRefreshStrategy = mLauncherCardConfigStrategy;
public void start() {
if ( DebugConfig.isLauncher() || DebugConfig.getCarMachineType() == DebugConfig.CAR_MACHINE_TYPE_BYD ) {
if ( !DebugConfig.isIsSupportLauncherCardRefreshStrategy() ) {
return;
}
if ( mStart ) {
@@ -172,6 +177,7 @@ class LauncherCardRefresher {
mLaunchTTSText = mContext.getString( R.string.module_service_open_app_tip );
mDefaultConfigCounter = 0;
mRefreshTicketCounter = 0;
mMsgExplorerWayOrOnlineCarDataCounter = 0;
mRefreshStrategy = mLauncherCardConfigStrategy;
// 延时加载数据已保证accOn之后网络恢复正常
long delay = ONE_MINUTE;
@@ -238,12 +244,16 @@ class LauncherCardRefresher {
restart();
return;
}
mMsgExplorerWayOrOnlineCarDataCounter++;
if ( mMsgExplorerWayOrOnlineCarDataCounter > 2 ) {
return;
}
MogoLatLng latLng = new MogoLatLng( location.getLatitude(), location.getLongitude() );
handleRefreshExplorerWayOrOnlineCarData( latLng, mRefreshStrategy.getType() );
}
private void handleRefreshExplorerWayOrOnlineCarData( MogoLatLng latLng, LauncherCardRefreshType type ) {
mRefreshModel.refreshDataSync( latLng,
mRefreshModel.refreshLauncherCardDataSync( latLng,
mRefreshStrategy.getRadius(),
mRefreshStrategy.getLimit(),
new RefreshCallback< MarkerResponse >() {

View File

@@ -0,0 +1,111 @@
package com.mogo.module.service.marker;
import com.mogo.module.carchattingprovider.ICallProviderResponse;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public
/**
* @author congtaowang
* @since 2020/9/28
*
* 描述
*/
abstract class CallProviderResponseImpl implements ICallProviderResponse {
@Override
public void addFriend( boolean b ) {
}
@Override
public void callInvokeError( @NotNull String s ) {
}
@Override
public void callStatus( int i ) {
}
@Override
public void callWindowStatus( boolean b ) {
}
@Override
public void canCall( boolean b ) {
}
@Override
public void hideUserWindowError( @NotNull String s ) {
}
@Override
public void invisibleUser( boolean b ) {
}
@Override
public void isFriend( boolean b ) {
}
@Override
public void isOnLine( boolean b, @Nullable String s ) {
}
@Override
public void userInfoCallBack( @Nullable String s, @Nullable String s1 ) {
}
@Override
public void userWindowStatus( boolean b ) {
}
@Override
public void call( @NotNull String s ) {
}
@Override
public void cancelMatch( boolean b ) {
}
@Override
public void error( @NotNull String s ) {
}
@Override
public void hangUp( boolean b ) {
}
@Override
public void invokeCallData( @NotNull String s ) {
}
@Override
public void match( @NotNull String s ) {
}
@Override
public void matchInvokeResult( boolean b, @NotNull String s ) {
}
@Override
public void mute( boolean b ) {
}
}

View File

@@ -3,7 +3,6 @@ package com.mogo.module.service.marker;
import android.content.Context;
import android.graphics.Rect;
import android.text.TextUtils;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.LinearInterpolator;
import com.mogo.commons.AbsMogoApplication;
@@ -16,6 +15,7 @@ import com.mogo.map.marker.MogoMarkerOptions;
import com.mogo.map.marker.anim.OnMarkerAnimationListener;
import com.mogo.map.uicontroller.EnumMapUI;
import com.mogo.module.common.ModuleNames;
import com.mogo.module.common.api.CallChatApi;
import com.mogo.module.common.entity.MarkerCarPois;
import com.mogo.module.common.entity.MarkerCardResult;
import com.mogo.module.common.entity.MarkerExploreWay;
@@ -25,7 +25,6 @@ import com.mogo.module.common.entity.MarkerOnlineCar;
import com.mogo.module.common.entity.MarkerResponse;
import com.mogo.module.common.entity.MarkerShareMusic;
import com.mogo.module.common.entity.MarkerShowEntity;
import com.mogo.module.common.utils.CarSeries;
import com.mogo.module.service.MarkerServiceHandler;
import com.mogo.module.service.R;
import com.mogo.module.service.ServiceConst;
@@ -109,16 +108,27 @@ public class MapMarkerManager implements IMogoMarkerClickListener,
mContext = context.getApplicationContext();
mRefreshModel = new RefreshModel( mContext );
// 长连接 - 长链变短链
// MarkerServiceHandler.getMogoSocketManager().registerOnMessageListener( 401001, this );
MarkerServiceHandler.getActionManager().registerBizActionDoneListener( this );
MarkerServiceHandler.getApis().getRegisterCenterApi().registerADASControlStatusChangedListener( TAG, this );
}
// ACC ON 的时候重置为trueACC OFF 设置为 false
// 保留 - 外部模块调用
public void setCheckOn( boolean checkOnLineData ) {
Logger.e( TAG, "do not invoke anymore." );
CallChatApi.getInstance().getApiProvider().registerUserWindowStatusListener( TAG, mContext, new CallProviderResponseImpl() {
@Override
public void userWindowStatus( boolean show ) {
try {
if ( mLastCheckMarker == null ) {
return;
}
if ( TextUtils.equals( mLastCheckMarker.getOwner(), ModuleNames.CARD_TYPE_USER_DATA )
&& !show ) {
closeMarker( mLastCheckMarker );
}
} catch ( Exception e ) {
e.printStackTrace();
}
}
} );
}
/**
@@ -130,6 +140,7 @@ public class MapMarkerManager implements IMogoMarkerClickListener,
try {
boolean result = switchMarkerOpenStatus( marker );
if ( !result ) {
updateCarUserInfoWindow( marker );
return false;
}
@@ -186,11 +197,7 @@ public class MapMarkerManager implements IMogoMarkerClickListener,
mLastCheckMarker = mogoMarker;
// 在线车辆点击使用infoWindow
if ( TextUtils.equals( mogoMarker.getOwner(), ModuleNames.CARD_TYPE_USER_DATA ) ) {
if ( !mogoMarker.isDestroyed() ) {
mogoMarker.setInfoWindowAdapter( UserDataMarkerInfoWindowAdapter.getInstance( mContext ) );
mogoMarker.showInfoWindow();
Logger.d( TAG, "打开info window" );
}
updateCarUserInfoWindow( mogoMarker );
} else {
Object object = mogoMarker.getObject();
if ( object != null ) {
@@ -210,7 +217,22 @@ public class MapMarkerManager implements IMogoMarkerClickListener,
}
}
MarkerServiceHandler.getMogoStatusManager().setUserInteractionStatus( TAG, true, false );
MarkerServiceHandler.getMapUIController().moveToCenter( mogoMarker.getPosition(), CarSeries.getSeries() == CarSeries.CAR_SERIES_F80X );
MarkerServiceHandler.getMapUIController().moveToCenter( mogoMarker.getPosition(), DebugConfig.isRoadEventAnimated() );
}
private void updateCarUserInfoWindow( IMogoMarker marker ) {
if ( marker != null && !marker.isDestroyed() ) {
try {
if ( !TextUtils.equals( marker.getOwner(), ModuleNames.CARD_TYPE_USER_DATA ) ) {
return;
}
marker.setIcon( OnlineCarMarkerView.getInstance().getSelectedBitmap( getCarVehicleType( marker ) ) );
MarkerOnlineCar onlineCar = ( MarkerOnlineCar ) ( ( MarkerShowEntity ) marker.getObject() ).getBindObj();
CallChatApi.getInstance().showUserWindow( mContext, onlineCar );
} catch ( Exception e ) {
Logger.e( TAG, e, "openMarker" );
}
}
}
// 折叠气泡
@@ -220,8 +242,7 @@ public class MapMarkerManager implements IMogoMarkerClickListener,
}
// 在线车辆点击使用infoWindow
if ( TextUtils.equals( mogoMarker.getOwner(), ModuleNames.CARD_TYPE_USER_DATA ) ) {
mogoMarker.hideInfoWindow();
Logger.d( TAG, "关闭info window" );
mogoMarker.setIcon( OnlineCarMarkerView.getInstance().getBitmap( getCarVehicleType( mogoMarker ) ) );
} else {
Object object = mogoMarker.getObject();
if ( object != null ) {
@@ -241,6 +262,17 @@ public class MapMarkerManager implements IMogoMarkerClickListener,
}
}
private int getCarVehicleType( IMogoMarker marker ) {
try {
return ( ( MarkerOnlineCar )
( ( MarkerShowEntity ) marker.getObject() ).getBindObj() )
.getCarInfo()
.getVehicleType();
} catch ( Exception e ) {
return 0;
}
}
// 绘制Marker
public synchronized void drawMapMarker( MarkerResponse response ) {
@@ -809,7 +841,7 @@ public class MapMarkerManager implements IMogoMarkerClickListener,
}
Logger.d( TAG, "内部 - 请求开始" );
mRefreshModel.queryOnLineCarWithRoute( latLng, onlyFocus, onlySameCity, radius, limit, new RefreshCallback() {
mRefreshModel.queryOnLineCarWithRoute( latLng, onlyFocus, onlySameCity, radius, limit, false, new RefreshCallback() {
@Override
public void onSuccess( Object o ) {
MarkerResponse data = ( MarkerResponse ) o;
@@ -994,7 +1026,7 @@ public class MapMarkerManager implements IMogoMarkerClickListener,
return;
}
if ( mLastDataResult != null ) {
runOnTargetThread( ()->{
runOnTargetThread( () -> {
MarkerServiceHandler.getMarkerManager().removeMarkers( ModuleNames.CARD_TYPE_ROAD_CONDITION );
drawMarkerByCurrentType( mLastDataResult );
mLastCheckMarker = null;

View File

@@ -22,6 +22,7 @@ import java.util.Map;
public class OnlineCarMarkerView implements IMarkerView {
private static Map< Integer, SoftReference< Bitmap > > sRef = new HashMap<>();
private static Map< Integer, SoftReference< Bitmap > > sTypedRef = new HashMap<>();
private OnlineCarMarkerView() {
// private constructor
@@ -72,6 +73,20 @@ public class OnlineCarMarkerView implements IMarkerView {
return sRef.get( vehicleType ).get();
}
public Bitmap getSelectedBitmap( int vehicleType ) {
if ( sTypedRef.get( vehicleType ) == null || sTypedRef.get( vehicleType ).get() == null
|| sTypedRef.get( vehicleType ).get().isRecycled() ) {
switch ( vehicleType ) {
case 2:
sTypedRef.put( vehicleType, new SoftReference<>( BitmapFactory.decodeResource( AbsMogoApplication.getApp().getResources(), R.drawable.icon_map_marker_car_type2 ) ) );
break;
default:
sTypedRef.put( vehicleType, new SoftReference<>( BitmapFactory.decodeResource( AbsMogoApplication.getApp().getResources(), R.drawable.icon_map_marker_car_gray_selected ) ) );
}
}
return sTypedRef.get( vehicleType ).get();
}
@Override
public void setMarker( IMogoMarker marker ) {

View File

@@ -3,6 +3,7 @@ package com.mogo.module.service.network;
import com.mogo.commons.data.BaseData;
import com.mogo.module.common.entity.MarkerResponse;
import com.mogo.module.service.network.bean.DemoUserInfoEntity;
import com.mogo.module.service.network.bean.HomeCompanyDistanceForPushResponse;
import java.util.Map;
@@ -37,4 +38,8 @@ public interface RefreshApiService {
*/
@GET( "/yycp-launcherSnapshot/mock/getMockUserInfos" )
Observable< DemoUserInfoEntity > getMockUsers();
@FormUrlEncoded
@POST("/yycp-travel-condition/trajectoryPrediction/calculationNotHomeCompanyDistanceForPush")
Observable< HomeCompanyDistanceForPushResponse > calculationNotHomeCompanyDistanceForPush( @FieldMap Map< String, Object > parameters);
}

View File

@@ -20,6 +20,7 @@ public class RefreshBody {
public boolean onlyFocus; // 是否仅查询已关注的好友
public boolean onlySameCity; // 是否仅查询注册城市相同的同城用户
public boolean viewPush; // 是否走V2X通道 true-401011false -401001
public boolean onlyRealUser;
public static class LatLon {

View File

@@ -65,51 +65,6 @@ 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();
final RefreshBody refreshBody = new RefreshBody();
refreshBody.limit = limit;
refreshBody.location = new RefreshBody.LatLon( latLng.lat, latLng.lng );
refreshBody.radius = radius;
refreshBody.dataType.add( ServiceConst.CARD_TYPE_ROAD_CONDITION );
String data = GsonUtil.jsonFromObject( refreshBody );
query.put( "data", data );
Logger.d( TAG, data );
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 );
}
}
@Override
public void onError( Throwable e ) {
super.onError( e );
if ( callback != null ) {
callback.onFail();
}
}
@Override
public void onError( String message, int code ) {
super.onError( message, code );
if ( callback != null ) {
callback.onFail();
}
}
} );
}
}
public void refreshExplorerWayData( MogoLatLng latLng, int radius, int limit, final RefreshCallback callback ) {
if ( mRefreshApiService != null ) {
final Map< String, Object > query = new ParamsProvider.Builder( mContext ).build();
@@ -117,6 +72,7 @@ public class RefreshModel {
refreshBody.limit = limit;
refreshBody.location = new RefreshBody.LatLon( latLng.lat, latLng.lng );
refreshBody.radius = radius;
refreshBody.viewPush = true;
refreshBody.dataType.add( ServiceConst.CARD_TYPE_ROAD_CONDITION );
String data = GsonUtil.jsonFromObject( refreshBody );
@@ -155,7 +111,7 @@ public class RefreshModel {
}
}
public void refreshDataSync( MogoLatLng latLng, int radius, int limit, final RefreshCallback callback ) {
public void refreshLauncherCardDataSync( 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();
@@ -169,7 +125,6 @@ public class RefreshModel {
query.put( "data", data );
Logger.d( TAG, data );
mRefreshApiService.refreshDataSync( query )
.subscribeOn( Schedulers.io() )
.observeOn( AndroidSchedulers.mainThread() )
@@ -208,12 +163,14 @@ public class RefreshModel {
* @param onlyFocus 是否仅查询已关注的好友
* @param onlySameCity 是否仅查询注册城市相同的同城用户
* @param callback
* @param onlyRealUser 是否只查询真实用户
*/
public void queryOnLineCarWithRoute( MogoLatLng latLng,
boolean onlyFocus,
boolean onlySameCity,
int radius,
int limit,
boolean onlyRealUser,
final RefreshCallback callback ) {
if ( mRefreshApiService != null ) {
final Map< String, Object > query = new ParamsProvider.Builder( mContext ).build();
@@ -226,6 +183,7 @@ public class RefreshModel {
refreshBody.location = new RefreshBody.LatLon( latLng.lat, latLng.lng );
refreshBody.onlyFocus = onlyFocus;
refreshBody.onlySameCity = onlySameCity;
refreshBody.onlyRealUser = onlyRealUser;
refreshBody.dataType.add( ServiceConst.CARD_TYPE_USER_DATA );
query.put( "data", GsonUtil.jsonFromObject( refreshBody ) );
@@ -241,6 +199,14 @@ public class RefreshModel {
}
}
@Override
public void onError( Throwable e ) {
super.onError( e );
if ( callback != null ) {
callback.onFail();
}
}
@Override
public void onError( String message, int code ) {
super.onError( message, code );

View File

@@ -0,0 +1,14 @@
package com.mogo.module.service.network.bean;
public
/**
* @author congtaowang
* @since 2020/9/22
*
* 描述
*/
class HomeCompanyDistanceForPushData {
public double lon;
public double lat;
}

View File

@@ -0,0 +1,19 @@
package com.mogo.module.service.network.bean;
import com.mogo.commons.data.BaseData;
public
/**
* @author congtaowang
* @since 2020/9/22
*
* 描述
*/
class HomeCompanyDistanceForPushResponse extends BaseData {
public HomeCompanyDistanceForPushResult result;
public static class HomeCompanyDistanceForPushResult {
public boolean pushFlag;
}
}

View File

@@ -0,0 +1,15 @@
package com.mogo.module.service.onlinecar.panel;
import androidx.fragment.app.FragmentActivity;
/**
* @author congtaowang
* @since 2020/9/21
* <p>
* 描述
*/
class ContainerHandler {
public static int sContainerId = 0;
public static FragmentActivity sAttachContext;
}

View File

@@ -0,0 +1,27 @@
package com.mogo.module.service.onlinecar.panel;
import com.mogo.commons.mvp.IView;
import com.mogo.module.common.entity.MarkerOnlineCar;
import java.util.List;
/**
* @author congtaowang
* @since 2020/9/21
* <p>
* 描述
*/
interface IOnlineCarPanelView extends IView {
void showLoading(boolean visible);
void renderOnlineCarList( List< MarkerOnlineCar > onlineCars, double lon, double lat );
void renderEmptyUi( OnlineCarStrategy strategy );
void renderNoNavigationInfoUi();
void renderErrorUi();
void removeSelf();
}

View File

@@ -0,0 +1,85 @@
package com.mogo.module.service.onlinecar.panel;
public
/**
* @author congtaowang
* @since 2020/9/21
* <p>
* 描述
*/
class NavigationTargetInfo {
/**
* FromPoiName : 东城区小黄庄北街2号
* FromPoiAddr : 在中国银行(北京安贞桥支行)附近
* FromPoiLongitude : 116.41082763671875
* FromPoiLatitude : 39.96831130981445
* ToPoiName : 北京市北京市北小营镇宏大工业开发中心A座7号
* ToPoiLongitude : 116.74490356445312
* ToPoiLatitude : 40.19820785522461
*/
private String FromPoiName;
private String FromPoiAddr;
private String FromPoiLongitude;
private String FromPoiLatitude;
private String ToPoiName;
private String ToPoiLongitude;
private String ToPoiLatitude;
public String getFromPoiName() {
return FromPoiName;
}
public void setFromPoiName( String FromPoiName ) {
this.FromPoiName = FromPoiName;
}
public String getFromPoiAddr() {
return FromPoiAddr;
}
public void setFromPoiAddr( String FromPoiAddr ) {
this.FromPoiAddr = FromPoiAddr;
}
public String getFromPoiLongitude() {
return FromPoiLongitude;
}
public void setFromPoiLongitude( String FromPoiLongitude ) {
this.FromPoiLongitude = FromPoiLongitude;
}
public String getFromPoiLatitude() {
return FromPoiLatitude;
}
public void setFromPoiLatitude( String FromPoiLatitude ) {
this.FromPoiLatitude = FromPoiLatitude;
}
public String getToPoiName() {
return ToPoiName;
}
public void setToPoiName( String ToPoiName ) {
this.ToPoiName = ToPoiName;
}
public String getToPoiLongitude() {
return ToPoiLongitude;
}
public void setToPoiLongitude( String ToPoiLongitude ) {
this.ToPoiLongitude = ToPoiLongitude;
}
public String getToPoiLatitude() {
return ToPoiLatitude;
}
public void setToPoiLatitude( String ToPoiLatitude ) {
this.ToPoiLatitude = ToPoiLatitude;
}
}

View File

@@ -0,0 +1,71 @@
package com.mogo.module.service.onlinecar.panel;
import android.content.Context;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.mogo.service.MogoServicePaths;
import com.mogo.service.strategy.IMogoOnlineCarListPanelProvider;
import com.mogo.utils.logger.Logger;
public
/**
* @author congtaowang
* @since 2020/9/21
*
* 描述
*/
@Route( path = MogoServicePaths.PATH_ONLINE_CAR_PANEL )
class OnlineCarListPanelProvider implements IMogoOnlineCarListPanelProvider {
private static final String TAG = "OnlineCarListPanelProvider";
@Override
public void initContainer( int containerId, FragmentActivity activity ) {
ContainerHandler.sContainerId = containerId;
ContainerHandler.sAttachContext = activity;
}
@Override
public void showPanel() {
if ( ContainerHandler.sAttachContext == null ) {
return;
}
Fragment fragment = new OnlineCarPanelFragment();
Logger.d( TAG, "showPanel" );
ContainerHandler.sAttachContext
.getSupportFragmentManager()
.beginTransaction()
.replace( ContainerHandler.sContainerId, fragment, TAG )
.commitNowAllowingStateLoss();
}
@Override
public void hidePanel() {
if ( ContainerHandler.sAttachContext == null ) {
return;
}
Logger.d( TAG, "hidePanel" );
Fragment fragment = ContainerHandler.sAttachContext.getSupportFragmentManager().findFragmentByTag( TAG );
if ( fragment != null ) {
ContainerHandler.sAttachContext
.getSupportFragmentManager()
.beginTransaction()
.remove( fragment )
.commitNowAllowingStateLoss();
}
}
@Override
public void clear() {
ContainerHandler.sContainerId = 0;
ContainerHandler.sAttachContext = null;
}
@Override
public void init( Context context ) {
}
}

View File

@@ -0,0 +1,118 @@
package com.mogo.module.service.onlinecar.panel;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.request.RequestOptions;
import com.mogo.map.location.MogoLocation;
import com.mogo.module.common.MogoApisHandler;
import com.mogo.module.common.api.CallChatApi;
import com.mogo.module.common.entity.MarkerLocation;
import com.mogo.module.common.entity.MarkerOnlineCar;
import com.mogo.module.common.glide.SkinAbleBitmapTarget;
import com.mogo.module.service.MarkerServiceHandler;
import com.mogo.module.service.R;
import com.mogo.module.service.Utils;
import com.mogo.utils.ResourcesHelper;
import com.mogo.utils.WindowUtils;
import com.mogo.utils.glide.GlideApp;
import com.mogo.utils.logger.Logger;
import java.util.List;
/**
* @author congtaowang
* @since 2020/9/21
* <p>
* 描述
*/
class OnlineCarPanelAdapter extends RecyclerView.Adapter< OnlineCarPanelAdapter.VH > {
private static final String TAG = "OnlineCarPanelAdapter";
private List< MarkerOnlineCar > mDatums;
private double mToLon;
private double mToLat;
public OnlineCarPanelAdapter( List< MarkerOnlineCar > mDatums, double mToLon, double mToLat ) {
this.mDatums = mDatums;
this.mToLon = mToLon;
this.mToLat = mToLat;
}
public void setDatums( List< MarkerOnlineCar > mDatums ) {
this.mDatums = mDatums;
notifyDataSetChanged();
}
@NonNull
@Override
public OnlineCarPanelAdapter.VH onCreateViewHolder( @NonNull ViewGroup parent, int viewType ) {
return new VH( LayoutInflater.from( parent.getContext() ).inflate( R.layout.module_services_online_car_panel_item, null ) );
}
@Override
public void onBindViewHolder( @NonNull OnlineCarPanelAdapter.VH holder, int position ) {
holder.bind( mDatums.get( position ), mToLon, mToLat );
}
@Override
public int getItemCount() {
return mDatums == null ? 0 : mDatums.size();
}
public static class VH extends RecyclerView.ViewHolder {
private ImageView avatar;
private TextView nickname;
private TextView distance;
private TextView detail;
public VH( @NonNull View itemView ) {
super( itemView );
RecyclerView.LayoutParams params = new RecyclerView.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT );
params.bottomMargin = ResourcesHelper.getDimensionPixelSize( itemView.getContext(), R.dimen.module_services_panel_item_marginBottom );
itemView.setLayoutParams( params );
avatar = itemView.findViewById( R.id.module_services_id_panel_item_avatar );
nickname = itemView.findViewById( R.id.module_services_id_panel_item_nickname );
distance = itemView.findViewById( R.id.module_services_id_panel_item_distance );
detail = itemView.findViewById( R.id.module_services_id_panel_item_detail );
}
public void bind( MarkerOnlineCar car, double lon, double lat ) {
RequestOptions options = new RequestOptions().circleCrop().placeholder( R.drawable.module_common_default_user_head ).error( R.drawable.module_common_default_user_head );
GlideApp.with( itemView.getContext() ).asBitmap().apply( options ).load( car.getUserInfo().getUserHead() ).into( new SkinAbleBitmapTarget( avatar, options ) );
nickname.setText( car.getUserInfo().getUserName() );
String content = getDistanceStr( car.getLocation(), lon, lat );
distance.setText( content );
detail.setOnClickListener( view -> {
MogoApisHandler.getInstance().getApis().getAnalyticsApi().track( "Mogoer_List_click", null );
try {
CallChatApi.getInstance().showUserWindow( itemView.getContext(), car );
} catch ( Exception e ) {
Logger.e( TAG, e, "detail.OnClick" );
}
} );
}
private String getDistanceStr( MarkerLocation location, double lon, double lat ) {
if ( location == null ) {
return "未知";
}
float distance = Utils.calculateLineDistance( location.getLon(), location.getLat(), lon, lat );
if ( distance >= 1000 ) {
return String.format( "%.1fKM", distance / 1000 );
} else {
return String.format( "%.1fM", distance );
}
}
}
}

View File

@@ -0,0 +1,183 @@
package com.mogo.module.service.onlinecar.panel;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.mogo.commons.mvp.MvpFragment;
import com.mogo.commons.voice.AIAssist;
import com.mogo.module.common.MogoApisHandler;
import com.mogo.module.common.entity.MarkerOnlineCar;
import com.mogo.module.common.view.OnPreventFastClickListener;
import com.mogo.module.service.MarkerServiceHandler;
import com.mogo.module.service.R;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author congtaowang
* @since 2020/9/21
* <p>
* 描述
*/
public class OnlineCarPanelFragment extends MvpFragment< IOnlineCarPanelView, OnlineCarPanelPresenter > implements IOnlineCarPanelView {
private RecyclerView mList;
private View mErrorPanel;
private View mRefreshPanel;
private TextView mEmptyTip;
private View m20KMStrategy;
private View m40KMStrategy;
private ProgressBar mLoading;
private OnlineCarPanelAdapter mOnlineCarPanelAdapter;
@Override
protected int getLayoutId() {
return R.layout.module_services_fragment_online_car_panel;
}
@Override
protected void initViews() {
findViewById( R.id.module_services_id_close ).setOnClickListener( new OnPreventFastClickListener() {
@Override
public void onClickImpl( View v ) {
removeSelf();
}
} );
mList = findViewById( R.id.module_services_id_recycler_view );
mRefreshPanel = findViewById( R.id.module_services_id_load_strategy_container );
mErrorPanel = findViewById( R.id.module_services_id_error_container );
m20KMStrategy = findViewById( R.id.module_services_id_20Km_radius );
m40KMStrategy = findViewById( R.id.module_services_id_40Km_radius );
mEmptyTip = findViewById( R.id.module_services_empty_tip );
mLoading = findViewById( R.id.module_services_id_loading );
mList.setLayoutManager( new LinearLayoutManager( getContext(), LinearLayoutManager.VERTICAL, false ) );
m20KMStrategy.setOnClickListener( new OnPreventFastClickListener() {
@Override
public void onClickImpl( View v ) {
mPresenter.next20KMStrategy();
}
} );
m40KMStrategy.setOnClickListener( new OnPreventFastClickListener() {
@Override
public void onClickImpl( View v ) {
mPresenter.next40KMStrategy();
}
} );
mErrorPanel.setOnClickListener( new OnPreventFastClickListener() {
@Override
public void onClickImpl( View v ) {
mPresenter.loadOnlineCar();
}
} );
mRootView.setOnClickListener( view -> {
} );
}
public void refreshPanel() {
mPresenter.refreshPanel();
}
@Override
public void showLoading( boolean visible ) {
if ( visible ) {
mRefreshPanel.setVisibility( View.GONE );
mList.setVisibility( View.GONE );
mErrorPanel.setVisibility( View.GONE );
mLoading.setVisibility( View.VISIBLE );
} else {
mLoading.setVisibility( View.GONE );
}
}
@NonNull
@Override
protected OnlineCarPanelPresenter createPresenter() {
return new OnlineCarPanelPresenter( this );
}
@Override
public void renderOnlineCarList( List< MarkerOnlineCar > onlineCars, double lon, double lat ) {
mRefreshPanel.setVisibility( View.GONE );
mErrorPanel.setVisibility( View.GONE );
mList.setVisibility( View.VISIBLE );
mLoading.setVisibility( View.GONE );
if ( mOnlineCarPanelAdapter == null ) {
mOnlineCarPanelAdapter = new OnlineCarPanelAdapter( onlineCars, lon, lat );
mList.setAdapter( mOnlineCarPanelAdapter );
} else {
mOnlineCarPanelAdapter.setDatums( onlineCars );
}
AIAssist.getInstance( getContext() ).speakTTSVoice( String.format( "为您找到%s个车友", onlineCars.size() ) );
Map< String, Object > properties = new HashMap<>();
properties.put( "number", onlineCars.size() );
MogoApisHandler.getInstance().getApis().getAnalyticsApi().track( "Mogoer_List_number", properties );
}
@Override
public void renderEmptyUi( OnlineCarStrategy strategy ) {
mErrorPanel.setVisibility( View.GONE );
mList.setVisibility( View.GONE );
mRefreshPanel.setVisibility( View.VISIBLE );
mLoading.setVisibility( View.GONE );
AIAssist.getInstance( getContext() ).speakTTSVoice( "未找到车友" );
if ( strategy == null ) {
m20KMStrategy.setVisibility( View.GONE );
m40KMStrategy.setVisibility( View.GONE );
mEmptyTip.setText( getString( R.string.module_services_online_car_panel_empty_tmpl, OnlineCarStrategy.Strategy3.getRadiusKM() ) );
} else {
switch ( strategy ) {
case Strategy3:
m20KMStrategy.setVisibility( View.GONE );
m40KMStrategy.setVisibility( View.GONE );
case Strategy2:
m20KMStrategy.setVisibility( View.GONE );
case Default:
break;
}
mEmptyTip.setText( getString( R.string.module_services_online_car_panel_empty_tmpl, strategy.getRadiusKM() ) );
}
}
@Override
public void renderNoNavigationInfoUi() {
mList.setVisibility( View.GONE );
mRefreshPanel.setVisibility( View.GONE );
mErrorPanel.setVisibility( View.VISIBLE );
mLoading.setVisibility( View.GONE );
}
@Override
public void renderErrorUi() {
mList.setVisibility( View.GONE );
mRefreshPanel.setVisibility( View.GONE );
mLoading.setVisibility( View.GONE );
mErrorPanel.setVisibility( View.VISIBLE );
}
@Override
public void removeSelf() {
MarkerServiceHandler.getApis().getOnlineCarPanelApi().hidePanel();
}
@Override
public void onDestroyView() {
if ( mPresenter != null ) {
mPresenter.destroy();
}
super.onDestroyView();
}
}

View File

@@ -0,0 +1,122 @@
package com.mogo.module.service.onlinecar.panel;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.lifecycle.LifecycleOwner;
import com.mogo.commons.mvp.Presenter;
import com.mogo.commons.storage.SpStorage;
import com.mogo.map.IDestroyable;
import com.mogo.map.MogoLatLng;
import com.mogo.map.navi.IMogoNaviListener2;
import com.mogo.module.common.MogoApisHandler;
import com.mogo.module.common.entity.MarkerResponse;
import com.mogo.module.service.network.RefreshCallback;
import com.mogo.module.service.network.RefreshModel;
import com.mogo.utils.logger.Logger;
import com.mogo.utils.network.utils.GsonUtil;
/**
* @author congtaowang
* @since 2020/9/21
* <p>
* 描述
*/
class OnlineCarPanelPresenter extends Presenter< IOnlineCarPanelView > implements
RefreshCallback< MarkerResponse >,
IMogoNaviListener2,
IDestroyable {
private static final String TAG = "OnlineCarPanelPresenter";
public static final int LIMIT = 20;
private RefreshModel mRefreshModel;
private OnlineCarStrategy mStrategy;
private NavigationTargetInfo mNavigationTargetInfo;
private Double mToLat;
private Double mToLon;
public OnlineCarPanelPresenter( IOnlineCarPanelView view ) {
super( view );
mRefreshModel = new RefreshModel( getContext() );
MogoApisHandler.getInstance().getApis().getRegisterCenterApi().registerMogoNaviListener( TAG, this );
}
@Override
public void onStopNavi() {
mView.removeSelf();
}
@Override
public void onCreate( @NonNull LifecycleOwner owner ) {
super.onCreate( owner );
refreshPanel();
}
public void next20KMStrategy() {
mStrategy = OnlineCarStrategy.Strategy2;
loadOnlineCar();
}
public void next40KMStrategy() {
mStrategy = OnlineCarStrategy.Strategy3;
loadOnlineCar();
}
public void refreshPanel() {
mStrategy = OnlineCarStrategy.Default;
String json = SpStorage.getNavigationTarget();
if ( TextUtils.isEmpty( json ) ) {
mView.renderNoNavigationInfoUi();
return;
}
Logger.d( TAG, json );
mNavigationTargetInfo = GsonUtil.objectFromJson( json, NavigationTargetInfo.class );
loadOnlineCar();
}
public void loadOnlineCar() {
if ( mNavigationTargetInfo == null ) {
mView.renderNoNavigationInfoUi();
return;
}
mView.showLoading( true );
try {
mToLat = Double.valueOf( mNavigationTargetInfo.getToPoiLatitude() );
mToLon = Double.valueOf( mNavigationTargetInfo.getToPoiLongitude() );
mRefreshModel.queryOnLineCarWithRoute( new MogoLatLng( mToLat, mToLon ),
false,
false,
mStrategy.getRadius(),
LIMIT,
true,
this
);
} catch ( Exception e ) {
mView.renderNoNavigationInfoUi();
}
}
@Override
public void onSuccess( MarkerResponse o ) {
if ( o == null
|| o.getResult() == null
|| o.getResult().getOnlineCar() == null
|| o.getResult().getOnlineCar().isEmpty() ) {
mView.renderEmptyUi( mStrategy );
} else {
mView.renderOnlineCarList( o.getResult().getOnlineCar(), mToLon, mToLat );
}
}
@Override
public void onFail() {
mView.renderErrorUi();
}
@Override
public void destroy() {
MogoApisHandler.getInstance().getApis().getRegisterCenterApi().unregisterMogoNaviListener( TAG );
}
}

View File

@@ -0,0 +1,35 @@
package com.mogo.module.service.onlinecar.panel;
/**
* @author congtaowang
* @since 2020/9/21
* <p>
* 描述
*/
enum OnlineCarStrategy {
Strategy3( 40_000, null ),
Strategy2( 20_000, Strategy3 ),
Default( 10_000, Strategy2 ),
;
private int radius;
private OnlineCarStrategy next;
OnlineCarStrategy( int radius, OnlineCarStrategy next ) {
this.radius = radius;
this.next = next;
}
public int getRadius() {
return radius;
}
public int getRadiusKM() {
return radius / 1000;
}
public OnlineCarStrategy getNext() {
return next;
}
}