Skip to content

Commit a1aedd1

Browse files
authored
Merge pull request #42 from wyjsonGo/develop
publish v2.4.8 1.修复存在多个相同页面事件解绑不及时bug 2.修改动态注册模块Application方法
2 parents 93c4b53 + 751e147 commit a1aedd1

File tree

6 files changed

+31
-23
lines changed

6 files changed

+31
-23
lines changed

GoRouter-Api/src/main/java/com/wyjson/router/GoRouter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public static void callAMOnTrimMemory(int level) {
157157
*
158158
* @param am
159159
*/
160-
public static void registerAM(Class<? extends IApplicationModule> am) {
160+
public void registerAM(Class<? extends IApplicationModule> am) {
161161
ApplicationModuleCenter.register(am);
162162
}
163163

GoRouter-Api/src/main/java/com/wyjson/router/core/EventCenter.java

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import com.wyjson.router.exception.RouterException;
2020
import com.wyjson.router.utils.TextUtils;
2121

22+
import java.util.Map;
23+
2224
public class EventCenter {
2325

2426
public static <T> void registerEvent(LifecycleOwner owner, Class<T> type, boolean isForever, @NonNull Observer<T> observer) {
@@ -39,7 +41,7 @@ public static <T> void registerEvent(LifecycleOwner owner, Class<T> type, boolea
3941
return;
4042
}
4143

42-
String key = path + "$" + type.getCanonicalName();
44+
String key = path + "$" + type.getCanonicalName() + "$" + owner;
4345
MutableLiveData<T> liveData;
4446
if (Warehouse.events.containsKey(key)) {
4547
liveData = Warehouse.events.get(key);
@@ -70,7 +72,7 @@ public static <T> void unRegisterEvent(LifecycleOwner owner, Class<T> type, Obse
7072
return;
7173
}
7274

73-
String key = path + "$" + type.getCanonicalName();
75+
String key = path + "$" + type.getCanonicalName() + "$" + owner;
7476
if (Warehouse.events.containsKey(key)) {
7577
MutableLiveData<T> liveData = Warehouse.events.get(key);
7678
if (liveData != null) {
@@ -133,18 +135,24 @@ public static <T> void postEvent(String path, T value) {
133135
throw new RouterException("value cannot be empty!");
134136
}
135137
String key = path + "$" + value.getClass().getCanonicalName();
136-
if (Warehouse.events.containsKey(key)) {
137-
MutableLiveData<T> liveData = Warehouse.events.get(key);
138-
if (liveData != null) {
139-
if (Looper.myLooper() == Looper.getMainLooper()) {
140-
liveData.setValue(value);
138+
boolean isFound = false;
139+
for (Map.Entry<String, MutableLiveData> entry : Warehouse.events.entrySet()) {
140+
if (entry.getKey().startsWith(key)) {
141+
isFound = true;
142+
MutableLiveData<T> liveData = entry.getValue();
143+
if (liveData != null) {
144+
GoRouter.logger.info(null, "[postEvent] send path[" + entry.getKey() + "] value[" + value + "]");
145+
if (Looper.myLooper() == Looper.getMainLooper()) {
146+
liveData.setValue(value);
147+
} else {
148+
liveData.postValue(value);
149+
}
141150
} else {
142-
liveData.postValue(value);
151+
GoRouter.logger.error(null, "[postEvent] LiveData is empty??");
143152
}
144-
} else {
145-
GoRouter.logger.error(null, "[postEvent] LiveData is empty??");
146153
}
147-
} else {
154+
}
155+
if (!isFound) {
148156
GoRouter.logger.warning(null, "[postEvent] No observer was found for this event");
149157
}
150158
}

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ dependencyResolutionManagement {
6969
}
7070
7171
dependencies {
72-
api 'com.github.wyjsonGo.GoRouter:GoRouter-Api:2.4.7'
72+
api 'com.github.wyjsonGo.GoRouter:GoRouter-Api:2.4.8'
7373
}
7474
// Kotlin配置参见8-1
7575
```
@@ -89,7 +89,7 @@ android {
8989
}
9090
9191
dependencies {
92-
annotationProcessor 'com.github.wyjsonGo.GoRouter:GoRouter-Compiler:2.4.7'
92+
annotationProcessor 'com.github.wyjsonGo.GoRouter:GoRouter-Compiler:2.4.8'
9393
}
9494
```
9595

@@ -157,7 +157,7 @@ pluginManagement {
157157
// 项目根目录下的build.gradle
158158
buildscript {
159159
dependencies {
160-
classpath 'com.github.wyjsonGo.GoRouter:GoRouter-Gradle-Plugin:2.4.7'
160+
classpath 'com.github.wyjsonGo.GoRouter:GoRouter-Gradle-Plugin:2.4.8'
161161
}
162162
}
163163
```
@@ -894,7 +894,7 @@ kapt {
894894
}
895895

896896
dependencies {
897-
kapt 'com.github.wyjsonGo.GoRouter:GoRouter-Compiler:2.4.7'
897+
kapt 'com.github.wyjsonGo.GoRouter:GoRouter-Compiler:2.4.8'
898898
}
899899
```
900900

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22
buildscript {
33
dependencies {
4-
classpath "com.github.wyjsonGo.GoRouter:GoRouter-Gradle-Plugin:${VERSION}"
4+
// classpath "com.github.wyjsonGo.GoRouter:GoRouter-Gradle-Plugin:${VERSION}"
55
}
66
}
77

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ android.nonTransitiveRClass=true
2525
# org.gradle.jvmargs=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
2626

2727
GROUP_ID=com.github.wyjsonGo.GoRouter
28-
VERSION=2.4.7
28+
VERSION=2.4.8

settings.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ dependencyResolutionManagement {
1818

1919
rootProject.name = "GoRouter"
2020

21-
include ':app'
22-
include ':module_main'
23-
include ':module_user'
24-
include ':module_kotlin'
25-
include ':module_common'
21+
//include ':app'
22+
//include ':module_main'
23+
//include ':module_user'
24+
//include ':module_kotlin'
25+
//include ':module_common'
2626

2727
include ':GoRouter-Api'
2828
include ':GoRouter-Annotation'

0 commit comments

Comments
 (0)