├── 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 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /MVPArmsTemplate/globals.xml.ftl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | <#include "../common/common_globals.xml.ftl" /> 11 | 12 | 13 | <#macro fileHeader> 14 | /** 15 | * ================================================ 16 | * Description: 17 | *

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 | -------------------------------------------------------------------------------- /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 | 5 | <@kt.addAllKotlinDependencies /> 6 | <@dagger2.addAllKaptDependencies /> 7 | <#if needActivity> 8 | 10 | 11 | 12 | <#if needActivity && generateActivityLayout> 13 | 15 | 16 | 17 | <#if needFragment && generateFragmentLayout> 18 | 20 | 21 | 22 | 23 | <#if needActivity> 24 | 26 | 27 | 28 | 29 | <#if needFragment> 30 | 32 | 33 | 34 | 35 | <#if needContract> 36 | 38 | 39 | 40 | <#if needPresenter> 41 | 43 | 44 | 45 | 46 | <#if needModel> 47 | 49 | 50 | 51 | <#if needDagger> 52 | 54 | 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /MVPArmsTemplate/root/AndroidManifest.xml.ftl: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | <#if isNewModule> 6 | 7 | 8 | 9 | 10 | 11 | 12 | <#else> 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /MVPArmsTemplate/root/res/layout/simple.xml.ftl: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | -------------------------------------------------------------------------------- /MVPArmsTemplate/root/src/app_package/ArmsActivity.java.ftl: -------------------------------------------------------------------------------- 1 | package ${ativityPackageName}; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.support.annotation.NonNull; 6 | import android.support.annotation.Nullable; 7 | 8 | import com.jess.arms.base.BaseActivity; 9 | import com.jess.arms.di.component.AppComponent; 10 | import com.jess.arms.utils.ArmsUtils; 11 | 12 | import ${componentPackageName}.Dagger${pageName}Component; 13 | import ${contractPackageName}.${pageName}Contract; 14 | import ${presenterPackageName}.${pageName}Presenter; 15 | 16 | import ${packageName}.R; 17 | 18 | 19 | import static com.jess.arms.utils.Preconditions.checkNotNull; 20 | 21 | <#import "root://activities/MVPArmsTemplate/globals.xml.ftl" as gb> 22 | 23 | <@gb.fileHeader /> 24 | public class ${pageName}Activity extends BaseActivity<${pageName}Presenter> implements ${pageName}Contract.View { 25 | 26 | @Override 27 | public void setupActivityComponent(@NonNull AppComponent appComponent) { 28 | Dagger${pageName}Component //如找不到该类,请编译一下项目 29 | .builder() 30 | .appComponent(appComponent) 31 | .view(this) 32 | .build() 33 | .inject(this); 34 | } 35 | 36 | @Override 37 | public int initView(@Nullable Bundle savedInstanceState) { 38 | return R.layout.${activityLayoutName}; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0 39 | } 40 | 41 | @Override 42 | public void initData(@Nullable Bundle savedInstanceState) { 43 | 44 | } 45 | 46 | @Override 47 | public void showLoading() { 48 | 49 | } 50 | 51 | @Override 52 | public void hideLoading() { 53 | 54 | } 55 | 56 | @Override 57 | public void showMessage(@NonNull String message) { 58 | checkNotNull(message); 59 | ArmsUtils.snackbarText(message); 60 | } 61 | 62 | @Override 63 | public void launchActivity(@NonNull Intent intent) { 64 | checkNotNull(intent); 65 | ArmsUtils.startActivity(intent); 66 | } 67 | 68 | @Override 69 | public void killMyself() { 70 | finish(); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /MVPArmsTemplate/root/src/app_package/ArmsActivity.kt.ftl: -------------------------------------------------------------------------------- 1 | package ${ativityPackageName} 2 | 3 | import android.content.Intent 4 | import android.os.Bundle 5 | 6 | import com.jess.arms.base.BaseActivity 7 | import com.jess.arms.di.component.AppComponent 8 | import com.jess.arms.utils.ArmsUtils 9 | 10 | import ${componentPackageName}.Dagger${pageName}Component 11 | import ${moudlePackageName}.${pageName}Module 12 | import ${contractPackageName}.${pageName}Contract 13 | import ${presenterPackageName}.${pageName}Presenter 14 | 15 | import ${packageName}.R 16 | 17 | 18 | <#import "root://activities/MVPArmsTemplate/globals.xml.ftl" as gb> 19 | 20 | <@gb.fileHeader /> 21 | /** 22 | * 如果没presenter 23 | * 你可以这样写 24 | * 25 | * @ActivityScope(請注意命名空間) class NullObjectPresenterByActivity 26 | * @Inject constructor() : IPresenter { 27 | * override fun onStart() { 28 | * } 29 | * 30 | * override fun onDestroy() { 31 | * } 32 | * } 33 | */ 34 | class ${pageName}Activity : BaseActivity<${pageName}Presenter>() , ${pageName}Contract.View { 35 | 36 | override fun setupActivityComponent(appComponent:AppComponent) { 37 | Dagger${pageName}Component //如找不到该类,请编译一下项目 38 | .builder() 39 | .appComponent(appComponent) 40 | .${extractLetters(pageName[0]?lower_case)}${pageName?substring(1,pageName?length)}Module(${pageName}Module(this)) 41 | .build() 42 | .inject(this) 43 | } 44 | 45 | 46 | override fun initView(savedInstanceState:Bundle?):Int { 47 | return R.layout.${activityLayoutName} //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0 48 | } 49 | 50 | 51 | 52 | override fun initData(savedInstanceState:Bundle?) { 53 | 54 | } 55 | 56 | 57 | override fun showLoading() { 58 | 59 | } 60 | 61 | override fun hideLoading() { 62 | 63 | } 64 | 65 | override fun showMessage(message:String) { 66 | ArmsUtils.snackbarText(message) 67 | } 68 | override fun launchActivity(intent:Intent) { 69 | ArmsUtils.startActivity(intent) 70 | } 71 | 72 | override fun killMyself() { 73 | finish() 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /MVPArmsTemplate/root/src/app_package/ArmsComponent.java.ftl: -------------------------------------------------------------------------------- 1 | package ${componentPackageName}; 2 | 3 | import dagger.BindsInstance; 4 | import dagger.Component; 5 | import com.jess.arms.di.component.AppComponent; 6 | 7 | import ${moudlePackageName}.${pageName}Module; 8 | import ${contractPackageName}.${pageName}Contract; 9 | 10 | <#if needActivity && needFragment> 11 | import com.jess.arms.di.scope.ActivityScope; 12 | import ${ativityPackageName}.${pageName}Activity; 13 | import ${fragmentPackageName}.${pageName}Fragment; 14 | <#elseif needActivity> 15 | import com.jess.arms.di.scope.ActivityScope; 16 | import ${ativityPackageName}.${pageName}Activity; 17 | <#elseif needFragment> 18 | import com.jess.arms.di.scope.FragmentScope; 19 | import ${fragmentPackageName}.${pageName}Fragment; 20 | 21 | 22 | <#import "root://activities/MVPArmsTemplate/globals.xml.ftl" as gb> 23 | 24 | <@gb.fileHeader /> 25 | <#if needActivity && needFragment> 26 | @ActivityScope 27 | <#elseif needActivity> 28 | @ActivityScope 29 | <#elseif needFragment> 30 | @FragmentScope 31 | 32 | @Component(modules = ${pageName}Module.class, dependencies = AppComponent.class) 33 | public interface ${pageName}Component { 34 | <#if needActivity && needFragment> 35 | void inject(${pageName}Activity activity); 36 | void inject(${pageName}Fragment fragment); 37 | <#elseif needActivity || needFragment> 38 | void inject(<#if needFragment>${pageName}Fragment fragment<#else>${pageName}Activity activity); 39 | 40 | @Component.Builder 41 | interface Builder { 42 | @BindsInstance 43 | ${pageName}Component.Builder view(${pageName}Contract.View view); 44 | ${pageName}Component.Builder appComponent(AppComponent appComponent); 45 | ${pageName}Component build(); 46 | } 47 | } -------------------------------------------------------------------------------- /MVPArmsTemplate/root/src/app_package/ArmsComponent.kt.ftl: -------------------------------------------------------------------------------- 1 | package ${componentPackageName} 2 | 3 | import dagger.Component 4 | import com.jess.arms.di.component.AppComponent 5 | 6 | import ${moudlePackageName}.${pageName}Module 7 | 8 | <#if needActivity && needFragment> 9 | import com.jess.arms.di.scope.ActivityScope 10 | import ${ativityPackageName}.${pageName}Activity 11 | import ${fragmentPackageName}.${pageName}Fragment 12 | <#elseif needActivity> 13 | import com.jess.arms.di.scope.ActivityScope 14 | import ${ativityPackageName}.${pageName}Activity 15 | <#elseif needFragment> 16 | import com.jess.arms.di.scope.FragmentScope 17 | import ${fragmentPackageName}.${pageName}Fragment 18 | 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 | 30 | @Component(modules = arrayOf(${pageName}Module::class),dependencies = arrayOf(AppComponent::class)) 31 | interface ${pageName}Component { 32 | <#if needActivity && needFragment> 33 | fun inject(activity:${pageName}Activity) 34 | fun inject(fragment:${pageName}Fragment) 35 | <#elseif needActivity || needFragment> 36 | fun inject(<#if needFragment>fragment:${pageName}Fragment<#else>activity:${pageName}Activity) 37 | 38 | } 39 | -------------------------------------------------------------------------------- /MVPArmsTemplate/root/src/app_package/ArmsContract.java.ftl: -------------------------------------------------------------------------------- 1 | package ${contractPackageName}; 2 | 3 | import com.jess.arms.mvp.IView; 4 | import com.jess.arms.mvp.IModel; 5 | 6 | <#import "root://activities/MVPArmsTemplate/globals.xml.ftl" as gb> 7 | 8 | <@gb.fileHeader /> 9 | public interface ${pageName}Contract { 10 | //对于经常使用的关于UI的方法可以定义到IView中,如显示隐藏进度条,和显示文字消息 11 | interface View extends IView { 12 | 13 | } 14 | //Model层定义接口,外部只需关心Model返回的数据,无需关心内部细节,即是否使用缓存 15 | interface Model extends IModel{ 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /MVPArmsTemplate/root/src/app_package/ArmsContract.kt.ftl: -------------------------------------------------------------------------------- 1 | package ${contractPackageName} 2 | 3 | import com.jess.arms.mvp.IView 4 | import com.jess.arms.mvp.IModel 5 | 6 | <#import "root://activities/MVPArmsTemplate/globals.xml.ftl" as gb> 7 | 8 | <@gb.fileHeader /> 9 | interface ${pageName}Contract { 10 | //对于经常使用的关于UI的方法可以定义到IView中,如显示隐藏进度条,和显示文字消息 11 | interface View : IView 12 | 13 | //Model层定义接口,外部只需关心Model返回的数据,无需关心内部细节,即是否使用缓存 14 | interface Model : IModel 15 | 16 | } 17 | -------------------------------------------------------------------------------- /MVPArmsTemplate/root/src/app_package/ArmsFragment.java.ftl: -------------------------------------------------------------------------------- 1 | package ${fragmentPackageName}; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.os.Message; 6 | import android.support.annotation.NonNull; 7 | import android.support.annotation.Nullable; 8 | import android.support.v4.app.Fragment; 9 | import android.view.LayoutInflater; 10 | import android.view.View; 11 | import android.view.ViewGroup; 12 | 13 | import com.jess.arms.base.BaseFragment; 14 | import com.jess.arms.di.component.AppComponent; 15 | import com.jess.arms.utils.ArmsUtils; 16 | 17 | import ${componentPackageName}.Dagger${pageName}Component; 18 | import ${contractPackageName}.${pageName}Contract; 19 | import ${presenterPackageName}.${pageName}Presenter; 20 | 21 | import ${packageName}.R; 22 | 23 | import static com.jess.arms.utils.Preconditions.checkNotNull; 24 | 25 | <#import "root://activities/MVPArmsTemplate/globals.xml.ftl" as gb> 26 | 27 | <@gb.fileHeader /> 28 | public class ${pageName}Fragment extends BaseFragment<${pageName}Presenter> implements ${pageName}Contract.View{ 29 | 30 | public static ${pageName}Fragment newInstance() { 31 | ${pageName}Fragment fragment = new ${pageName}Fragment(); 32 | return fragment; 33 | } 34 | 35 | @Override 36 | public void setupFragmentComponent(@NonNull AppComponent appComponent) { 37 | Dagger${pageName}Component //如找不到该类,请编译一下项目 38 | .builder() 39 | .appComponent(appComponent) 40 | .view(this) 41 | .build() 42 | .inject(this); 43 | } 44 | 45 | @Override 46 | public View initView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 47 | return inflater.inflate(R.layout.${fragmentLayoutName}, container, false); 48 | } 49 | 50 | @Override 51 | public void initData(@Nullable Bundle savedInstanceState) { 52 | 53 | } 54 | 55 | /** 56 | * 通过此方法可以使 Fragment 能够与外界做一些交互和通信, 比如说外部的 Activity 想让自己持有的某个 Fragment 对象执行一些方法, 57 | * 建议在有多个需要与外界交互的方法时, 统一传 {@link Message}, 通过 what 字段来区分不同的方法, 在 {@link #setData(Object)} 58 | * 方法中就可以 {@code switch} 做不同的操作, 这样就可以用统一的入口方法做多个不同的操作, 可以起到分发的作用 59 | *

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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 212 | -------------------------------------------------------------------------------- /MVPArmsTemplate/template_blank_activity.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JessYanCoding/MVPArmsTemplate/3aa783edaa09b496c56adccbe08abf15f0954416/MVPArmsTemplate/template_blank_activity.png -------------------------------------------------------------------------------- /MVPArtTemplate/dagger2.gradle.ftl: -------------------------------------------------------------------------------- 1 | dependencies { 2 | kapt rootProject.ext.dependencies["dagger2-compiler"] 3 | } -------------------------------------------------------------------------------- /MVPArtTemplate/dagger2_macros.ftl: -------------------------------------------------------------------------------- 1 | <#macro addAllKaptDependencies> 2 | <#if !isNewModule && ((language!'Java')?string == 'Kotlin')> 3 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /MVPArtTemplate/globals.xml.ftl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | <#include "../common/common_globals.xml.ftl" /> 11 | 12 | 13 | <#macro fileHeader> 14 | /** 15 | * ================================================ 16 | * Description: 17 | *

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 | -------------------------------------------------------------------------------- /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 | 5 | <@kt.addAllKotlinDependencies /> 6 | <@dagger2.addAllKaptDependencies /> 7 | <#if needActivity> 8 | 10 | 11 | 12 | <#if needActivity && generateActivityLayout> 13 | 15 | 16 | 17 | <#if needFragment && generateFragmentLayout> 18 | 20 | 21 | 22 | 23 | <#if needActivity> 24 | 26 | 27 | 28 | 29 | <#if needFragment> 30 | 32 | 33 | 34 | 35 | <#if needPresenter && presenterName?has_content> 36 | 38 | 39 | 40 | 41 | <#if needModel && modelName?has_content> 42 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /MVPArtTemplate/root/AndroidManifest.xml.ftl: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | <#if isNewModule> 6 | 7 | 8 | 9 | 10 | 11 | 12 | <#else> 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /MVPArtTemplate/root/res/layout/simple.xml.ftl: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | -------------------------------------------------------------------------------- /MVPArtTemplate/root/src/app_package/ArtActivity.java.ftl: -------------------------------------------------------------------------------- 1 | package ${packageName}${ativityPackageName}; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.NonNull; 5 | import android.support.annotation.Nullable; 6 | 7 | import me.jessyan.art.base.BaseActivity; 8 | import me.jessyan.art.mvp.IView; 9 | import me.jessyan.art.mvp.Message; 10 | import me.jessyan.art.utils.ArtUtils; 11 | 12 | import static me.jessyan.art.utils.Preconditions.checkNotNull; 13 | 14 | <#if presenterName?has_content> 15 | import ${packageName}${presenterPackageName}.${presenterName}; 16 | 17 | 18 | import ${packageName}.R; 19 | 20 | <#import "root://activities/MVPArtTemplate/globals.xml.ftl" as gb> 21 | 22 | <@gb.fileHeader /> 23 | public class ${pageName}Activity extends BaseActivity <#if presenterName?has_content><${presenterName}> implements IView { 24 | 25 | @Override 26 | public int initView(@Nullable Bundle savedInstanceState) { 27 | return R.layout.${activityLayoutName}; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0 28 | } 29 | 30 | @Override 31 | public void initData(@Nullable Bundle savedInstanceState) { 32 | 33 | } 34 | 35 | @Override 36 | @Nullable 37 | public <#if presenterName?has_content>${presenterName}<#else>IPresenter obtainPresenter() { 38 | return <#if presenterName?has_content> new ${presenterName}(ArtUtils.obtainAppComponentFromContext(this))<#else> null; 39 | } 40 | 41 | @Override 42 | public void showLoading() { 43 | 44 | } 45 | 46 | @Override 47 | public void hideLoading() { 48 | 49 | } 50 | 51 | @Override 52 | public void showMessage(@NonNull String message) { 53 | checkNotNull(message); 54 | ArtUtils.snackbarText(message); 55 | } 56 | 57 | @Override 58 | public void handleMessage(@NonNull Message message) { 59 | checkNotNull(message); 60 | switch (message.what) { 61 | case 0: 62 | break; 63 | case 1: 64 | break; 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /MVPArtTemplate/root/src/app_package/ArtActivity.kt.ftl: -------------------------------------------------------------------------------- 1 | package ${packageName}${ativityPackageName} 2 | 3 | import android.os.Bundle 4 | 5 | import me.jessyan.art.base.BaseActivity 6 | import me.jessyan.art.mvp.IView 7 | import me.jessyan.art.mvp.Message 8 | import me.jessyan.art.utils.ArtUtils 9 | 10 | 11 | <#if presenterName?has_content> 12 | import ${packageName}${presenterPackageName}.${presenterName}; 13 | 14 | 15 | import ${packageName}.R; 16 | 17 | <#import "root://activities/MVPArtTemplate/globals.xml.ftl" as gb> 18 | 19 | <@gb.fileHeader /> 20 | class ${pageName}Activity : BaseActivity <#if presenterName?has_content><${presenterName}>() , IView { 21 | 22 | override fun initView(savedInstanceState:Bundle?):Int { 23 | return R.layout.${activityLayoutName} //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0 24 | } 25 | 26 | 27 | override fun initData(savedInstanceState:Bundle?) { 28 | 29 | } 30 | 31 | override fun obtainPresenter():<#if presenterName?has_content>${presenterName}<#else>IPresenter? { 32 | return <#if presenterName?has_content> ${presenterName}(ArtUtils.obtainAppComponentFromContext(this))<#else> null; 33 | } 34 | 35 | override fun showLoading() { 36 | 37 | } 38 | 39 | override fun hideLoading() { 40 | 41 | } 42 | 43 | override fun showMessage(message:String) { 44 | ArtUtils.snackbarText(message) 45 | } 46 | 47 | override fun handleMessage(message:Message) { 48 | when (message.what) { 49 | 0 -> { 50 | //根据what 做你想做的事情 51 | } 52 | else -> { 53 | } 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /MVPArtTemplate/root/src/app_package/ArtFragment.java.ftl: -------------------------------------------------------------------------------- 1 | package ${packageName}${fragmentPackageName}; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.NonNull; 5 | import android.support.annotation.Nullable; 6 | import android.app.Activity; 7 | import android.support.v4.app.Fragment; 8 | import android.view.LayoutInflater; 9 | import android.view.View; 10 | import android.view.ViewGroup; 11 | 12 | import me.jessyan.art.base.BaseFragment; 13 | import me.jessyan.art.base.delegate.IFragment; 14 | import me.jessyan.art.mvp.IView; 15 | import me.jessyan.art.mvp.Message; 16 | import me.jessyan.art.utils.ArtUtils; 17 | 18 | import static me.jessyan.art.utils.Preconditions.checkNotNull; 19 | 20 | <#if presenterName?has_content> 21 | import ${packageName}${presenterPackageName}.${presenterName}; 22 | 23 | 24 | import ${packageName}.R; 25 | 26 | <#import "root://activities/MVPArtTemplate/globals.xml.ftl" as gb> 27 | 28 | <@gb.fileHeader /> 29 | public class ${pageName}Fragment extends BaseFragment <#if presenterName?has_content><${presenterName}> implements IView { 30 | 31 | public static ${pageName}Fragment newInstance() { 32 | ${pageName}Fragment fragment = new ${pageName}Fragment(); 33 | return fragment; 34 | } 35 | 36 | @Override 37 | public View initView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 38 | return inflater.inflate(R.layout.${fragmentLayoutName}, container, false); 39 | } 40 | 41 | @Override 42 | public void initData(@Nullable Bundle savedInstanceState) { 43 | 44 | } 45 | 46 | @Override 47 | @Nullable 48 | public <#if presenterName?has_content>${presenterName}<#else>IPresenter obtainPresenter() { 49 | return <#if presenterName?has_content> new ${presenterName}(ArtUtils.obtainAppComponentFromContext(getActivity()))<#else> null; 50 | } 51 | 52 | /** 53 | * 通过此方法可以使 Fragment 能够与外界做一些交互和通信, 比如说外部的 Activity 想让自己持有的某个 Fragment 对象执行一些方法, 54 | * 建议在有多个需要与外界交互的方法时, 统一传 {@link Message}, 通过 what 字段来区分不同的方法, 在 {@link #setData(Object)} 55 | * 方法中就可以 {@code switch} 做不同的操作, 这样就可以用统一的入口方法做多个不同的操作, 可以起到分发的作用 56 | *

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 | 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}>() , 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? { 44 | return <#if presenterName?has_content> ${presenterName}(ArtUtils.obtainAppComponentFromContext(activity))<#else> null; 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 | 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}> { 15 | private RxErrorHandler mErrorHandler; 16 | 17 | public ${presenterName}(AppComponent appComponent) { 18 | <#if modelName?has_content>super(appComponent.repositoryManager().createRepository(${modelName}.class))<#else>super(); 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 | 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 modelName?has_content>appComponent.repositoryManager().createRepository(${modelName}::class.java)<#else>) { 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 | 189 | -------------------------------------------------------------------------------- /MVPArtTemplate/template_blank_activity.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JessYanCoding/MVPArmsTemplate/3aa783edaa09b496c56adccbe08abf15f0954416/MVPArtTemplate/template_blank_activity.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![Logo](https://raw.githubusercontent.com/JessYanCoding/MVPArms/master/image/arms_banner_v1.0.jpg) 2 | ![gif](art/MVPArmsTemplate.gif) 3 | 4 | # 4.0 + AndroidStudio 已不可用该模板,只能使用自制插件的方式引入模板,请参考[这里](https://github.com/JessYanCoding/MVPArms/issues/387) 5 | 6 | **A template for Android Studio to create [MVPArms](https://github.com/JessYanCoding/MVPArms) and [MVPArt](https://github.com/JessYanCoding/MVPArt) Page** 7 | 8 | **MVPArmsTemplate** 和 **MVPArtTemplate** 是 [**JessYan**](https://github.com/JessYanCoding) 为强大的 [**MVPArms**](https://github.com/JessYanCoding/MVPArms) 以及 [**MVPArt**](https://github.com/JessYanCoding/MVPArt) 打造的一系列高度可配置且炒鸡炫酷的插件式模版, 可以为每个业务页面一键自动生成 **File**、**Xml**, 还可以自定义配置文件名、布局名和用于文件生成的目标包路径, 并且每一个文件都可以控制生成与否, 如果想一键搭建 **MVPArms** 的官方架构, 请使用 [**MVPArms** 的 **Module** 级模板](https://github.com/JessYanCoding/MVPArms-Module-Template) 9 | 10 | > **Tips: 若您基于本模板修改并且开源于网络, 请注明出处, 尊重开源, 才有人愿意开源, 谢谢!** 11 | 12 | 此模板会持续保持更新新的内容并同步兼容最新的 **AndroidStudio 稳定版**, 如果最新的模板代码不能兼容您的 **AndroidStudio 旧版本**, 请自行升级 **AndroidStudio** 到最新的稳定版, 或者自行回滚模板代码 (有些版本在可以在 [releases](https://github.com/JessYanCoding/MVPArmsTemplate/releases) 中找到) 到能兼容旧版本的代码 (因为模板也是和 **AndroidStudio** 的版本同步更新的, 但也可能模板第一次提交兼容的版本都高于您的 **AndroidStudio** 旧版本), 此模板由于会随时更新新的内容, 所以不可能为每个 **AndroidStudio** 版本都维护一个分支, 这将极大的增加我的工作量, 所以在受益于模板带来的便利的同时, 也请尊重我的决定, 请不要提关于 **AndroidStudio 旧版本** 不兼容的 **Issues**, 谢谢 13 | 14 | ## 如何安装? 15 | 16 | 请将 **MVPArmsTemplate** (如果使用的是 **MVPArt** 请复制 **MVPArtTemplate** 文件夹) 这个文件夹复制到 **AndroidStudio Activity** 模版的存放路径(其他模版同理), 请注意是复制整个文件夹, 不是里面的内容! 17 | 18 | **AndroidStudio Activity** 模版存放路径 (**请注意是放在 activities 文件夹里, 不是 gradle-projects 文件夹!!!**): 19 | 20 | * Windows : AS安装目录/plugins/android/lib/templates/activities 21 | 22 | * Mac : /Applications/Android Studio.app/Contents/plugins/android/lib/templates/activities 23 | 24 | **最后记得重启 AndroidStudio !** 25 | 26 | ## 如何使用? 27 | 28 | 一图胜千言, 两个红色的选项都可以打开模板, 至于快捷键自己百度, **Mac** 是 **Command + n** 29 | 30 | ![step](art/step.png) 31 | 32 | ## 注意事项 33 | 34 | 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 --------------------------------------------------------------------------------