将调用HMI调用层抽离

Signed-off-by: 董宏宇 <martindhy@gmail.com>
This commit is contained in:
董宏宇
2021-09-17 16:40:06 +08:00
parent 67dfd2621e
commit b8b5cf29a7
8 changed files with 86 additions and 1 deletions

View File

@@ -0,0 +1,27 @@
package com.mogo.eagle.core.function.call;
import com.alibaba.android.arouter.facade.template.IProvider;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* @author xiaoyuzhou
* @date 2021/9/17 4:10 下午
*/
public class CallerBusManager {
private static final String TAG = "CallerBusManager";
private static final Map<Class, Object> sSingletons = new ConcurrentHashMap<>();
public static <T> T get(Class<T> clazz) {
return (T) sSingletons.get(clazz);
}
public static <T extends IProvider> void registerApi(Class<? extends IProvider> api, T impl) throws Exception {
if (api == null || impl == null) {
return;
}
sSingletons.put(api, impl);
}
}

View File

@@ -0,0 +1,36 @@
package com.mogo.eagle.core.function.call.base;
import com.alibaba.android.arouter.facade.template.IProvider;
import com.alibaba.android.arouter.launcher.ARouter;
import com.mogo.eagle.core.function.call.CallerBusManager;
import com.mogo.eagle.core.utilcode.util.LogUtils;
/**
* @author xiaoyuzhou
* @date 2021/9/17 4:02 下午
*/
public class CallerBase {
private static final String TAG = "CallerBase";
public static <T extends IProvider> T getApiInstance(Class<T> clazz, String path) {
T inst = CallerBusManager.get(clazz);
if (inst == null) {
synchronized (CallerBase.class) {
inst = CallerBusManager.get(clazz);
if (inst != null) {
return inst;
}
T newInst = (T) ARouter.getInstance().build(path).navigation();
try {
CallerBusManager.registerApi(clazz, newInst);
LogUtils.dTag(TAG, "keep IProvider instance to SingletonHolder: path = %s", path);
} catch (Exception e) {
e.printStackTrace();
}
return newInst;
}
}
return inst;
}
}

View File

@@ -0,0 +1,16 @@
package com.mogo.eagle.core.function.call.hmi;
import com.mogo.eagle.core.function.api.hmi.warning.IMoGoWaringProvider;
import com.mogo.eagle.core.function.call.base.CallerBase;
import com.mogo.service.MogoServicePaths;
/**
* @author xiaoyuzhou
* @date 2021/9/17 3:59 下午
*/
public class CallerHmiManager extends CallerBase {
public static IMoGoWaringProvider getWaringProviderApi() {
return getApiInstance(IMoGoWaringProvider.class, MogoServicePaths.PATH_V2X_WARNING);
}
}