-
Notifications
You must be signed in to change notification settings - Fork 153
/
MVP_generator_solution
333 lines (224 loc) · 8.23 KB
/
MVP_generator_solution
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
第二代模版已经开源到 https://github.com/JessYanCoding/MVPArmsTemplate ,一键生成所有文件
Name: ArtActivity
--------------------------------------------------------------------------------------
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
import android.os.Bundle;
import me.jessyan.art.base.App;
import me.jessyan.art.base.BaseActivity;
import me.jessyan.art.mvp.IView;
import me.jessyan.art.mvp.Message;
import me.jessyan.art.utils.ArtUtils;
#parse("File Header.java")
public class ${NAME}Activity extends BaseActivity<${NAME}Presenter> implements IView {
@Override
public int initView(Bundle savedInstanceState) {
return 0;
}
@Override
public void initData(Bundle savedInstanceState) {
}
@Override
public ${NAME}Presenter obtainPresenter() {
return new ${NAME}Presenter(ArtUtils.obtainAppComponentFromContext(this));
}
@Override
public void showLoading() {
}
@Override
public void hideLoading() {
}
@Override
public void showMessage(String message) {
ArtUtils.snackbarText(message);
}
@Override
public void handleMessage(Message message) {
switch (message.what) {
case 0:
break;
case 1:
break;
}
}
}
--------------------------------------------------------------------------------------
Name: ArtModel
--------------------------------------------------------------------------------------
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
import me.jessyan.art.mvp.IModel;
import me.jessyan.art.mvp.IRepositoryManager;
/**
* 必须实现 IModel
* 可以根据不同的业务逻辑划分多个 Repository 类,多个业务逻辑相近的页面可以使用同一个 Repository 类
* 无需每个页面都创建一个独立的 Repository
* 通过 {@link me.jessyan.art.mvp.IRepositoryManager#createRepository(java.lang.Class)} 获得的 Repository 实例,为单例对象
*/
#parse("File Header.java")
public class ${NAME}Repository implements IModel {
private IRepositoryManager mManager;
/**
* 必须含有一个接收IRepositoryManager接口的构造函数,否则会报错
* @param manager
*/
public ${NAME}Repository(IRepositoryManager manager) {
this.mManager = manager;
}
@Override
public void onDestroy() {
}
}
--------------------------------------------------------------------------------------
Name: ArtPresenter
--------------------------------------------------------------------------------------
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
import me.jessyan.art.di.component.AppComponent;
import me.jessyan.art.mvp.BasePresenter;
import me.jessyan.rxerrorhandler.core.RxErrorHandler;
#parse("File Header.java")
public class ${NAME}Presenter extends BasePresenter<YoureRepository> {
private RxErrorHandler mErrorHandler;
public ${NAME}Presenter(AppComponent appComponent) {
super(appComponent.repositoryManager().createRepository(YoureRepository.class));
this.mErrorHandler = appComponent.rxErrorHandler();
}
@Override
public void onDestroy() {
super.onDestroy();
this.mErrorHandler = null;
}
}
--------------------------------------------------------------------------------------
Name: ArtFragment
--------------------------------------------------------------------------------------
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import me.jessyan.art.base.App;
import me.jessyan.art.base.BaseFragment;
import me.jessyan.art.mvp.IView;
import me.jessyan.art.mvp.Message;
import me.jessyan.art.utils.ArtUtils;
#parse("File Header.java")
public class ${NAME}Fragment extends BaseFragment<${NAME}Presenter> implements IView{
public static ${NAME}Fragment newInstance() {
${NAME}Fragment fragment = new ${NAME}Fragment();
return fragment;
}
@Override
public View initView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(layout_id, container, false);
}
@Override
public void initData(Bundle savedInstanceState) {
}
@Override
public ${NAME}Presenter obtainPresenter() {
return new ${NAME}Presenter(ArtUtils.obtainAppComponentFromContext(getActivity()));
}
/**
* 此方法是让外部调用使fragment做一些操作的,比如说外部的activity想让fragment对象执行一些方法,
* 建议在有多个需要让外界调用的方法时,统一传Message,通过what字段,来区分不同的方法,在setData
* 方法中就可以switch做不同的操作,这样就可以用统一的入口方法做不同的事
*
* 使用此方法时请注意调用时fragment的生命周期,如果调用此setData方法时onCreate还没执行
* setData里却调用了presenter的方法时,是会报空的,因为presenter是在onCreate方法中创建的
* 如果要做一些初始化操作,可以不必让外部调setData,在initData中初始化就可以了
*
* @param data
*/
@Override
public void setData(Object data) {
}
@Override
public void showLoading() {
}
@Override
public void hideLoading() {
}
@Override
public void showMessage(String message) {
ArtUtils.snackbarText(message);
}
@Override
public void handleMessage(Message message) {
switch (message.what) {
case 0:
break;
case 1:
break;
}
}
}
--------------------------------------------------------------------------------------
Name: AutoView
--------------------------------------------------------------------------------------
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.ViewGroup;
import com.zhy.autolayout.AutoLayoutInfo;
import com.zhy.autolayout.utils.AutoLayoutHelper;
/**
* 此Template用于生成AutoLayout需要的的Auto系列View,如需要使ScrollView适配,使用此Template输入ScrollView,即可生成
* AutoScrollView,使用此View即可自适应
* Created by jess on 16/4/14.
*/
public class Auto${NAME} extends ${NAME} {
private AutoLayoutHelper mHelper = new AutoLayoutHelper(this);
public Auto${NAME}(Context context) {
super(context);
}
public Auto${NAME}(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public Auto${NAME}(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
if (!isInEditMode())
mHelper.adjustChildren();
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b)
{
super.onLayout(changed, l, t, r, b);
}
@Override
public LayoutParams generateLayoutParams(AttributeSet attrs) {
return new LayoutParams(getContext(), attrs);
}
public static class LayoutParams extends ${NAME}.LayoutParams
implements AutoLayoutHelper.AutoLayoutParams
{
private AutoLayoutInfo mAutoLayoutInfo;
public LayoutParams(Context c, AttributeSet attrs)
{
super(c, attrs);
mAutoLayoutInfo = AutoLayoutHelper.getAutoLayoutInfo(c, attrs);
}
@Override
public AutoLayoutInfo getAutoLayoutInfo()
{
return mAutoLayoutInfo;
}
public LayoutParams(int width, int height)
{
super(width, height);
}
public LayoutParams(ViewGroup.LayoutParams source)
{
super(source);
}
public LayoutParams(MarginLayoutParams source)
{
super(source);
}
}
}
--------------------------------------------------------------------------------------