@@ -21,7 +21,249 @@ public class AppModuleController extends Controller {
2121 // 这里注册对应模块
2222 this . addOnceModuleClass(RunsUserLoginModule . class);
2323 this . addOnceModuleClass(RunsHomePageModule . class);
24+ }# PureMVC_AppFacade_Android
25+
26+ #####< font color= " #272727" size = " 3px" > 这库是一个轻量级MVC 为Android 软件从头开始架构的,特点是轻、解耦、模块化,业务分离,简单实用< / font>
27+
28+ #####< font color= " #4590a3" size = " 3px" > This library is a lightweight MVC architecture for Android software from the ground up, featuring light, decoupling, modular, business separation, simple and practical. < / font>
29+
30+ #####< font color= " #272727" size = " 3px" > 该库的设计主要有 Facade 、Observer 等,以及热插拔特性,充分给了我开发者注重业务开发逻辑注意力,而不用在意逻辑的分离与耦合< / font>
31+
32+ #####< 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>
33+
34+ ####< font color= " #000000" size = " 6px" > How To Get Started :< / font>
35+ #####< font color= " #4590a3" size = " 4px" > 第一步 初始化自定义模块控制类:用于注册模块和解注册模块< / font>
36+
37+ #### < a name= " AppModuleController" > AppModuleController :< / a>
38+ ######初始化和创建 < font color= " #4590a3" size = " 3px" > AppModuleController</ font> , 它继承自 < font color= " #4590a3" size = " 3px" > Controller</ font>
39+ ```java
40+ public class AppModuleController extends Controller {
41+ @Override
42+ public void registerAllModules () {
43+ super . registerAllModules();
44+ // 这里注册对应模块
45+ this . addOnceModuleClass(RunsUserLoginModule . class);
46+ this . addOnceModuleClass(RunsHomePageModule . class);
47+ }
48+
49+ @Override
50+ public void unRegisterAllModules () {
51+ super . unRegisterAllModules();
52+ // 这里解注册对应模块(最好位置与注册对应)
53+ this . removeModule(RunsUserLoginModule . class. getName());
54+ this . removeModule(RunsHomePageModule . class. getName());
55+ }
56+ }
57+ ```
58+ ```java
59+ public class MainActivity extends AppCompatActivity {
60+ private ActivityMainBinding activityMainBinding = null ;
61+ public MainActivity () {
62+ super ();
63+ // 初始化调用 注册模块到模块管理类
64+ Facade . getInstance(). init(new AppModuleController ());
65+ }
66+ }
67+ ```
68+
69+ #####< font color= " #4590a3" size = " 4px" > 第二步 创建模块文件夹目录(如图)< / font>
70+
71+ ######至于每个模块分别是什么职责一目了然
72+
73+ ! [F04F6A3FB1343515D617810B1681E63F.jpg](./puremvc_appfacade/image/F04F6A3FB1343515D617810B1681E63F.jpg)
74+
75+ 
76+
77+ #####<font color="#4590a3" size = "4px"> 第三步 创建对应的功能模块,比如登录、主页等</font>
78+ #### <a name="RunsUserLoginModule "> RunsUserLoginModule</a>
79+ ######初始化和创建 <font color="#4590a3" size = "3px"> RunsUserLoginModule</font> , 它继承自 <font color="#4590a3" size = "3px"> Module</font> , 注册该模块需要的<font color="#4590a3" size = "3px"> Mediator,ViewModel</font> , 以及移除解注册.
80+ ```java
81+ public class RunsUserLoginModule extends Module {
82+
83+ @Override
84+ public void onRegister() {
85+ this . registerMediatorClass(RunsUserLoginMediator . class);
86+ this . registerMediatorClass(RunsUserRegisterMediator . class);
87+ //
88+ this . registerViewModelClass(RunsUserLoginViewModel . class);
89+ }
90+
91+ @Override
92+ public void onRemove() {
93+ this . removeAllMediator();
94+ this . removeAllViewModel();
95+ }
96+ }
97+ ```
98+ ```java
99+ public class RunsUserLoginMediator extends Mediator {
100+
101+ @Override
102+ public void initializeMediator () {
103+ super . initializeMediator();
104+ }
105+
106+ @Override
107+ public void handleNotification (INotification notification ) {
108+ super . handleNotification(notification);
109+ String notificationName = notification. getName();
110+
111+ if (notificationName. equals(Runs . BIND_VIEW_COMPONENT )) {
112+ Object object = notification. getObject();
113+ if (null != object) {
114+ this . setViewComponent(object);
115+ Toast . makeText((Context )object, Runs . BIND_VIEW_COMPONENT , Toast . LENGTH_SHORT ). show();
116+ }
117+ return ;
118+ }
119+
120+ if (notificationName. equals(Runs . USER_LOGIN_NOTIFICATION )) {
121+ ...
122+ return ;
123+ }
124+
125+ if (notificationName. equals(Runs . USER_REGISTER_NOTIFICATION )){
126+ ...
127+ return ;
128+ }
129+
130+ if (notificationName. equals(Runs . USER_LOGOUT_NOTIFICATION )) {
131+ ...
132+ return ;
133+ }
134+
135+ }
136+
137+ @Override
138+ public String [] listNotificationInterests () {
139+ return new String []{
140+ Runs . BIND_VIEW_COMPONENT ,
141+ Runs . USER_LOGIN_NOTIFICATION ,
142+ Runs . USER_LOGOUT_NOTIFICATION ,
143+ Runs . USER_REGISTER_NOTIFICATION };
144+ }
145+ }
146+
147+ ```
148+
149+ ```java
150+ public abstract class Runs {
151+
152+ public static final IFacade FACADE = Facade . getInstance();
153+
154+ // RunsUserLoginMediator
155+ public static final String BIND_VIEW_COMPONENT = " BIND_VIEW_COMPONENT" ;
156+ public static final String USER_LOGIN_NOTIFICATION = " USER_LOGIN_NOTIFICATION" ;
157+ public static final String USER_LOGOUT_NOTIFICATION = " USER_LOGOUT_NOTIFICATION" ;
158+ public static final String USER_REGISTER_NOTIFICATION = " USER_REGISTER_NOTIFICATION" ;
159+
160+ // RunsUserRegisterMediator
161+ public static final String BIND_REGISTER_COMPONENT = " BIND_REGISTER_COMPONENT" ;
162+ public static final String USER_BIND_PHONE_NOTIFICATION = " USER_BIND_PHONE_NOTIFICATION" ;
163+ public static final String USER_REGISTER_DONE_NOTIFICATION = " USER_REGISTER_DONE_NOTIFICATION" ;
164+
165+ }
166+
167+ ```
168+
169+ ```java
170+
171+ public class RunsUserLoginViewModel extends ViewModel {
172+ @Override
173+ public void setModel (Object model ) {
174+ super . setModel(model);
175+ }
176+
177+ @Override
178+ public void initializeViewModel () {
179+ super . initializeViewModel();
180+ }
181+ }
182+ ```
183+ ####< font color= " #000000" size = " 6px" > Usage :< / font>
184+ 1.根据注册名(Java中反射获取Class字符串)获取对应 **Mediator**(不常用)
185+ ```java
186+ String className = RunsUserLoginMediator.class.getName ();
187+ RunsUserLoginMediator mediator = (RunsUserLoginMediator )Runs . FACADE. getMediatorWithName(className);
188+ ```
189+ 2.根据注册名(Java中反射获取Class字符串)获取对应 **ViewModel**(常用)
190+ ```java
191+ String className = RunsUserLoginViewModel.class.getName ();
192+ IViewModel viewModel = Runs . FACADE. getViewModelWithName(className);
193+ ```
194+ 3. 核心用法,消息派发. 通过** sendNotification** 方法,发出的消息会被对应监听的** Mediator ** 收听到而做对应的逻辑处理(核心)
195+ ```java
196+ @Override
197+ protected void onCreate (Bundle savedInstanceState ) {
198+ super . onCreate(savedInstanceState);
199+ Runs . FACADE. sendNotification(Runs . BIND_VIEW_COMPONENT , this );
200+
201+ activityMainBinding = DataBindingUtil . setContentView(this , R . layout. activity_main);
202+ activityMainBinding. login. setOnClickListener(new View .OnClickListener () {
203+ @Override
204+ public void onClick (View v ) {
205+ Runs . FACADE. sendNotification(Runs . USER_LOGIN_NOTIFICATION );
206+ Intent intent = new Intent (MainActivity . this , RunsUserLoginActivity . class);
207+ startActivity(intent);
208+ }
209+ });
210+
211+ activityMainBinding. register. setOnClickListener(new View .OnClickListener () {
212+ @Override
213+ public void onClick (View v ) {
214+ Runs . FACADE. sendNotification(Runs . USER_REGISTER_NOTIFICATION );
215+ }
216+ });
217+
218+ activityMainBinding. logout. setOnClickListener(new View .OnClickListener () {
219+ @Override
220+ public void onClick (View v ) {
221+ Runs . FACADE. sendNotification(Runs . USER_LOGOUT_NOTIFICATION );
222+ }
223+ });
24224 }
225+ ```
226+ ###Download
227+ You can download a jar from GitHub's [releases page](https:// github.com/RunsCode/AppFacadeMVC/releases).
228+ Gradle:
229+ ```ruby
230+ allprojects {
231+ repositories {
232+ ...
233+ maven { url ' https://jitpack.io' }
234+ }
235+ }
236+ ```
237+ ```ruby
238+ dependencies {
239+ compile ' com.github.RunsCode:AppFacadeMVC:v1.0.0'
240+ }
241+ ```
242+ Maven :
243+ ```xml
244+ < repositories>
245+ < repository>
246+ < id> jitpack. io< / id>
247+ < url> https: // jitpack.io</url>
248+ < / repository>
249+ < / repositories>
250+ ```
251+ ```xml
252+ < dependency>
253+ < groupId> com.github.RunsCode</ groupId>
254+ < artifactId> AppFacadeMVC</ artifactId>
255+ < version> v1. 0.0 < / version>
256+ < / dependency>
257+ ```
258+
259+
260+ ### Security Disclosure
261+
262+ If you believe you have identified a security vulnerability with PureMVC_AppFacade_Android , you should report it as soon as possible via email to dev_wang@foxmail . com. Please do not post it to a public issue tracker.
263+
264+ ## License
265+
266+ PureMVC_AppFacade_Android is released under the MIT license. See LICENSE for details.
25267
26268 @Override
27269 public void unRegisterAllModules() {
0 commit comments