新建IMoGoFunctionProvider.java提供给功能模块进行初始化加载的一些定义
Signed-off-by: 董宏宇 <martindhy@gmail.com>
This commit is contained in:
@@ -4,7 +4,7 @@ import android.content.Context
|
||||
import android.view.View
|
||||
import com.mogo.module.hmi.notification.enums.SidePattern
|
||||
import com.mogo.module.hmi.notification.interfaces.OnFloatAnimator
|
||||
import com.mogo.service.warning.WarningStatusListener
|
||||
import com.mogo.eagle.core.function.api.hmi.warning.WarningStatusListener
|
||||
import com.mogo.utils.WindowUtils
|
||||
import com.mogo.utils.logger.Logger
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import com.mogo.module.hmi.notification.enums.ShowPattern
|
||||
import com.mogo.module.hmi.notification.enums.SidePattern
|
||||
import com.mogo.module.hmi.notification.interfaces.OnFloatAnimator
|
||||
import com.mogo.module.hmi.notification.interfaces.OnFloatCallbacks
|
||||
import com.mogo.service.warning.WarningStatusListener
|
||||
import com.mogo.eagle.core.function.api.hmi.warning.WarningStatusListener
|
||||
|
||||
/**
|
||||
* @author xiaoyuzhou
|
||||
|
||||
@@ -7,7 +7,7 @@ import com.alibaba.android.arouter.launcher.ARouter
|
||||
import com.mogo.module.hmi.WaringConst
|
||||
import com.mogo.service.IMogoServiceApis
|
||||
import com.mogo.service.MogoServicePaths
|
||||
import com.mogo.service.warning.IMoGoWaringProvider
|
||||
import com.mogo.eagle.core.function.api.hmi.warning.IMoGoWaringProvider
|
||||
import com.mogo.utils.logger.Logger
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,7 +7,7 @@ import com.alibaba.android.arouter.launcher.ARouter
|
||||
import com.mogo.module.hmi.WaringConst
|
||||
import com.mogo.service.IMogoServiceApis
|
||||
import com.mogo.service.MogoServicePaths
|
||||
import com.mogo.service.warning.IMoGoWaringProvider
|
||||
import com.mogo.eagle.core.function.api.hmi.warning.IMoGoWaringProvider
|
||||
import com.mogo.utils.logger.Logger
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,7 +8,7 @@ import com.mogo.module.common.enums.EventTypeEnum
|
||||
import com.mogo.module.hmi.WaringConst
|
||||
import com.mogo.service.IMogoServiceApis
|
||||
import com.mogo.service.MogoServicePaths
|
||||
import com.mogo.service.warning.IMoGoWaringProvider
|
||||
import com.mogo.eagle.core.function.api.hmi.warning.IMoGoWaringProvider
|
||||
import com.mogo.utils.logger.Logger
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.mogo.module.hmi.ui
|
||||
|
||||
import com.mogo.commons.mvp.IView
|
||||
import com.mogo.eagle.core.data.enums.WarningDirectionEnum
|
||||
import com.mogo.service.warning.WarningStatusListener
|
||||
import com.mogo.eagle.core.function.api.hmi.warning.WarningStatusListener
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,7 +15,7 @@ import com.mogo.module.hmi.notification.WarningFloat
|
||||
import com.mogo.module.hmi.notification.anim.DefaultAnimator
|
||||
import com.mogo.module.hmi.notification.enums.SidePattern
|
||||
import com.mogo.module.hmi.ui.widget.V2XNotificationView
|
||||
import com.mogo.service.warning.WarningStatusListener
|
||||
import com.mogo.eagle.core.function.api.hmi.warning.WarningStatusListener
|
||||
import com.mogo.utils.logger.Logger
|
||||
import kotlinx.android.synthetic.main.fragment_warning.*
|
||||
|
||||
|
||||
@@ -9,12 +9,11 @@ import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.alibaba.android.arouter.facade.annotation.Route;
|
||||
import com.mogo.eagle.core.data.enums.WarningDirectionEnum;
|
||||
import com.mogo.eagle.core.function.api.hmi.warning.IMoGoWaringProvider;
|
||||
import com.mogo.eagle.core.function.api.hmi.warning.WarningStatusListener;
|
||||
import com.mogo.module.hmi.WaringConst;
|
||||
import com.mogo.module.hmi.ui.MoGoWarningFragment;
|
||||
import com.mogo.service.MogoServicePaths;
|
||||
import com.mogo.service.module.ModuleType;
|
||||
import com.mogo.service.warning.IMoGoWaringProvider;
|
||||
import com.mogo.service.warning.WarningStatusListener;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
/**
|
||||
@@ -36,7 +35,7 @@ public class MoGoWarningProvider implements IMoGoWaringProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment createFragment(Context context, Bundle data) {
|
||||
public Fragment createCoverage(Context context, Bundle data) {
|
||||
Logger.d(TAG, "初始化蘑菇预警模块 Fragment……");
|
||||
mMoGoWarningFragment = new MoGoWarningFragment();
|
||||
return mMoGoWarningFragment;
|
||||
@@ -44,15 +43,10 @@ public class MoGoWarningProvider implements IMoGoWaringProvider {
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String getModuleName() {
|
||||
public String getFunctionName() {
|
||||
return WaringConst.MODULE_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType() {
|
||||
return ModuleType.TYPE_CARD_FRAGMENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showWarningTrafficLight(int checkLightId) {
|
||||
mMoGoWarningFragment.showWarningTrafficLight(checkLightId);
|
||||
@@ -97,7 +91,7 @@ public class MoGoWarningProvider implements IMoGoWaringProvider {
|
||||
public void showWarningV2X(int v2xType, @Nullable String alertContent,
|
||||
@Nullable String ttsContent, @Nullable String tag,
|
||||
@Nullable WarningStatusListener listener) {
|
||||
mMoGoWarningFragment.showWarningV2X(v2xType, alertContent, ttsContent, tag,listener);
|
||||
mMoGoWarningFragment.showWarningV2X(v2xType, alertContent, ttsContent, tag, listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -256,6 +256,7 @@ public class MainActivity extends MvpActivity<MainView, MainPresenter> implement
|
||||
// 加载地图,触发地图加载完毕回调,在初始化其他卡片模块,保证卡片模块可以正确获取地图相关服务。
|
||||
loadContainerModules();
|
||||
MogoModulesManager.getInstance().loadModules();
|
||||
MogoModulesManager.getInstance().loadFunctionModules();
|
||||
mPresenter.delayOperations();
|
||||
|
||||
// 启动一些基本的服务:定位等
|
||||
|
||||
@@ -24,6 +24,11 @@ public interface MogoModulesHandler {
|
||||
*/
|
||||
List<IMogoModuleProvider> loadCardsModule();
|
||||
|
||||
/**
|
||||
* 架构升级v1.1加载功能模块
|
||||
*/
|
||||
void loadFunctionModules();
|
||||
|
||||
/**
|
||||
* 加载地图
|
||||
*
|
||||
|
||||
@@ -6,6 +6,7 @@ import android.content.Context;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.alibaba.android.arouter.launcher.ARouter;
|
||||
import com.mogo.eagle.core.function.api.base.IMoGoFunctionProvider;
|
||||
import com.mogo.module.common.MogoApisHandler;
|
||||
import com.mogo.module.common.MogoModule;
|
||||
import com.mogo.module.common.MogoModulePaths;
|
||||
@@ -38,6 +39,10 @@ public class MogoModulesManager implements MogoModulesHandler {
|
||||
// 空间换效率
|
||||
private Map< String, IMogoModuleProvider > mModuleNameProviders = new HashMap<>();
|
||||
|
||||
// 架构升级后的加载功能模块的方式
|
||||
private Map< MogoModule, IMoGoFunctionProvider> mModuleFunctionProviders = new HashMap<>();
|
||||
private Map< String, IMoGoFunctionProvider> mModuleNameFunctionProviders = new HashMap<>();
|
||||
|
||||
private static volatile MogoModulesManager sInstance;
|
||||
|
||||
private MogoModulesManager() {
|
||||
@@ -101,6 +106,21 @@ public class MogoModulesManager implements MogoModulesHandler {
|
||||
return providers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadFunctionModules() {
|
||||
final List< MogoModule > modules = MogoModulePaths.getModules();
|
||||
if ( modules != null && !modules.isEmpty() ) {
|
||||
for ( MogoModule module : modules ) {
|
||||
Logger.d( TAG, "module.getPath():" + module.getPath() + " name: " + module.getName() );
|
||||
IMoGoFunctionProvider provider = loadFunction( module.getPath() );
|
||||
if ( provider != null ) {
|
||||
mModuleFunctionProviders.put( module, provider );
|
||||
mModuleNameFunctionProviders.put( module.getName(), provider );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadMapModule( int containerId ) {
|
||||
Logger.d( TAG, "loadMapModule" );
|
||||
@@ -154,7 +174,7 @@ public class MogoModulesManager implements MogoModulesHandler {
|
||||
|
||||
@Override
|
||||
public void loadWaringModule(int containerId) {
|
||||
IMogoModuleProvider provider = ( IMogoModuleProvider ) ARouter.getInstance()
|
||||
IMoGoFunctionProvider provider = ( IMoGoFunctionProvider ) ARouter.getInstance()
|
||||
.build( MogoServicePaths.PATH_V2X_WARNING )
|
||||
.navigation( getContext() );
|
||||
addFragment( provider, containerId );
|
||||
@@ -165,6 +185,16 @@ public class MogoModulesManager implements MogoModulesHandler {
|
||||
try {
|
||||
return ( IMogoModuleProvider ) ARouter.getInstance().build( path ).navigation( getContext() );
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private IMoGoFunctionProvider loadFunction( String path ) {
|
||||
try {
|
||||
return ( IMoGoFunctionProvider ) ARouter.getInstance().build( path ).navigation( getContext() );
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -188,6 +218,24 @@ public class MogoModulesManager implements MogoModulesHandler {
|
||||
.commitAllowingStateLoss();
|
||||
}
|
||||
|
||||
private void addFragment( IMoGoFunctionProvider provider, int containerId ) {
|
||||
if ( provider == null ) {
|
||||
Logger.e( TAG, "add fragment fail cause provider == null, container is %s", ResourcesHelper.getResNameById( getApplicationContext(), containerId ) );
|
||||
return;
|
||||
}
|
||||
Fragment fragment = mActivity.getSupportFragmentManager().findFragmentByTag( provider.getFunctionName() );
|
||||
if ( fragment == null ) {
|
||||
fragment = provider.createCoverage( getContext(), null );
|
||||
}
|
||||
if ( fragment == null ) {
|
||||
Logger.e( TAG, "add fragment fail cause fragment == null, container is %s", ResourcesHelper.getResNameById( getApplicationContext(), containerId ) );
|
||||
return;
|
||||
}
|
||||
mActivity.getSupportFragmentManager().beginTransaction()
|
||||
.replace( containerId, fragment, provider.getFunctionName() )
|
||||
.commitAllowingStateLoss();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
if ( mModuleNameProviders != null ) {
|
||||
@@ -207,6 +255,23 @@ public class MogoModulesManager implements MogoModulesHandler {
|
||||
if ( mModuleProviders != null ) {
|
||||
mModuleProviders.clear();
|
||||
}
|
||||
if ( mModuleFunctionProviders != null ) {
|
||||
Collection< IMoGoFunctionProvider > modules = mModuleFunctionProviders.values();
|
||||
if ( modules != null ) {
|
||||
for ( IMoGoFunctionProvider module : modules ) {
|
||||
try {
|
||||
Logger.d( TAG, "destroy module: " + module.getFunctionName() );
|
||||
module.onDestroy();
|
||||
} catch ( Exception e ) {
|
||||
Logger.e( TAG, e, "onDestroy" );
|
||||
}
|
||||
}
|
||||
}
|
||||
mModuleNameFunctionProviders.clear();
|
||||
}
|
||||
if ( mModuleFunctionProviders != null ) {
|
||||
mModuleFunctionProviders.clear();
|
||||
}
|
||||
mActivity = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,8 +11,8 @@ import com.mogo.module.obu.mogo.utils.TrafficDataConvertUtils
|
||||
import com.mogo.service.IMogoServiceApis
|
||||
import com.mogo.service.MogoServicePaths
|
||||
import com.mogo.service.map.IMogoMapService
|
||||
import com.mogo.service.warning.IMoGoWaringProvider
|
||||
import com.mogo.service.warning.WarningStatusListener
|
||||
import com.mogo.eagle.core.function.api.hmi.warning.IMoGoWaringProvider
|
||||
import com.mogo.eagle.core.function.api.hmi.warning.WarningStatusListener
|
||||
import com.mogo.utils.logger.Logger
|
||||
import com.mogo.utils.storage.SharedPrefsMgr
|
||||
import com.zhidao.support.obu.MogoObuManager
|
||||
|
||||
Reference in New Issue
Block a user