Commit df65cfe9 by 王涛55

feat:module_bus

parent a359cf8d
......@@ -22,8 +22,6 @@
<option value="$PROJECT_DIR$/function" />
<option value="$PROJECT_DIR$/function/lib_app_common" />
<option value="$PROJECT_DIR$/function/lib_common_ui" />
<option value="$PROJECT_DIR$/function/lib_data_drive" />
<option value="$PROJECT_DIR$/function/lib_router_module" />
<option value="$PROJECT_DIR$/function_base" />
<option value="$PROJECT_DIR$/function_base/lib_network" />
</set>
......
......@@ -6,10 +6,9 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import com.app.passport.R;
import com.message.bean.GeneralMessageBean;
import com.message.driver.MessageWrap;
import com.hikcreate.module_bus.bean.GeneralMessageBean;
import com.hikcreate.module_bus.driver.MessageWrap;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
......@@ -38,8 +37,7 @@ public class TestFragment extends Fragment {
@Subscribe(threadMode = ThreadMode.MAIN)
public void test(GeneralMessageBean bean) {
Toast.makeText(getActivity(), MessageWrap.getMessageWrapDefault().
getMessageInfo(bean, "tempValue"), Toast.LENGTH_LONG).show();
Toast.makeText(getActivity(), bean.getDataAction(), Toast.LENGTH_LONG).show();
}
@Override
......
......@@ -36,7 +36,6 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
api project(':function:lib_app_common')
api project(':function:lib_common_ui')
api project(':function:lib_data_drive')
api project(':function_base:lib_network')
api project(':business_base:app_module_manager')
}
......@@ -35,4 +35,6 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation deps.multidex
implementation deps.rxandroid2
implementation deps.eventbus
implementation deps.gson
}
package com.message.bean;
package com.hikcreate.module_bus.bean;
import java.util.HashMap;
/**
* 事件驱动消息流类
......@@ -10,9 +12,8 @@ package com.message.bean;
public class GeneralMessageBean {
private String dataAction;//消息来自于哪个事件
private String moduleName;//消息moduleName
private String dataClassName;//用于通过反射获取类的字符串
private String messageJsonData;//message的json数据
private String extraJsonData;//额外的消息的json数据
private HashMap<String,String> dataValue;
public String getDataAction() {
return dataAction;
......@@ -30,27 +31,11 @@ public class GeneralMessageBean {
this.moduleName = moduleName;
}
public String getDataClassName() {
return dataClassName;
}
public void setDataClassName(String dataClassName) {
this.dataClassName = dataClassName;
}
public String getMessageJsonData() {
return messageJsonData;
}
public void setMessageJsonData(String messageJsonData) {
this.messageJsonData = messageJsonData;
}
public String getExtraJsonData() {
return extraJsonData;
public HashMap<String, String> getDataValue() {
return dataValue;
}
public void setExtraJsonData(String extraJsonData) {
this.extraJsonData = extraJsonData;
public void setDataValue(HashMap<String, String> dataValue) {
this.dataValue = dataValue;
}
}
package com.message.driver;
package com.hikcreate.module_bus.driver;
import android.util.Log;
import com.message.bean.GeneralMessageBean;
import com.message.util.ObjectUtil;
import com.hikcreate.module_bus.bean.GeneralMessageBean;
import com.hikcreate.module_bus.util.ObjectUtil;
import org.greenrobot.eventbus.EventBus;
import info.hook.com.lib_data_drive.BuildConfig;
import java.util.Map;
import info.hook.com.lib_module_common.BuildConfig;
/**
* author : taowang
......@@ -34,7 +36,6 @@ public final class MessageWrap {
private MessageWrap() {
messageEventBus = new EventBus();
}
public void register(Object subscriber) {
......@@ -72,8 +73,11 @@ public final class MessageWrap {
//打印消息信息
Log.v(MESSAGE_TAG, "moduleName-----" + mGeneralMessageBean.getModuleName());
Log.v(MESSAGE_TAG, "dataAction-----" + mGeneralMessageBean.getDataAction());
Log.v(MESSAGE_TAG, "dataClassName-----" + mGeneralMessageBean.getDataClassName());
Log.v(MESSAGE_TAG, "messageJsonData-----" + mGeneralMessageBean.getMessageJsonData());
if(mGeneralMessageBean.getDataValue() != null){
for (Map.Entry<String, String> entry : mGeneralMessageBean.getDataValue().entrySet()) {
Log.v(MESSAGE_TAG, "dataAction-----" + "key= " + entry.getKey() + " and value= " + entry.getValue());
}
}
}
}
......
package com.message.util;
package com.hikcreate.module_bus.util;
import com.message.bean.GeneralMessageBean;
import com.google.gson.Gson;
import com.hikcreate.module_bus.bean.GeneralMessageBean;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
......@@ -105,21 +105,4 @@ public class ObjectUtil {
}
return null;
}
public static String readAttributeValueByMethod(GeneralMessageBean mGeneralMessageBean, String name) {
Object message = getObjectBean(mGeneralMessageBean.getDataClassName(), mGeneralMessageBean.getMessageJsonData());
return (String) invokeMethod(message, name);
}
public static String readAttributeValueByName(GeneralMessageBean mGeneralMessageBean, String name) {
try {
Class messageClass = Class.forName(mGeneralMessageBean.getDataClassName());
Gson gson = new Gson();
Object jsonObject = gson.fromJson(mGeneralMessageBean.getExtraJsonData(), messageClass);
return readAttributeValueByName(jsonObject, name);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
apply plugin: 'com.android.library'
android {
compileSdkVersion build_config.compile_sdk
defaultConfig {
minSdkVersion build_config.min_sdk
targetSdkVersion build_config.target_sdk
resourcePrefix build_modele_baidu_resourcePrefix
versionCode build_config.version_code
versionName build_config.version_name
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
encoding = 'utf-8'
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
dexOptions {
preDexLibraries = false
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation deps.eventbus
implementation deps.gson
}
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
package info.hook.com.lib_data_drive;
import android.content.Context;
import androidx.test.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
assertEquals("info.hook.com.lib_data_drive.test", appContext.getPackageName());
}
}
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="info.hook.com.lib_data_drive" />
<resources>
<string name="app_name">lib_data_drive</string>
</resources>
package info.hook.com.lib_data_drive;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() {
assertEquals(4, 2 + 2);
}
}
\ No newline at end of file
include ':app', ':function:lib_common_ui',
':function:lib_data_drive',
':function:lib_router_module',
':function_base:lib_network',
':function:lib_app_common',
'business:app_passport',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment