修复 模块加载 类型转换异常

Signed-off-by: 董宏宇 <martindhy@gmail.com>
This commit is contained in:
董宏宇
2021-10-15 18:57:07 +08:00
parent 0e119f8f55
commit da955835a2
35 changed files with 321 additions and 219 deletions

View File

@@ -22,6 +22,8 @@ public class MogoModulePaths {
private static final List<MogoModule> mModuleFunctions = new ArrayList<>();
private static final List<MogoModule> mModuleFunctionServers = new ArrayList<>();
/**
* 地图模块 fragment 路径
*/
@@ -38,17 +40,6 @@ public class MogoModulePaths {
*/
public static final String PATH_ENTRANCE = "/extension/entrance";
/**
* 添加卡片模块
*
* @param path
*/
@Deprecated
public static void addModule(String path) {
throw new IllegalArgumentException("this method can't be invoked.");
}
/**
* 添加卡片模块
*
@@ -73,6 +64,18 @@ public class MogoModulePaths {
mModuleFunctions.add(module);
}
/**
* 添加 功能服务, 不带UI Fragment的
*
* @param module 功能模块
*/
public static void addModuleFunctionServer(MogoModule module) {
if (module == null || TextUtils.isEmpty(module.getPath().replace(" ", ""))) {
throw new IllegalArgumentException("module path can't be empty or null or blank");
}
mModuleFunctionServers.add(module);
}
/**
* 添加基础模块
*
@@ -96,4 +99,8 @@ public class MogoModulePaths {
public static List<MogoModule> getModuleFunctions() {
return mModuleFunctions;
}
public static List<MogoModule> getModuleFunctionServers() {
return mModuleFunctionServers;
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 862 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 862 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 862 B

View File

@@ -2,12 +2,4 @@
<resources>
<dimen name="module_ext_top_view_width_in_vr_mode">1100px</dimen>
<dimen name="module_switch_map">279px</dimen>
<dimen name="module_switch_map_height">119px</dimen>
<dimen name="module_switch_margin_left">22px</dimen>
<dimen name="module_switch_text_size">36px</dimen>
<dimen name="module_switch_image">50px</dimen>
<dimen name="module_switch_image_circle">60px</dimen>
</resources>

View File

@@ -184,11 +184,4 @@
<dimen name="module_switch_map">190px</dimen>
<dimen name="module_switch_map_height">76px</dimen>
<dimen name="module_switch_margin_left">16px</dimen>
<dimen name="module_switch_text_size">24px</dimen>
<dimen name="module_switch_image">35px</dimen>
<dimen name="module_switch_image_circle">38px</dimen>
</resources>

View File

@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="module_ext_color_voice_text">#FFFFFF</color>
<color name="module_ext_weather_bkg_color">#BF30334C</color>
<color name="module_ext_weather_text_color">#fff</color>
<color name="module_ext_vr_mode_left_notice_content_text_color">#f1f1f1</color>

View File

@@ -244,12 +244,4 @@
<dimen name="module_video_window_width_content">400px</dimen>
<dimen name="module_video_window_height_content">300px</dimen>
<dimen name="module_switch_map">190px</dimen>
<dimen name="module_switch_map_height">76px</dimen>
<dimen name="module_switch_margin_left">16px</dimen>
<dimen name="module_switch_text_size">24px</dimen>
<dimen name="module_switch_image">35px</dimen>
<dimen name="module_switch_image_circle">38px</dimen>
</resources>

View File

@@ -69,7 +69,5 @@
<item>提前看看出行路况,试试唤醒小智说,“中关村路况怎么样”</item>
</string-array>
<string name="module_map_model_normal">近距视角</string>
<string name="module_map_model_faster">远距视角</string>
</resources>

View File

@@ -29,6 +29,11 @@ public interface MogoModulesHandler {
*/
void loadFunctionModules();
/**
* 架构升级v1.1加载功能模块
*/
void loadFunctionModulesServer();
/**
* 加载地图
*

View File

@@ -5,8 +5,10 @@ import android.content.Context;
import androidx.fragment.app.Fragment;
import com.alibaba.android.arouter.facade.template.IProvider;
import com.alibaba.android.arouter.launcher.ARouter;
import com.mogo.eagle.core.function.api.base.IMoGoFunctionProvider;
import com.mogo.eagle.core.function.api.base.IMoGoFunctionServerProvider;
import com.mogo.module.common.MogoApisHandler;
import com.mogo.module.common.MogoModule;
import com.mogo.module.common.MogoModulePaths;
@@ -43,6 +45,10 @@ public class MogoModulesManager implements MogoModulesHandler {
private Map< MogoModule, IMoGoFunctionProvider> mModuleFunctionProviders = new HashMap<>();
private Map< String, IMoGoFunctionProvider> mModuleNameFunctionProviders = new HashMap<>();
// 架构升级后的加载功能模块的方式
private Map< MogoModule, IMoGoFunctionServerProvider> mModuleFunctionServerProviders = new HashMap<>();
private Map< String, IMoGoFunctionServerProvider> mModuleNameFunctionServerProviders = new HashMap<>();
private static volatile MogoModulesManager sInstance;
private MogoModulesManager() {
@@ -121,6 +127,21 @@ public class MogoModulesManager implements MogoModulesHandler {
}
}
@Override
public void loadFunctionModulesServer() {
final List< MogoModule > modules = MogoModulePaths.getModuleFunctionServers();
if ( modules != null && !modules.isEmpty() ) {
for ( MogoModule module : modules ) {
Logger.d( TAG, "module.getPath():" + module.getPath() + " name: " + module.getName() );
IMoGoFunctionServerProvider provider = loadFunctionServer( module.getPath() );
if ( provider != null ) {
mModuleFunctionServerProviders.put( module, provider );
mModuleNameFunctionServerProviders.put( module.getName(), provider );
}
}
}
}
@Override
public void loadMapModule( int containerId ) {
Logger.d( TAG, "loadMapModule" );
@@ -168,7 +189,7 @@ public class MogoModulesManager implements MogoModulesHandler {
continue;
}
Logger.d( TAG, "加载基本模块:%s", baseModule.getPath() );
load( baseModule.getPath() );
loadBaseProvider( baseModule.getPath() );
}
}
@@ -181,6 +202,15 @@ public class MogoModulesManager implements MogoModulesHandler {
}
private IProvider loadBaseProvider(String path ) {
try {
return ( IProvider ) ARouter.getInstance().build( path ).navigation( getContext() );
} catch ( Exception e ) {
e.printStackTrace();
return null;
}
}
private IMogoModuleProvider load( String path ) {
try {
return ( IMogoModuleProvider ) ARouter.getInstance().build( path ).navigation( getContext() );
@@ -199,6 +229,15 @@ public class MogoModulesManager implements MogoModulesHandler {
}
}
private IMoGoFunctionServerProvider loadFunctionServer(String path ) {
try {
return ( IMoGoFunctionServerProvider ) ARouter.getInstance().build( path ).navigation( getContext() );
} catch ( Exception e ) {
e.printStackTrace();
return null;
}
}
private void addFragment( IMogoModuleProvider provider, int containerId ) {
if ( provider == null ) {
Logger.e( TAG, "add fragment fail cause provider == null, container is %s", ResourcesHelper.getResNameById( getApplicationContext(), containerId ) );
@@ -272,6 +311,23 @@ public class MogoModulesManager implements MogoModulesHandler {
if ( mModuleFunctionProviders != null ) {
mModuleFunctionProviders.clear();
}
if ( mModuleFunctionServerProviders != null ) {
Collection< IMoGoFunctionServerProvider > modules = mModuleFunctionServerProviders.values();
if ( modules != null ) {
for ( IMoGoFunctionServerProvider module : modules ) {
try {
Logger.d( TAG, "destroy module: " + module.getFunctionName() );
module.onDestroy();
} catch ( Exception e ) {
Logger.e( TAG, e, "onDestroy" );
}
}
}
mModuleNameFunctionProviders.clear();
}
if ( mModuleFunctionServerProviders != null ) {
mModuleFunctionServerProviders.clear();
}
mActivity = null;
}
}