├── LICENSE
├── MVPArmsTemplate
├── dagger2.gradle.ftl
├── dagger2_macros.ftl
├── globals.xml.ftl
├── recipe.xml.ftl
├── root
│ ├── AndroidManifest.xml.ftl
│ ├── res
│ │ └── layout
│ │ │ └── simple.xml.ftl
│ └── src
│ │ └── app_package
│ │ ├── ArmsActivity.java.ftl
│ │ ├── ArmsActivity.kt.ftl
│ │ ├── ArmsComponent.java.ftl
│ │ ├── ArmsComponent.kt.ftl
│ │ ├── ArmsContract.java.ftl
│ │ ├── ArmsContract.kt.ftl
│ │ ├── ArmsFragment.java.ftl
│ │ ├── ArmsFragment.kt.ftl
│ │ ├── ArmsModel.java.ftl
│ │ ├── ArmsModel.kt.ftl
│ │ ├── ArmsModule.java.ftl
│ │ ├── ArmsModule.kt.ftl
│ │ ├── ArmsPresenter.java.ftl
│ │ └── ArmsPresenter.kt.ftl
├── template.xml
└── template_blank_activity.png
├── MVPArtTemplate
├── dagger2.gradle.ftl
├── dagger2_macros.ftl
├── globals.xml.ftl
├── recipe.xml.ftl
├── root
│ ├── AndroidManifest.xml.ftl
│ ├── res
│ │ └── layout
│ │ │ └── simple.xml.ftl
│ └── src
│ │ └── app_package
│ │ ├── ArtActivity.java.ftl
│ │ ├── ArtActivity.kt.ftl
│ │ ├── ArtFragment.java.ftl
│ │ ├── ArtFragment.kt.ftl
│ │ ├── ArtModel.java.ftl
│ │ ├── ArtModel.kt.ftl
│ │ ├── ArtPresenter.java.ftl
│ │ └── ArtPresenter.kt.ftl
├── template.xml
└── template_blank_activity.png
├── README.md
└── art
├── MVPArmsTemplate.gif
├── attention.png
└── step.png
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/MVPArmsTemplate/dagger2.gradle.ftl:
--------------------------------------------------------------------------------
1 | dependencies {
2 | kapt rootProject.ext.dependencies["dagger2-compiler"]
3 | }
--------------------------------------------------------------------------------
/MVPArmsTemplate/dagger2_macros.ftl:
--------------------------------------------------------------------------------
1 | <#macro addAllKaptDependencies>
2 | <#if !isNewModule && ((language!'Java')?string == 'Kotlin')>
3 |
18 | * Created by MVPArmsTemplate on ${.now?string["MM/dd/yyyy HH:mm"]}
19 | * Contact me
20 | * Follow me
21 | * Star me
22 | * See me
23 | * 模版请保持更新
24 | * ================================================
25 | */
26 | #macro>
--------------------------------------------------------------------------------
/MVPArmsTemplate/recipe.xml.ftl:
--------------------------------------------------------------------------------
1 |
2 | <#import "root://activities/common/kotlin_macros.ftl" as kt>
3 | <#import "root://activities/MVPArmsTemplate/dagger2_macros.ftl" as dagger2>
4 |
60 | * 调用此方法时请注意调用时 Fragment 的生命周期, 如果调用 {@link #setData(Object)} 方法时 {@link Fragment#onCreate(Bundle)} 还没执行 61 | * 但在 {@link #setData(Object)} 里却调用了 Presenter 的方法, 是会报空的, 因为 Dagger 注入是在 {@link Fragment#onCreate(Bundle)} 方法中执行的 62 | * 然后才创建的 Presenter, 如果要做一些初始化操作,可以不必让外部调用 {@link #setData(Object)}, 在 {@link #initData(Bundle)} 中初始化就可以了 63 | *
64 | * Example usage: 65 | *
66 | * public void setData(@Nullable Object data) { 67 | * if (data != null && data instanceof Message) { 68 | * switch (((Message) data).what) { 69 | * case 0: 70 | * loadData(((Message) data).arg1); 71 | * break; 72 | * case 1: 73 | * refreshUI(); 74 | * break; 75 | * default: 76 | * //do something 77 | * break; 78 | * } 79 | * } 80 | * } 81 | * 82 | * // call setData(Object): 83 | * Message data = new Message(); 84 | * data.what = 0; 85 | * data.arg1 = 1; 86 | * fragment.setData(data); 87 | *88 | * 89 | * @param data 当不需要参数时 {@code data} 可以为 {@code null} 90 | */ 91 | @Override 92 | public void setData(@Nullable Object data) { 93 | 94 | } 95 | 96 | @Override 97 | public void showLoading() { 98 | 99 | } 100 | 101 | @Override 102 | public void hideLoading() { 103 | 104 | } 105 | 106 | @Override 107 | public void showMessage(@NonNull String message) { 108 | checkNotNull(message); 109 | ArmsUtils.snackbarText(message); 110 | } 111 | 112 | @Override 113 | public void launchActivity(@NonNull Intent intent) { 114 | checkNotNull(intent); 115 | ArmsUtils.startActivity(intent); 116 | } 117 | 118 | @Override 119 | public void killMyself() { 120 | 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /MVPArmsTemplate/root/src/app_package/ArmsFragment.kt.ftl: -------------------------------------------------------------------------------- 1 | package ${fragmentPackageName} 2 | 3 | import android.content.Intent 4 | import android.os.Bundle 5 | import android.os.Message 6 | import android.support.v4.app.Fragment 7 | import android.view.LayoutInflater 8 | import android.view.View 9 | import android.view.ViewGroup 10 | 11 | import com.jess.arms.base.BaseFragment 12 | import com.jess.arms.di.component.AppComponent 13 | import com.jess.arms.utils.ArmsUtils 14 | 15 | import ${componentPackageName}.Dagger${pageName}Component 16 | import ${moudlePackageName}.${pageName}Module 17 | import ${contractPackageName}.${pageName}Contract 18 | import ${presenterPackageName}.${pageName}Presenter 19 | 20 | import ${packageName}.R 21 | 22 | <#import "root://activities/MVPArmsTemplate/globals.xml.ftl" as gb> 23 | 24 | <@gb.fileHeader /> 25 | /** 26 | * 如果没presenter 27 | * 你可以这样写 28 | * 29 | * @FragmentScope(請注意命名空間) class NullObjectPresenterByFragment 30 | * @Inject constructor() : IPresenter { 31 | * override fun onStart() { 32 | * } 33 | * 34 | * override fun onDestroy() { 35 | * } 36 | * } 37 | */ 38 | class ${pageName}Fragment : BaseFragment<${pageName}Presenter>() , ${pageName}Contract.View{ 39 | companion object { 40 | fun newInstance():${pageName}Fragment { 41 | val fragment = ${pageName}Fragment() 42 | return fragment 43 | } 44 | } 45 | 46 | 47 | override fun setupFragmentComponent(appComponent:AppComponent) { 48 | Dagger${pageName}Component //如找不到该类,请编译一下项目 49 | .builder() 50 | .appComponent(appComponent) 51 | .${extractLetters(pageName[0]?lower_case)}${pageName?substring(1,pageName?length)}Module(${pageName}Module(this)) 52 | .build() 53 | .inject(this) 54 | } 55 | 56 | override fun initView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?):View{ 57 | return inflater.inflate(R.layout.${fragmentLayoutName}, container, false); 58 | } 59 | 60 | override fun initData(savedInstanceState:Bundle?) { 61 | 62 | } 63 | 64 | /** 65 | * 通过此方法可以使 Fragment 能够与外界做一些交互和通信, 比如说外部的 Activity 想让自己持有的某个 Fragment 对象执行一些方法, 66 | * 建议在有多个需要与外界交互的方法时, 统一传 {@link Message}, 通过 what 字段来区分不同的方法, 在 {@link #setData(Object)} 67 | * 方法中就可以 {@code switch} 做不同的操作, 这样就可以用统一的入口方法做多个不同的操作, 可以起到分发的作用 68 | *
69 | * 调用此方法时请注意调用时 Fragment 的生命周期, 如果调用 {@link #setData(Object)} 方法时 {@link Fragment#onCreate(Bundle)} 还没执行 70 | * 但在 {@link #setData(Object)} 里却调用了 Presenter 的方法, 是会报空的, 因为 Dagger 注入是在 {@link Fragment#onCreate(Bundle)} 方法中执行的 71 | * 然后才创建的 Presenter, 如果要做一些初始化操作,可以不必让外部调用 {@link #setData(Object)}, 在 {@link #initData(Bundle)} 中初始化就可以了 72 | *
73 | * Example usage: 74 | *
75 | *fun setData(data:Any) { 76 | * if(data is Message){ 77 | * when (data.what) { 78 | * 0-> { 79 | * //根据what 做你想做的事情 80 | * } 81 | * else -> { 82 | * } 83 | * } 84 | * } 85 | *} 86 | * 87 | * 88 | * 89 | * 90 | * 91 | * // call setData(Object): 92 | * val data = Message(); 93 | * data.what = 0; 94 | * data.arg1 = 1; 95 | * fragment.setData(data); 96 | *97 | * 98 | * @param data 当不需要参数时 {@code data} 可以为 {@code null} 99 | */ 100 | override fun setData(data:Any?) { 101 | 102 | } 103 | 104 | override fun showLoading() { 105 | 106 | } 107 | 108 | override fun hideLoading() { 109 | 110 | } 111 | 112 | override fun showMessage(message:String) { 113 | ArmsUtils.snackbarText(message) 114 | } 115 | 116 | override fun launchActivity(intent:Intent) { 117 | ArmsUtils.startActivity(intent) 118 | } 119 | 120 | override fun killMyself() { 121 | 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /MVPArmsTemplate/root/src/app_package/ArmsModel.java.ftl: -------------------------------------------------------------------------------- 1 | package ${modelPackageName}; 2 | 3 | import android.app.Application; 4 | import com.google.gson.Gson; 5 | import com.jess.arms.integration.IRepositoryManager; 6 | import com.jess.arms.mvp.BaseModel; 7 | 8 | <#if needActivity && needFragment> 9 | import com.jess.arms.di.scope.ActivityScope; 10 | <#elseif needActivity> 11 | import com.jess.arms.di.scope.ActivityScope; 12 | <#elseif needFragment> 13 | import com.jess.arms.di.scope.FragmentScope; 14 | #if> 15 | import javax.inject.Inject; 16 | 17 | import ${contractPackageName}.${pageName}Contract; 18 | 19 | <#import "root://activities/MVPArmsTemplate/globals.xml.ftl" as gb> 20 | 21 | <@gb.fileHeader /> 22 | <#if needActivity && needFragment> 23 | @ActivityScope 24 | <#elseif needActivity> 25 | @ActivityScope 26 | <#elseif needFragment> 27 | @FragmentScope 28 | #if> 29 | public class ${pageName}Model extends BaseModel implements ${pageName}Contract.Model{ 30 | @Inject 31 | Gson mGson; 32 | @Inject 33 | Application mApplication; 34 | 35 | @Inject 36 | public ${pageName}Model(IRepositoryManager repositoryManager) { 37 | super(repositoryManager); 38 | } 39 | 40 | @Override 41 | public void onDestroy() { 42 | super.onDestroy(); 43 | this.mGson = null; 44 | this.mApplication = null; 45 | } 46 | } -------------------------------------------------------------------------------- /MVPArmsTemplate/root/src/app_package/ArmsModel.kt.ftl: -------------------------------------------------------------------------------- 1 | package ${modelPackageName} 2 | 3 | import android.app.Application 4 | import com.google.gson.Gson 5 | import com.jess.arms.integration.IRepositoryManager 6 | import com.jess.arms.mvp.BaseModel 7 | 8 | <#if needActivity && needFragment> 9 | import com.jess.arms.di.scope.ActivityScope 10 | <#elseif needActivity> 11 | import com.jess.arms.di.scope.ActivityScope 12 | <#elseif needFragment> 13 | import com.jess.arms.di.scope.FragmentScope 14 | #if> 15 | import javax.inject.Inject 16 | 17 | import ${contractPackageName}.${pageName}Contract 18 | 19 | <#import "root://activities/MVPArmsTemplate/globals.xml.ftl" as gb> 20 | 21 | <@gb.fileHeader /> 22 | <#if needActivity && needFragment> 23 | @ActivityScope 24 | <#elseif needActivity> 25 | @ActivityScope 26 | <#elseif needFragment> 27 | @FragmentScope 28 | #if> 29 | class ${pageName}Model 30 | @Inject 31 | constructor(repositoryManager: IRepositoryManager) : BaseModel(repositoryManager), ${pageName}Contract.Model{ 32 | @Inject 33 | lateinit var mGson:Gson; 34 | @Inject 35 | lateinit var mApplication:Application; 36 | 37 | override fun onDestroy() { 38 | super.onDestroy(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /MVPArmsTemplate/root/src/app_package/ArmsModule.java.ftl: -------------------------------------------------------------------------------- 1 | package ${moudlePackageName}; 2 | 3 | <#if needActivity && needFragment> 4 | import com.jess.arms.di.scope.ActivityScope; 5 | <#elseif needActivity> 6 | import com.jess.arms.di.scope.ActivityScope; 7 | <#elseif needFragment> 8 | import com.jess.arms.di.scope.FragmentScope; 9 | #if> 10 | 11 | import dagger.Binds; 12 | import dagger.Module; 13 | import dagger.Provides; 14 | 15 | import ${contractPackageName}.${pageName}Contract; 16 | import ${modelPackageName}.${pageName}Model; 17 | 18 | <#import "root://activities/MVPArmsTemplate/globals.xml.ftl" as gb> 19 | 20 | <@gb.fileHeader /> 21 | @Module 22 | public abstract class ${pageName}Module { 23 | 24 | @Binds 25 | abstract ${pageName}Contract.Model bind${pageName}Model(${pageName}Model model); 26 | } -------------------------------------------------------------------------------- /MVPArmsTemplate/root/src/app_package/ArmsModule.kt.ftl: -------------------------------------------------------------------------------- 1 | package ${moudlePackageName} 2 | 3 | <#if needActivity && needFragment> 4 | import com.jess.arms.di.scope.ActivityScope 5 | <#elseif needActivity> 6 | import com.jess.arms.di.scope.ActivityScope 7 | <#elseif needFragment> 8 | import com.jess.arms.di.scope.FragmentScope 9 | #if> 10 | 11 | import dagger.Module 12 | import dagger.Provides 13 | 14 | import ${contractPackageName}.${pageName}Contract 15 | import ${modelPackageName}.${pageName}Model 16 | 17 | <#import "root://activities/MVPArmsTemplate/globals.xml.ftl" as gb> 18 | 19 | <@gb.fileHeader /> 20 | @Module 21 | //构建${pageName}Module时,将View的实现类传进来,这样就可以提供View的实现类给presenter 22 | class ${pageName}Module(private val view:${pageName}Contract.View) { 23 | <#if needActivity && needFragment> 24 | @ActivityScope 25 | <#elseif needActivity> 26 | @ActivityScope 27 | <#elseif needFragment> 28 | @FragmentScope 29 | #if> 30 | @Provides 31 | fun provide${pageName}View():${pageName}Contract.View{ 32 | return this.view 33 | } 34 | 35 | <#if needActivity && needFragment> 36 | @ActivityScope 37 | <#elseif needActivity> 38 | @ActivityScope 39 | <#elseif needFragment> 40 | @FragmentScope 41 | #if> 42 | @Provides 43 | fun provide${pageName}Model(model:${pageName}Model):${pageName}Contract.Model{ 44 | return model 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /MVPArmsTemplate/root/src/app_package/ArmsPresenter.java.ftl: -------------------------------------------------------------------------------- 1 | package ${presenterPackageName}; 2 | 3 | import android.app.Application; 4 | 5 | import com.jess.arms.integration.AppManager; 6 | <#if needActivity && needFragment> 7 | import com.jess.arms.di.scope.ActivityScope; 8 | <#elseif needActivity> 9 | import com.jess.arms.di.scope.ActivityScope; 10 | <#elseif needFragment> 11 | import com.jess.arms.di.scope.FragmentScope; 12 | #if> 13 | import com.jess.arms.mvp.BasePresenter; 14 | import com.jess.arms.http.imageloader.ImageLoader; 15 | import me.jessyan.rxerrorhandler.core.RxErrorHandler; 16 | import javax.inject.Inject; 17 | 18 | import ${contractPackageName}.${pageName}Contract; 19 | 20 | <#import "root://activities/MVPArmsTemplate/globals.xml.ftl" as gb> 21 | 22 | <@gb.fileHeader /> 23 | <#if needActivity && needFragment> 24 | @ActivityScope 25 | <#elseif needActivity> 26 | @ActivityScope 27 | <#elseif needFragment> 28 | @FragmentScope 29 | #if> 30 | public class ${pageName}Presenter extends BasePresenter<${pageName}Contract.Model, ${pageName}Contract.View> { 31 | @Inject 32 | RxErrorHandler mErrorHandler; 33 | @Inject 34 | Application mApplication; 35 | @Inject 36 | ImageLoader mImageLoader; 37 | @Inject 38 | AppManager mAppManager; 39 | 40 | @Inject 41 | public ${pageName}Presenter (${pageName}Contract.Model model, ${pageName}Contract.View rootView) { 42 | super(model, rootView); 43 | } 44 | 45 | @Override 46 | public void onDestroy() { 47 | super.onDestroy(); 48 | this.mErrorHandler = null; 49 | this.mAppManager = null; 50 | this.mImageLoader = null; 51 | this.mApplication = null; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /MVPArmsTemplate/root/src/app_package/ArmsPresenter.kt.ftl: -------------------------------------------------------------------------------- 1 | package ${presenterPackageName} 2 | 3 | import android.app.Application 4 | 5 | import com.jess.arms.integration.AppManager 6 | <#if needActivity && needFragment> 7 | import com.jess.arms.di.scope.ActivityScope 8 | <#elseif needActivity> 9 | import com.jess.arms.di.scope.ActivityScope 10 | <#elseif needFragment> 11 | import com.jess.arms.di.scope.FragmentScope 12 | #if> 13 | import com.jess.arms.mvp.BasePresenter 14 | import com.jess.arms.http.imageloader.ImageLoader 15 | import me.jessyan.rxerrorhandler.core.RxErrorHandler 16 | import javax.inject.Inject 17 | 18 | import ${contractPackageName}.${pageName}Contract 19 | 20 | <#import "root://activities/MVPArmsTemplate/globals.xml.ftl" as gb> 21 | 22 | <@gb.fileHeader /> 23 | <#if needActivity && needFragment> 24 | @ActivityScope 25 | <#elseif needActivity> 26 | @ActivityScope 27 | <#elseif needFragment> 28 | @FragmentScope 29 | #if> 30 | class ${pageName}Presenter 31 | @Inject 32 | constructor(model: ${pageName}Contract.Model, rootView: ${pageName}Contract.View) : 33 | BasePresenter<${pageName}Contract.Model, ${pageName}Contract.View>(model,rootView) { 34 | @Inject 35 | lateinit var mErrorHandler:RxErrorHandler 36 | @Inject 37 | lateinit var mApplication:Application 38 | @Inject 39 | lateinit var mImageLoader:ImageLoader 40 | @Inject 41 | lateinit var mAppManager:AppManager 42 | 43 | 44 | override fun onDestroy() { 45 | super.onDestroy(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /MVPArmsTemplate/template.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 |
18 | * Created by MVPArtTemplate on ${.now?string["MM/dd/yyyy HH:mm"]}
19 | * Contact me
20 | * Follow me
21 | * Star me
22 | * See me
23 | * 模版请保持更新
24 | * ================================================
25 | */
26 | #macro>
--------------------------------------------------------------------------------
/MVPArtTemplate/recipe.xml.ftl:
--------------------------------------------------------------------------------
1 |
2 | <#import "root://activities/common/kotlin_macros.ftl" as kt>
3 | <#import "root://activities/MVPArmsTemplate/dagger2_macros.ftl" as dagger2>
4 |
57 | * 调用此方法时请注意调用时 Fragment 的生命周期, 如果调用 {@link #setData(Object)} 方法时 {@link Fragment#onCreate(Bundle)} 还没执行 58 | * 但在 {@link #setData(Object)} 里却调用了 Presenter 的方法, 是会报空的, 因为 Dagger 注入是在 {@link Fragment#onCreate(Bundle)} 方法中执行的 59 | * 然后才创建的 Presenter, 如果要做一些初始化操作,可以不必让外部调用 {@link #setData(Object)}, 在 {@link #initData(Bundle)} 中初始化就可以了 60 | *
61 | * Example usage: 62 | *
63 | * public void setData(@Nullable Object data) { 64 | * if (data != null && data instanceof Message) { 65 | * switch (((Message) data).what) { 66 | * case 0: 67 | * loadData(((Message) data).arg1); 68 | * break; 69 | * case 1: 70 | * refreshUI(); 71 | * break; 72 | * default: 73 | * //do something 74 | * break; 75 | * } 76 | * } 77 | * } 78 | * 79 | * // call setData(Object): 80 | * Message data = new Message(); 81 | * data.what = 0; 82 | * data.arg1 = 1; 83 | * fragment.setData(data); 84 | *85 | * 86 | * {@link #setData(Object)} 框架是不会调用的, 是拿给开发者自己去调用的, 让 {@link Activity} 或者其他类可以和 {@link Fragment} 通信, 87 | * 并且因为 {@link #setData(Object)} 是 {@link IFragment} 的方法, 所以你可以通过多态, 持有父类, 88 | * 不持有具体子类的方式就可以和子类 {@link Fragment} 通信, 这样如果需要替换子类, 就不会影响到其他地方, 89 | * 并且 {@link #setData(Object)} 可以通过传入 {@link Message} 作为参数, 使外部统一调用 {@link #setData(Object)}, 90 | * 方法内部再通过 {@code switch(message.what)} 的方式, 从而在外部调用方式不变的情况下, 却可以扩展更多的方法, 91 | * 让方法扩展更多的参数, 这样不管 {@link Fragment} 子类怎么变, 它内部的方法以及方法的参数怎么变, 却不会影响到外部调用的任何一行代码 92 | * 93 | * @param data 当不需要参数时 {@code data} 可以为 {@code null} 94 | */ 95 | @Override 96 | public void setData(@Nullable Object data) { 97 | 98 | } 99 | 100 | @Override 101 | public void showLoading() { 102 | 103 | } 104 | 105 | @Override 106 | public void hideLoading() { 107 | 108 | } 109 | 110 | @Override 111 | public void showMessage(@NonNull String message) { 112 | checkNotNull(message); 113 | ArtUtils.snackbarText(message); 114 | } 115 | 116 | @Override 117 | public void handleMessage(@NonNull Message message) { 118 | checkNotNull(message); 119 | switch (message.what) { 120 | case 0: 121 | break; 122 | case 1: 123 | break; 124 | } 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /MVPArtTemplate/root/src/app_package/ArtFragment.kt.ftl: -------------------------------------------------------------------------------- 1 | package ${packageName}${fragmentPackageName} 2 | 3 | import android.os.Bundle 4 | import android.app.Activity 5 | import android.support.v4.app.Fragment 6 | import android.view.LayoutInflater 7 | import android.view.View 8 | import android.view.ViewGroup 9 | 10 | import me.jessyan.art.base.BaseFragment 11 | import me.jessyan.art.base.delegate.IFragment 12 | import me.jessyan.art.mvp.IView 13 | import me.jessyan.art.mvp.Message 14 | import me.jessyan.art.utils.ArtUtils 15 | 16 | 17 | <#if presenterName?has_content> 18 | import ${packageName}${presenterPackageName}.${presenterName} 19 | #if> 20 | 21 | import ${packageName}.R 22 | 23 | <#import "root://activities/MVPArtTemplate/globals.xml.ftl" as gb> 24 | 25 | <@gb.fileHeader /> 26 | class ${pageName}Fragment : BaseFragment <#if presenterName?has_content><${presenterName}>#if>() , IView { 27 | 28 | companion object { 29 | fun newInstance():${pageName}Fragment { 30 | val fragment = ${pageName}Fragment() 31 | return fragment 32 | } 33 | } 34 | 35 | override fun initView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?):View{ 36 | return inflater.inflate(R.layout.${fragmentLayoutName}, container, false); 37 | } 38 | 39 | override fun initData(savedInstanceState:Bundle?) { 40 | 41 | } 42 | 43 | override fun obtainPresenter():<#if presenterName?has_content>${presenterName}<#else>IPresenter#if>? { 44 | return <#if presenterName?has_content> ${presenterName}(ArtUtils.obtainAppComponentFromContext(activity))<#else> null#if>; 45 | } 46 | 47 | /** 48 | * 通过此方法可以使 Fragment 能够与外界做一些交互和通信, 比如说外部的 Activity 想让自己持有的某个 Fragment 对象执行一些方法, 49 | * 建议在有多个需要与外界交互的方法时, 统一传 {@link Message}, 通过 what 字段来区分不同的方法, 在 {@link #setData(Object)} 50 | * 方法中就可以 {@code switch} 做不同的操作, 这样就可以用统一的入口方法做多个不同的操作, 可以起到分发的作用 51 | *
52 | * 调用此方法时请注意调用时 Fragment 的生命周期, 如果调用 {@link #setData(Object)} 方法时 {@link Fragment#onCreate(Bundle)} 还没执行 53 | * 但在 {@link #setData(Object)} 里却调用了 Presenter 的方法, 是会报空的, 因为 Dagger 注入是在 {@link Fragment#onCreate(Bundle)} 方法中执行的 54 | * 然后才创建的 Presenter, 如果要做一些初始化操作,可以不必让外部调用 {@link #setData(Object)}, 在 {@link #initData(Bundle)} 中初始化就可以了 55 | *
56 | * Example usage: 57 | *
58 | * fun setData(data:Any) { 59 | * if(data is Message){ 60 | * when (data.what) { 61 | * 0-> { 62 | * //根据what 做你想做的事情 63 | * } 64 | * else -> { 65 | * } 66 | * } 67 | * } 68 | * } 69 | * 70 | * 71 | * 72 | * 73 | * 74 | * // call setData(Object) 75 | * val data = Message() 76 | * data.what = 0 77 | * data.arg1 = 1 78 | * fragment.setData(data) 79 | *80 | * 81 | * {@link #setData(Object)} 框架是不会调用的, 是拿给开发者自己去调用的, 让 {@link Activity} 或者其他类可以和 {@link Fragment} 通信, 82 | * 并且因为 {@link #setData(Object)} 是 {@link IFragment} 的方法, 所以你可以通过多态, 持有父类, 83 | * 不持有具体子类的方式就可以和子类 {@link Fragment} 通信, 这样如果需要替换子类, 就不会影响到其他地方, 84 | * 并且 {@link #setData(Object)} 可以通过传入 {@link Message} 作为参数, 使外部统一调用 {@link #setData(Object)}, 85 | * 方法内部再通过 {@code when(message.what)} 的方式, 从而在外部调用方式不变的情况下, 却可以扩展更多的方法, 86 | * 让方法扩展更多的参数, 这样不管 {@link Fragment} 子类怎么变, 它内部的方法以及方法的参数怎么变, 却不会影响到外部调用的任何一行代码 87 | * 88 | * @param data 当不需要参数时 {@code data} 可以为 {@code null} 89 | */ 90 | override fun setData(data:Any?) { 91 | 92 | } 93 | 94 | override fun showLoading() { 95 | 96 | } 97 | 98 | override fun hideLoading() { 99 | 100 | } 101 | 102 | override fun showMessage(message:String) { 103 | ArtUtils.snackbarText(message) 104 | } 105 | 106 | override fun handleMessage(message: Message) { 107 | when (message.what) { 108 | 0 -> { 109 | //根据what 执行不同事务 110 | } 111 | else -> { 112 | } 113 | } 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /MVPArtTemplate/root/src/app_package/ArtModel.java.ftl: -------------------------------------------------------------------------------- 1 | package ${packageName}${modelPackageName}; 2 | 3 | import me.jessyan.art.mvp.IModel; 4 | import me.jessyan.art.mvp.IRepositoryManager; 5 | 6 | /** 7 | * ================================================ 8 | * 必须实现 IModel 9 | * 可以根据不同的业务逻辑划分多个 Repository 类, 多个业务逻辑相近的页面可以使用同一个 Repository 类 10 | * 无需每个页面都创建一个独立的 Repository 11 | * 通过 {@link me.jessyan.art.mvp.IRepositoryManager#createRepository(java.lang.Class)} 获得的 Repository 实例, 为单例对象 12 | *
13 | * Created by MVPArtTemplate on ${.now?string["MM/dd/yyyy HH:mm"]} 14 | * Contact me 15 | * Follow me 16 | * Star me 17 | * See me 18 | * 模版请保持更新 19 | * ================================================ 20 | */ 21 | public class ${modelName} implements IModel { 22 | private IRepositoryManager mManager; 23 | 24 | public ${modelName}(IRepositoryManager manager) { 25 | this.mManager = manager; 26 | } 27 | 28 | @Override 29 | public void onDestroy() { 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /MVPArtTemplate/root/src/app_package/ArtModel.kt.ftl: -------------------------------------------------------------------------------- 1 | package ${packageName}${modelPackageName} 2 | 3 | import me.jessyan.art.mvp.IModel 4 | import me.jessyan.art.mvp.IRepositoryManager 5 | 6 | /** 7 | * ================================================ 8 | * 必须实现 IModel 9 | * 可以根据不同的业务逻辑划分多个 Repository 类, 多个业务逻辑相近的页面可以使用同一个 Repository 类 10 | * 无需每个页面都创建一个独立的 Repository 11 | * 通过 {@link me.jessyan.art.mvp.IRepositoryManager#createRepository(java.lang.Class)} 获得的 Repository 实例, 为单例对象 12 | *
13 | * Created by MVPArtTemplate on ${.now?string["MM/dd/yyyy HH:mm"]}
14 | * Contact me
15 | * Follow me
16 | * Star me
17 | * See me
18 | * 模版请保持更新
19 | * ================================================
20 | */
21 | class ${modelName}(manager:IRepositoryManager) : IModel {
22 |
23 | override fun onDestroy() {
24 |
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/MVPArtTemplate/root/src/app_package/ArtPresenter.java.ftl:
--------------------------------------------------------------------------------
1 | package ${packageName}${presenterPackageName};
2 |
3 | import me.jessyan.art.di.component.AppComponent;
4 | import me.jessyan.art.mvp.BasePresenter;
5 | import me.jessyan.rxerrorhandler.core.RxErrorHandler;
6 |
7 | <#if modelName?has_content>
8 | import ${packageName}${modelPackageName}.${modelName};
9 | #if>
10 |
11 | <#import "root://activities/MVPArtTemplate/globals.xml.ftl" as gb>
12 |
13 | <@gb.fileHeader />
14 | public class ${presenterName} extends BasePresenter <#if modelName?has_content><${modelName}>#if> {
15 | private RxErrorHandler mErrorHandler;
16 |
17 | public ${presenterName}(AppComponent appComponent) {
18 | <#if modelName?has_content>super(appComponent.repositoryManager().createRepository(${modelName}.class))<#else>super()#if>;
19 | this.mErrorHandler = appComponent.rxErrorHandler();
20 | }
21 |
22 | @Override
23 | public void onDestroy() {
24 | super.onDestroy();
25 | this.mErrorHandler = null;
26 | }
27 | }
--------------------------------------------------------------------------------
/MVPArtTemplate/root/src/app_package/ArtPresenter.kt.ftl:
--------------------------------------------------------------------------------
1 | package ${packageName}${presenterPackageName}
2 |
3 | import me.jessyan.art.di.component.AppComponent
4 | import me.jessyan.art.mvp.BasePresenter
5 | import me.jessyan.rxerrorhandler.core.RxErrorHandler
6 |
7 | <#if modelName?has_content>
8 | import ${packageName}${modelPackageName}.${modelName}
9 | #if>
10 |
11 | <#import "root://activities/MVPArtTemplate/globals.xml.ftl" as gb>
12 |
13 | <@gb.fileHeader />
14 | class ${presenterName}(appComponent:AppComponent) :
15 | BasePresenter <#if modelName?has_content><${modelName}>#if>(<#if modelName?has_content>appComponent.repositoryManager().createRepository(${modelName}::class.java)<#else>#if>) {
16 | private val mErrorHandler by lazy{
17 | appComponent.rxErrorHandler()
18 | }
19 |
20 | override fun onDestroy() {
21 | super.onDestroy()
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/MVPArtTemplate/template.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
35 |
36 | * 原则上在任何包下都可以点击上面的按钮生成文件, 您在哪个包下点击生成文件, **Root Package Name** 的值就是哪个包, 下面的 **Activity Package Name**, **Presenter Package Name** 的默认值 (根据 **MVPArms Demo** 的包结构) 都是根据这个 **Root Package Name** 联动的, 如上图, 以我 **MVPArms Demo** 的包结构, **Presenter** 应该是放在 **.mvp.presenter** 下的, 但是现在 **Presenter Package Name** 的值却显示的是 **.app.mvp.presenter**, 明显和预期的输出包名不一致, 所以您最好在您的根包名下点击生成文件 (如 **me.jessyan.wideeyes**), 当然这些输出包名都是可以修改, 您不一定要使用我的默认的输出包名, 因为每个人的包结构都不一样, 所以包名可配置是刚需
37 |
38 | * 生成 **Activity** 以及 **Fragment** 前, 必须填写 **Layout Name**, 您可以自行生成布局后, 再将布局名填写到 **Activity/Fragment Layout Name**, 也可以使用本模版自动生成布局, 自动生成布局请将 **Generate Activity/Fragment Layout** 勾选上 (默认勾选), 如果您已经自行生成了布局, 不想使用自动生成布局, 那请不要勾选 (一定要注意, 因为这个是默认勾选的)
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/art/MVPArmsTemplate.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JessYanCoding/MVPArmsTemplate/3aa783edaa09b496c56adccbe08abf15f0954416/art/MVPArmsTemplate.gif
--------------------------------------------------------------------------------
/art/attention.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JessYanCoding/MVPArmsTemplate/3aa783edaa09b496c56adccbe08abf15f0954416/art/attention.png
--------------------------------------------------------------------------------
/art/step.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JessYanCoding/MVPArmsTemplate/3aa783edaa09b496c56adccbe08abf15f0954416/art/step.png
--------------------------------------------------------------------------------