opt
This commit is contained in:
@@ -229,7 +229,9 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme
|
||||
}
|
||||
|
||||
private void init() {
|
||||
mServiceApis = ( IMogoServiceApis ) ARouter.getInstance().build( MogoServicePaths.PATH_SERVICE_APIS ).navigation();
|
||||
if ( mServiceApis == null ) {
|
||||
mServiceApis = ( IMogoServiceApis ) ARouter.getInstance().build( MogoServicePaths.PATH_SERVICE_APIS ).navigation();
|
||||
}
|
||||
mMogoStatusManager = mServiceApis.getStatusManagerApi();
|
||||
}
|
||||
|
||||
@@ -388,6 +390,14 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme
|
||||
mPresenter.handleSchemeIntent( intent );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMogoServiceApis getApis() {
|
||||
if ( mServiceApis == null ) {
|
||||
mServiceApis = ( IMogoServiceApis ) ARouter.getInstance().build( MogoServicePaths.PATH_SERVICE_APIS ).navigation();
|
||||
}
|
||||
return mServiceApis;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
||||
@@ -12,6 +12,7 @@ import androidx.lifecycle.LifecycleOwner;
|
||||
|
||||
import com.alibaba.android.arouter.launcher.ARouter;
|
||||
import com.mogo.commons.mvp.Presenter;
|
||||
import com.mogo.map.navi.IMogoNavi;
|
||||
import com.mogo.module.main.constants.MainConstants;
|
||||
import com.mogo.module.main.livedata.CardSwitchLiveData;
|
||||
import com.mogo.service.MogoServicePaths;
|
||||
@@ -140,14 +141,7 @@ public class MainPresenter extends Presenter< MainView > {
|
||||
}
|
||||
|
||||
public void handleSchemeIntent( Intent intent ) {
|
||||
if ( intent == null || intent.getData() == null ) {
|
||||
return;
|
||||
}
|
||||
Uri target = intent.getData();
|
||||
switch ( target.getPath() ) {
|
||||
case "/main/switch2":
|
||||
mView.switch2Card( target.getQueryParameter( "type" ), true );
|
||||
break;
|
||||
}
|
||||
SchemeIntent.getInstance().init( getContext(), mView.getApis() );
|
||||
SchemeIntent.getInstance().handle( intent );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.mogo.module.main;
|
||||
|
||||
import com.mogo.commons.mvp.IView;
|
||||
import com.mogo.service.IMogoServiceApis;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
@@ -36,4 +37,11 @@ public interface MainView extends IView {
|
||||
* 加载模块
|
||||
*/
|
||||
void loadModules();
|
||||
|
||||
/**
|
||||
* 接口水龙头
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
IMogoServiceApis getApis();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
package com.mogo.module.main;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
|
||||
import com.mogo.map.MogoLatLng;
|
||||
import com.mogo.module.common.ModuleNames;
|
||||
import com.mogo.module.main.livedata.CardInfo;
|
||||
import com.mogo.module.main.livedata.CardSwitchLiveData;
|
||||
import com.mogo.service.IMogoServiceApis;
|
||||
import com.mogo.utils.TipToast;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020-04-20
|
||||
* <p>
|
||||
* scheme 意图处理
|
||||
* <p>
|
||||
* 导航:adb shell am start -d "mogo://launcher/main/switch2?type=navi'&'lon=116.327007'&'lat=39.977639"
|
||||
*/
|
||||
public class SchemeIntent {
|
||||
|
||||
private static final String TAG = "SchemeIntent";
|
||||
|
||||
public static final String TYPE_NAVI = "navi";
|
||||
|
||||
private IMogoServiceApis mApis;
|
||||
private Context mContext;
|
||||
|
||||
private SchemeIntent() {
|
||||
// private constructor
|
||||
}
|
||||
|
||||
private static final class InstanceHolder {
|
||||
private static final SchemeIntent INSTANCE = new SchemeIntent();
|
||||
}
|
||||
|
||||
public static SchemeIntent getInstance() {
|
||||
return InstanceHolder.INSTANCE;
|
||||
}
|
||||
|
||||
public void init( Context context, IMogoServiceApis apis ) {
|
||||
mContext = context;
|
||||
mApis = apis;
|
||||
}
|
||||
|
||||
private Object readResolve() {
|
||||
// 阻止反序列化,必须实现 Serializable 接口
|
||||
return InstanceHolder.INSTANCE;
|
||||
}
|
||||
|
||||
public void handle( Intent intent ) {
|
||||
if ( intent == null || intent.getData() == null ) {
|
||||
return;
|
||||
}
|
||||
Uri target = intent.getData();
|
||||
String path = target.getPath();
|
||||
if ( path == null || path.isEmpty() ) {
|
||||
return;
|
||||
}
|
||||
switch ( path ) {
|
||||
case "/main/switch2":
|
||||
handleSwitch2Action( target );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void handleSwitch2Action( Uri target ) {
|
||||
String type = target.getQueryParameter( "type" );
|
||||
switch ( type ) {
|
||||
case ModuleNames.CARD_TYPE_BUSINESS_OPERATION:
|
||||
case ModuleNames.CARD_TYPE_CARS_CHATTING:
|
||||
case ModuleNames.CARD_TYPE_NOVELTY:
|
||||
case ModuleNames.CARD_TYPE_ROAD_CONDITION:
|
||||
case ModuleNames.CARD_TYPE_SHARE_MUSIC:
|
||||
case ModuleNames.CARD_TYPE_USER_DATA:
|
||||
handleSwitchCardIntent( type );
|
||||
break;
|
||||
case TYPE_NAVI:
|
||||
handleNaviIntent( target );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void handleSwitchCardIntent( String type ) {
|
||||
CardSwitchLiveData.getInstance().postValue( new CardInfo( type, true ) );
|
||||
}
|
||||
|
||||
private void handleNaviIntent( Uri naviUri ) {
|
||||
if ( mApis == null ) {
|
||||
return;
|
||||
}
|
||||
String lon = naviUri.getQueryParameter( "lon" );
|
||||
String lat = naviUri.getQueryParameter( "lat" );
|
||||
|
||||
// TODO: 2020-04-20 补充场景
|
||||
|
||||
try {
|
||||
double dlon = Double.valueOf( lon );
|
||||
double dlat = Double.valueOf( lat );
|
||||
if ( mApis.getMapServiceApi().getNavi( mContext ).isNaviing() ) {
|
||||
mApis.getMapServiceApi().getNavi( mContext ).naviTo( new MogoLatLng( dlat, dlon ) );
|
||||
} else {
|
||||
mApis.getAddressManagerApi().calculatePath( new MogoLatLng( dlat, dlon ) );
|
||||
}
|
||||
} catch ( Exception e ) {
|
||||
TipToast.shortTip( "目的地异常,不能导航" );
|
||||
Logger.e( TAG, e, "error." );
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user