Skip to content

Commit aa2491b

Browse files
author
Dev_Wang
committed
...
1 parent d1b2a46 commit aa2491b

File tree

2 files changed

+130
-6
lines changed

2 files changed

+130
-6
lines changed

README.md

Lines changed: 130 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#####<font color="#4590a3" size = "3px">The design of the library are Facade, Observer, etc., and hot-swap features, and give me the full attention of developers focus on business development logic, rather than care about the separation and coupling logic.</font>
1010

11-
####<font color="#000000" size = "6px">Usage:</font>
11+
####<font color="#000000" size = "6px">How To Get Started:</font>
1212
#####<font color="#4590a3" size = "4px">第一步 初始化自定义模块控制类:用于注册模块和解注册模块</font>
1313

1414
#### <a name="AppModuleController">AppModuleController:</a>
@@ -72,3 +72,132 @@ public class RunsUserLoginModule extends Module {
7272
}
7373
}
7474
```
75+
```java
76+
public class RunsUserLoginMediator extends Mediator {
77+
78+
@Override
79+
public void initializeMediator() {
80+
super.initializeMediator();
81+
}
82+
83+
@Override
84+
public void handleNotification(INotification notification) {
85+
super.handleNotification(notification);
86+
String notificationName = notification.getName();
87+
88+
if (notificationName.equals(Runs.BIND_VIEW_COMPONENT)) {
89+
Object object = notification.getObject();
90+
if (null != object) {
91+
this.setViewComponent(object);
92+
Toast.makeText((Context)object, Runs.BIND_VIEW_COMPONENT, Toast.LENGTH_SHORT).show();
93+
}
94+
return;
95+
}
96+
97+
if (notificationName.equals(Runs.USER_LOGIN_NOTIFICATION)) {
98+
...
99+
return;
100+
}
101+
102+
if (notificationName.equals(Runs.USER_REGISTER_NOTIFICATION)){
103+
...
104+
return;
105+
}
106+
107+
if (notificationName.equals(Runs.USER_LOGOUT_NOTIFICATION)) {
108+
...
109+
return;
110+
}
111+
112+
}
113+
114+
@Override
115+
public String[] listNotificationInterests() {
116+
return new String[]{
117+
Runs.BIND_VIEW_COMPONENT,
118+
Runs.USER_LOGIN_NOTIFICATION,
119+
Runs.USER_LOGOUT_NOTIFICATION,
120+
Runs.USER_REGISTER_NOTIFICATION };
121+
}
122+
}
123+
124+
```
125+
126+
```java
127+
public abstract class Runs {
128+
129+
public static final IFacade FACADE = Facade.getInstance();
130+
131+
//RunsUserLoginMediator
132+
public static final String BIND_VIEW_COMPONENT = "BIND_VIEW_COMPONENT";
133+
public static final String USER_LOGIN_NOTIFICATION = "USER_LOGIN_NOTIFICATION";
134+
public static final String USER_LOGOUT_NOTIFICATION = "USER_LOGOUT_NOTIFICATION";
135+
public static final String USER_REGISTER_NOTIFICATION = "USER_REGISTER_NOTIFICATION";
136+
137+
//RunsUserRegisterMediator
138+
public static final String BIND_REGISTER_COMPONENT = "BIND_REGISTER_COMPONENT";
139+
public static final String USER_BIND_PHONE_NOTIFICATION = "USER_BIND_PHONE_NOTIFICATION";
140+
public static final String USER_REGISTER_DONE_NOTIFICATION = "USER_REGISTER_DONE_NOTIFICATION";
141+
142+
}
143+
144+
```
145+
146+
```java
147+
148+
public class RunsUserLoginViewModel extends ViewModel {
149+
@Override
150+
public void setModel(Object model) {
151+
super.setModel(model);
152+
}
153+
154+
@Override
155+
public void initializeViewModel() {
156+
super.initializeViewModel();
157+
}
158+
}
159+
```
160+
####<font color="#000000" size = "6px">Usage:</font>
161+
1.根据注册名(Java中反射获取Class字符串)获取对应 **Mediator**(不常用)
162+
```java
163+
String className = RunsUserLoginMediator.class.getName();
164+
RunsUserLoginMediator mediator = (RunsUserLoginMediator)Runs.FACADE.getMediatorWithName(className);
165+
```
166+
2.根据注册名(Java中反射获取Class字符串)获取对应 **ViewModel**(常用)
167+
```java
168+
String className = RunsUserLoginViewModel.class.getName();
169+
IViewModel viewModel = Runs.FACADE.getViewModelWithName(className);
170+
```
171+
3.核心用法,消息派发.通过**sendNotification**方法,发出的消息会被对应监听的**Mediator**收听到而做对应的逻辑处理(核心)
172+
```java
173+
@Override
174+
protected void onCreate(Bundle savedInstanceState) {
175+
super.onCreate(savedInstanceState);
176+
Runs.FACADE.sendNotification(Runs.BIND_VIEW_COMPONENT, this);
177+
178+
activityMainBinding = DataBindingUtil.setContentView(this, R.layout.activity_main);
179+
activityMainBinding.login.setOnClickListener(new View.OnClickListener() {
180+
@Override
181+
public void onClick(View v) {
182+
Runs.FACADE.sendNotification(Runs.USER_LOGIN_NOTIFICATION);
183+
Intent intent = new Intent(MainActivity.this, RunsUserLoginActivity.class);
184+
startActivity(intent);
185+
}
186+
});
187+
188+
activityMainBinding.register.setOnClickListener(new View.OnClickListener() {
189+
@Override
190+
public void onClick(View v) {
191+
Runs.FACADE.sendNotification(Runs.USER_REGISTER_NOTIFICATION);
192+
}
193+
});
194+
195+
activityMainBinding.logout.setOnClickListener(new View.OnClickListener() {
196+
@Override
197+
public void onClick(View v) {
198+
Runs.FACADE.sendNotification(Runs.USER_LOGOUT_NOTIFICATION);
199+
}
200+
});
201+
}
202+
203+
```

app/src/main/java/com/example/dev_wang/databindingdemo/MainActivity.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,6 @@ public void onClick(View v) {
5252
}
5353
});
5454

55-
RunsLog.v("吧吧吧吧吧吧吧");
56-
RunsLog.d("吧吧吧吧吧吧吧");
57-
RunsLog.i("吧吧吧吧吧吧吧");
58-
RunsLog.w("吧吧吧吧吧吧吧");
59-
RunsLog.e("吧吧吧吧吧吧吧");
6055
// String className = RunsUserLoginViewModel.class.getName();
6156
// IViewModel viewModel = Runs.FACADE.getViewModelWithName(className);
6257
// String viewModelName = viewModel.getViewModelName();

0 commit comments

Comments
 (0)