├── .gitignore ├── README.md ├── build.gradle ├── demo ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── example │ │ └── zane │ │ └── demo │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── zane │ │ │ └── demo │ │ │ ├── App.java │ │ │ ├── BaseActivity.java │ │ │ ├── Bean │ │ │ ├── Data_One.java │ │ │ ├── Data_Two.java │ │ │ └── RecycleviewData.java │ │ │ ├── Constant.java │ │ │ ├── presenter │ │ │ ├── MainActivity.java │ │ │ ├── MainActivity2.java │ │ │ └── MyRecycleviewAdapter.java │ │ │ └── view │ │ │ ├── DataOneViewHolder.java │ │ │ ├── DataTwoViewHolder.java │ │ │ ├── MainListView.java │ │ │ └── MainView2.java │ └── res │ │ ├── layout │ │ ├── activity_2.xml │ │ ├── activity_main.xml │ │ └── listview_item_layout.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── example │ └── zane │ └── demo │ └── ExampleUnitTest.java ├── easymvp ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── example │ │ └── zane │ │ └── easymvp │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── zane │ │ │ └── easymvp │ │ │ ├── base │ │ │ ├── IListModel.java │ │ │ ├── IPersenter.java │ │ │ └── IView.java │ │ │ ├── presenter │ │ │ ├── BaseActivityPresenter.java │ │ │ ├── BaseFragmentPresenter.java │ │ │ └── BaseListAdapterPresenter.java │ │ │ └── view │ │ │ ├── BaseListViewHolderImpl.java │ │ │ └── BaseViewImpl.java │ └── res │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ └── values │ │ └── strings.xml │ └── test │ └── java │ └── com │ └── example │ └── zane │ └── easymvp │ └── ExampleUnitTest.java ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by https://www.gitignore.io/api/android 2 | 3 | ### Android ### 4 | # Built application files 5 | *.apk 6 | *.ap_ 7 | 8 | # Files for the Dalvik VM 9 | *.dex 10 | 11 | # Java class files 12 | *.class 13 | 14 | # Generated files 15 | bin/ 16 | gen/ 17 | out/ 18 | 19 | # Gradle files 20 | .gradle/ 21 | build/ 22 | 23 | # Local configuration file (sdk path, etc) 24 | local.properties 25 | 26 | # Proguard folder generated by Eclipse 27 | proguard/ 28 | 29 | # Log Files 30 | *.log 31 | 32 | # Android Studio Navigation editor temp files 33 | .navigation/ 34 | 35 | # Android Studio captures folder 36 | captures/ 37 | 38 | # Intellij 39 | *.iml 40 | .idea 41 | 42 | # Keystore files 43 | *.jks 44 | 45 | ### Android Patch ### 46 | gen-external-apklibs 47 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # EasyMVP 2 | 在安卓上运用的MVP模式开发框架。A framework for MVP pattern in android. 3 | 4 | 与传统MVP开发模式相反,EasyMVP是将activity,fragment, adapter作为presenter的mvp开发框架。 5 | 6 | ## 了解更多 7 | + 可以看看这篇文章对这种模式的理解:[《MVP模式的一种新的尝试》](https://github.com/bboyfeiyu/android-tech-frontier/tree/master/androidweekly/%E4%B8%80%E7%A7%8D%E5%9C%A8android%E4%B8%AD%E5%AE%9E%E7%8E%B0MVP%E6%A8%A1%E5%BC%8F%E7%9A%84%E6%96%B0%E6%80%9D%E8%B7%AF) 8 | + 以及框架的具体介绍文章:[《MVP开发框架的第一次尝试》](http://zane96.github.io/2016/01/28/MVP%E5%BC%80%E5%8F%91%E6%A1%86%E6%9E%B6%E7%9A%84%E4%B8%80%E6%AC%A1%E5%B0%9D%E8%AF%95%E2%80%94%E2%80%94EasyMVP/) 9 | 10 | ## 重复依赖 11 | **butterknife** 12 | 13 | ## 添加依赖: 14 | gradle: 15 | **Add it in your root build.gradle at the end of repositories:** 16 | ``` 17 | allprojects { 18 | repositories { 19 | ... 20 | maven { url "https://jitpack.io" } 21 | } 22 | } 23 | ``` 24 | **Add the dependency:** 25 | ``` 26 | dependencies { 27 | compile 'com.github.Zane96:EasyMVP:v1.3.9' 28 | } 29 | ``` 30 | 31 | ###使用: 32 | **View**: 33 | ``` 34 | public class MainListView extends BaseViewImpl 35 | ``` 36 | **Presenter** 37 | ``` 38 | public class MainActivity extends BaseActivityPresenter 39 | ``` 40 | **ViewHolder** 41 | ``` 42 | public class MainListViewHolder extends BaseListViewHolderImpl 43 | ``` 44 | **Adapter** 45 | ``` 46 | public class MyRecycleviewAdapter extends BaseListAdapterPresenter 47 | ``` 48 | **Model** 49 | ``` 50 | public class RecycleviewData implements IListModel 51 | ``` 52 | 53 | ## BaseListAdapterPresenter和BaseListViewHolderImpl的介绍 54 | viewHolder与Adapter解耦的部分请看上述博客。将viewHolder于adapter分离,viewholder去管理item的view,给adapter瘦身。 55 | **更新介绍**: 56 | + 数据对象的集合全部在base类中进行管理,所有的数据操作都已经在BaseAdapterPresenter里面定义好了。开发者只需要在适配器里面调用继承过来的mDatas对象就可以操作数据了。具体可以看源码。 57 | + 解决特殊情况下一个recycleview需要展示不同数据源数据(多个model)的情况。例如一个recycleview的前5个item要展示Model A的数据,后5个item要展示Model B的数据。这样开发者需要写一个公共ModelC类,并且持有A,B的对象。并且这个C类实现框架IListModel接口,实现getViewType()(根据父类里面的之类实例对象是否为空来返回相应的type)方法。因为C类是适配器的类泛型,所以在getItemViewType方法里面去调用C里面的getViewType方法。但是以后可能会把这项工作放到框架总去做,因为现在没有太多的考虑head和foot的问题。A,B类是要继承C类,并且在将C类的数据集合生成的时候,必须要用相应的子类对象作为父类引用的指向对象,不然在viewHolder里面父类强转子类对象会报错哦(java基础)。具体实现请看demo中的代码。 58 | + 开发者不用再去adapter里面定义item的点击事件的接口回调,世界在代码里面**setOnRecycleViewItemClickListener()**就可以了。 59 | 60 | ## 版本更新介绍: 61 | + v1.3.9:直接向V层注入IPresenter 62 | + v1.3.7:修复了适配器中设置head,foot,itemcount出错的bug 63 | + v1.3.5:添加了view中的onPresenterDestory()方法,这个方法用于view与presenter的onDestory()方法同步。作用就是可以当presenter销毁的时候,在view中做相应的销毁操作。比如EventBus的unRegister,可以避免不必要的内存泄漏。 64 | + v1.3.1:主要修改在**BaseListAdapter**中: 65 | 1. 开发者需要在adapter里面实现setHeadNum()和setFootNum()方法来告诉框架你添加的headhe foot的数量。 66 | 2. 主要的数据源均在框架里面进行管理,开发者直接调用框架中的对集合操作的方法去操作mDatas变量。开发者当然也可以自定义数据变量。 67 | + v.1.3.0:强制使activity拥有提供context到view中的函数。因为有时候view的使用必须用到activity类型的context。提供的过程由框架内部完成,开发者只需要get,set就行。比如启动activity,启动Toast都可以在view中实现,解决java类作为View的一个很麻烦的问题。 68 | 69 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:2.2.3' 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | jcenter() 18 | maven { url "https://jitpack.io" } 19 | } 20 | } 21 | 22 | task clean(type: Delete) { 23 | delete rootProject.buildDir 24 | } 25 | -------------------------------------------------------------------------------- /demo/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /demo/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.2" 6 | 7 | defaultConfig { 8 | applicationId "com.example.zane.demo" 9 | minSdkVersion 15 10 | targetSdkVersion 23 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | 21 | allprojects { 22 | repositories { 23 | maven { url "https://jitpack.io" } 24 | } 25 | } 26 | } 27 | 28 | dependencies { 29 | compile fileTree(include: ['*.jar'], dir: 'libs') 30 | testCompile 'junit:junit:4.12' 31 | compile 'com.android.support:appcompat-v7:23.1.1' 32 | compile 'com.android.support:recyclerview-v7:23.1.1' 33 | 34 | compile project(':easymvp') 35 | } 36 | 37 | -------------------------------------------------------------------------------- /demo/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/Zane/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /demo/src/androidTest/java/com/example/zane/demo/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.example.zane.demo; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /demo/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /demo/src/main/java/com/example/zane/demo/App.java: -------------------------------------------------------------------------------- 1 | package com.example.zane.demo; 2 | 3 | import android.app.Application; 4 | 5 | /** 6 | * Created by Zane on 16/4/10. 7 | */ 8 | public class App extends Application{ 9 | 10 | private static App app; 11 | 12 | @Override 13 | public void onCreate() { 14 | super.onCreate(); 15 | app = this; 16 | } 17 | 18 | public static App getInstance(){ 19 | return app; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /demo/src/main/java/com/example/zane/demo/BaseActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.zane.demo; 2 | 3 | import android.os.Bundle; 4 | 5 | import com.example.zane.easymvp.base.IView; 6 | import com.example.zane.easymvp.presenter.BaseActivityPresenter; 7 | 8 | /** 9 | * Created by Zane on 2016/12/11. 10 | * Email: zanebot96@gmail.com 11 | * Blog: zane96.github.io 12 | */ 13 | 14 | public abstract class BaseActivity extends BaseActivityPresenter{ 15 | 16 | @Override 17 | protected void onCreate(Bundle savedInstanceState) { 18 | super.onCreate(savedInstanceState); 19 | log(); 20 | } 21 | 22 | public abstract void log(); 23 | } 24 | -------------------------------------------------------------------------------- /demo/src/main/java/com/example/zane/demo/Bean/Data_One.java: -------------------------------------------------------------------------------- 1 | package com.example.zane.demo.Bean; 2 | 3 | import com.example.zane.easymvp.base.IListModel; 4 | 5 | import java.util.Arrays; 6 | import java.util.List; 7 | 8 | /** 9 | * Created by Zane on 16/4/10. 10 | */ 11 | public class Data_One extends RecycleviewData{ 12 | 13 | private String dataOne; 14 | 15 | public Data_One(String dataOne){ 16 | this.dataOne = dataOne; 17 | } 18 | 19 | public void setDataOne(String dataOne) { 20 | this.dataOne = dataOne; 21 | } 22 | 23 | public String getDataOne(){ 24 | return dataOne; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /demo/src/main/java/com/example/zane/demo/Bean/Data_Two.java: -------------------------------------------------------------------------------- 1 | package com.example.zane.demo.Bean; 2 | 3 | import com.example.zane.easymvp.base.IListModel; 4 | 5 | import java.util.Arrays; 6 | import java.util.List; 7 | 8 | /** 9 | * Created by Zane on 16/4/10. 10 | */ 11 | public class Data_Two extends RecycleviewData{ 12 | 13 | private String dataTwo; 14 | 15 | public Data_Two(String dataTwo){ 16 | this.dataTwo = dataTwo; 17 | } 18 | 19 | public String getDataTwo() { 20 | return dataTwo; 21 | } 22 | 23 | public void setDataTwo(String dataTwo) { 24 | this.dataTwo = dataTwo; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /demo/src/main/java/com/example/zane/demo/Bean/RecycleviewData.java: -------------------------------------------------------------------------------- 1 | package com.example.zane.demo.Bean; 2 | 3 | import android.util.Log; 4 | 5 | import com.example.zane.easymvp.base.IListModel; 6 | 7 | /** 8 | * Created by Zane on 16/4/10. 9 | */ 10 | public class RecycleviewData implements IListModel{ 11 | 12 | private Data_One data_one; 13 | private Data_Two data_two; 14 | 15 | public static final int DATA_ONE = 1122; 16 | public static final int DATA_TWO = 2211; 17 | 18 | public RecycleviewData(){ 19 | } 20 | 21 | public Data_One getData_one() { 22 | return data_one; 23 | } 24 | 25 | public void setData_one(Data_One data_one) { 26 | this.data_one = data_one; 27 | } 28 | 29 | public Data_Two getData_two() { 30 | return data_two; 31 | } 32 | 33 | public void setData_two(Data_Two data_two) { 34 | this.data_two = data_two; 35 | } 36 | 37 | 38 | /** 39 | * 管理多个数据model的父类来根据model存在与否而返回不同的viewtype 40 | * @return 41 | */ 42 | @Override 43 | public int getModelViewType() { 44 | Log.i("RecycleviewData", String.valueOf(data_one)); 45 | if (data_one != null){ 46 | return DATA_ONE; 47 | }else { 48 | return DATA_TWO; 49 | } 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /demo/src/main/java/com/example/zane/demo/Constant.java: -------------------------------------------------------------------------------- 1 | package com.example.zane.demo; 2 | 3 | import com.example.zane.easymvp.view.BaseViewImpl; 4 | 5 | /** 6 | * Created by Zane on 16/4/10. 7 | */ 8 | public class Constant{ 9 | 10 | 11 | public static final String[] DataOne = {"one", "one", "one", "one", "one"}; 12 | 13 | public static final String[] DataTwo = {"two", "two", "two", "two", "two"}; 14 | 15 | } 16 | -------------------------------------------------------------------------------- /demo/src/main/java/com/example/zane/demo/presenter/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.zane.demo.presenter; 2 | 3 | import android.os.Bundle; 4 | import android.os.Handler; 5 | import android.os.Message; 6 | import android.support.v7.app.AppCompatActivity; 7 | import android.support.v7.widget.LinearLayoutManager; 8 | import android.util.Log; 9 | import android.view.View; 10 | import android.widget.Toast; 11 | 12 | import com.example.zane.demo.BaseActivity; 13 | import com.example.zane.demo.Bean.Data_One; 14 | import com.example.zane.demo.Bean.Data_Two; 15 | import com.example.zane.demo.Bean.RecycleviewData; 16 | import com.example.zane.demo.Constant; 17 | import com.example.zane.demo.view.MainListView; 18 | import com.example.zane.easymvp.base.IPersenter; 19 | import com.example.zane.easymvp.base.IView; 20 | import com.example.zane.easymvp.presenter.BaseActivityPresenter; 21 | import com.example.zane.easymvp.presenter.BaseListAdapterPresenter; 22 | 23 | import java.lang.ref.WeakReference; 24 | import java.util.ArrayList; 25 | import java.util.List; 26 | 27 | public class MainActivity extends BaseActivity { 28 | 29 | private LinearLayoutManager linearLayoutManager; 30 | private MyRecycleviewAdapter adapter; 31 | private List datas = new ArrayList<>(); 32 | private MyHandler handler; 33 | private static final String TAG = "MainActivity_demo"; 34 | 35 | @Override 36 | public Class getRootViewClass() { 37 | return MainListView.class; 38 | } 39 | 40 | @Override 41 | public void inCreat(Bundle bundle) { 42 | 43 | v.showProgress(); 44 | handler = new MyHandler(this); 45 | Message message = new Message(); 46 | message.what = 1; 47 | handler.sendMessageDelayed(message, 4000); 48 | 49 | for (int i = 0; i < Constant.DataOne.length; i++) { 50 | //先向上转型,再向下转型为Data_One类型的对象。 51 | RecycleviewData recycleviewData = new Data_One(Constant.DataOne[i]); 52 | recycleviewData.setData_one((Data_One) recycleviewData); 53 | datas.add(recycleviewData); 54 | } 55 | 56 | for (int j = 0; j < Constant.DataTwo.length; j++) { 57 | RecycleviewData recycleviewData = new Data_Two(Constant.DataTwo[j]); 58 | recycleviewData.setData_two((Data_Two) recycleviewData); 59 | datas.add(recycleviewData); 60 | } 61 | 62 | linearLayoutManager = new LinearLayoutManager(this); 63 | adapter = new MyRecycleviewAdapter(this, datas); 64 | v.initRecycleview(linearLayoutManager, adapter); 65 | 66 | adapter.setOnRecycleViewItemClickListener(new BaseListAdapterPresenter.OnRecycleViewItemClickListener() { 67 | @Override 68 | public void onClick(View view, int position) { 69 | Toast.makeText(MainActivity.this, "点击!", Toast.LENGTH_SHORT).show(); 70 | } 71 | 72 | @Override 73 | public void onLongClick(View view, int position) { 74 | Toast.makeText(MainActivity.this, "长按!", Toast.LENGTH_SHORT).show(); 75 | } 76 | }); 77 | 78 | Toast.makeText(this, adapter.getItemCount()+"", Toast.LENGTH_SHORT).show(); 79 | 80 | } 81 | 82 | @Override 83 | public void inDestory() { 84 | handler.removeMessages(1); 85 | } 86 | 87 | @Override 88 | public IPersenter getPersenter() { 89 | return this; 90 | } 91 | 92 | @Override 93 | public void log() { 94 | Log.i("main2", "sssss"); 95 | } 96 | 97 | private static final class MyHandler extends Handler{ 98 | WeakReference reference; 99 | public MyHandler(MainActivity activity){ 100 | reference = new WeakReference<>(activity); 101 | } 102 | 103 | @Override 104 | public void handleMessage(Message msg) { 105 | if (reference.get() != null){ 106 | super.handleMessage(msg); 107 | switch (msg.what){ 108 | case 1: 109 | reference.get().v.hideProgress(); 110 | } 111 | } 112 | } 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /demo/src/main/java/com/example/zane/demo/presenter/MainActivity2.java: -------------------------------------------------------------------------------- 1 | package com.example.zane.demo.presenter; 2 | 3 | import android.app.Activity; 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | import android.support.v7.app.AppCompatActivity; 7 | import android.view.View; 8 | 9 | import com.example.zane.demo.R; 10 | import com.example.zane.demo.view.MainView2; 11 | import com.example.zane.easymvp.base.IPersenter; 12 | import com.example.zane.easymvp.presenter.BaseActivityPresenter; 13 | 14 | /** 15 | * Created by Zane on 16/1/27. 16 | */ 17 | public class MainActivity2 extends BaseActivityPresenter{ 18 | 19 | @Override 20 | public Class getRootViewClass() { 21 | return MainView2.class; 22 | } 23 | 24 | @Override 25 | public void inCreat(Bundle bundle) { 26 | 27 | v.setOnClickListener(new View.OnClickListener() { 28 | @Override 29 | public void onClick(View v) { 30 | startActivity(new Intent(MainActivity2.this, MainActivity.class)); 31 | } 32 | }, R.id.button); 33 | 34 | v.ClickButtonShowToast(); 35 | } 36 | 37 | @Override 38 | public void inDestory() { 39 | 40 | } 41 | 42 | @Override 43 | public IPersenter getPersenter() { 44 | return this; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /demo/src/main/java/com/example/zane/demo/presenter/MyRecycleviewAdapter.java: -------------------------------------------------------------------------------- 1 | package com.example.zane.demo.presenter; 2 | 3 | import android.content.Context; 4 | import android.view.ViewGroup; 5 | 6 | import com.example.zane.demo.Bean.RecycleviewData; 7 | import com.example.zane.demo.R; 8 | import com.example.zane.demo.view.DataOneViewHolder; 9 | import com.example.zane.demo.view.DataTwoViewHolder; 10 | import com.example.zane.easymvp.presenter.BaseListAdapterPresenter; 11 | import com.example.zane.easymvp.view.BaseListViewHolderImpl; 12 | 13 | import java.util.List; 14 | 15 | /** 16 | * Created by Zane on 15/12/20. 17 | */ 18 | public class MyRecycleviewAdapter extends BaseListAdapterPresenter{ 19 | 20 | public MyRecycleviewAdapter(Context mContext, List datas){ 21 | super(mContext, datas); 22 | } 23 | 24 | @Override 25 | public int getItemViewType(int position) { 26 | if (mDatas.get(position).getModelViewType() == RecycleviewData.DATA_ONE){ 27 | return RecycleviewData.DATA_ONE; 28 | } else { 29 | return RecycleviewData.DATA_TWO; 30 | } 31 | } 32 | 33 | @Override 34 | public BaseListViewHolderImpl OnCreatViewHolder(ViewGroup parent, int viewType) { 35 | switch (viewType){ 36 | case RecycleviewData.DATA_ONE: 37 | return new DataOneViewHolder(parent, R.layout.listview_item_layout); 38 | case RecycleviewData.DATA_TWO: 39 | return new DataTwoViewHolder(parent, R.layout.listview_item_layout); 40 | default: 41 | throw new IllegalArgumentException("没有匹配的ViewHolder!"); 42 | } 43 | 44 | } 45 | 46 | @Override 47 | public void OnBindViewHloder(BaseListViewHolderImpl holder, int position) { 48 | 49 | holder.setData(mDatas.get(position)); 50 | 51 | } 52 | 53 | //没有头 54 | @Override 55 | public int setHeadNum() { 56 | return 0; 57 | } 58 | 59 | //没有尾 60 | @Override 61 | public int setFootNum() { 62 | return 0; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /demo/src/main/java/com/example/zane/demo/view/DataOneViewHolder.java: -------------------------------------------------------------------------------- 1 | package com.example.zane.demo.view; 2 | 3 | import android.support.annotation.LayoutRes; 4 | import android.view.ViewGroup; 5 | import android.widget.TextView; 6 | 7 | import com.example.zane.demo.Bean.Data_One; 8 | import com.example.zane.demo.R; 9 | import com.example.zane.easymvp.view.BaseListViewHolderImpl; 10 | 11 | 12 | /** 13 | * Created by Zane on 15/12/20. 14 | */ 15 | public class DataOneViewHolder extends BaseListViewHolderImpl { 16 | 17 | private TextView mTextView; 18 | 19 | public DataOneViewHolder(ViewGroup parent, @LayoutRes int res) { 20 | super(parent, res); 21 | } 22 | 23 | @Override 24 | public void initView() { 25 | mTextView = get(R.id.item_text_show); 26 | } 27 | 28 | @Override 29 | public void setData(Data_One data) { 30 | mTextView.setText(data.getDataOne()); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /demo/src/main/java/com/example/zane/demo/view/DataTwoViewHolder.java: -------------------------------------------------------------------------------- 1 | package com.example.zane.demo.view; 2 | 3 | import android.support.annotation.LayoutRes; 4 | import android.util.Log; 5 | import android.view.ViewGroup; 6 | import android.widget.TextView; 7 | 8 | import com.example.zane.demo.Bean.Data_Two; 9 | import com.example.zane.demo.R; 10 | import com.example.zane.easymvp.view.BaseListViewHolderImpl; 11 | 12 | /** 13 | * Created by Zane on 16/4/10. 14 | */ 15 | public class DataTwoViewHolder extends BaseListViewHolderImpl{ 16 | 17 | private TextView mTextView; 18 | 19 | public DataTwoViewHolder(ViewGroup parent, @LayoutRes int res) { 20 | super(parent, res); 21 | } 22 | 23 | @Override 24 | public void initView() { 25 | mTextView = get(R.id.item_text_show); 26 | Log.i("DataTwoViewHolder", String.valueOf(mTextView)); 27 | } 28 | 29 | @Override 30 | public void setData(Data_Two data) { 31 | mTextView.setText(data.getDataTwo()); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /demo/src/main/java/com/example/zane/demo/view/MainListView.java: -------------------------------------------------------------------------------- 1 | package com.example.zane.demo.view; 2 | 3 | import android.app.Activity; 4 | import android.app.ProgressDialog; 5 | import android.support.v7.widget.LinearLayoutManager; 6 | import android.support.v7.widget.RecyclerView; 7 | import android.widget.Toast; 8 | 9 | import com.example.zane.demo.R; 10 | import com.example.zane.demo.presenter.MainActivity; 11 | import com.example.zane.demo.presenter.MyRecycleviewAdapter; 12 | import com.example.zane.easymvp.base.IPersenter; 13 | import com.example.zane.easymvp.view.BaseViewImpl; 14 | 15 | import butterknife.Bind; 16 | 17 | 18 | /** 19 | * Created by Zane on 15/12/20. 20 | */ 21 | public class MainListView extends BaseViewImpl { 22 | @Bind(R.id.recycleview) 23 | RecyclerView mRecycleview; 24 | private ProgressDialog progressDialog; 25 | private Activity activity; 26 | 27 | @Override 28 | public int getRootViewId() { 29 | return R.layout.activity_main; 30 | } 31 | 32 | // @Override 33 | // public void setActivityContext(Activity activity) { 34 | // this.activity = activity; 35 | // } 36 | 37 | 38 | @Override 39 | public void injectPresenter(IPersenter persenter) { 40 | activity = (MainActivity) persenter; 41 | } 42 | 43 | @Override 44 | public void onPresenterDestory() { 45 | Toast.makeText(activity, "destory", Toast.LENGTH_SHORT).show(); 46 | } 47 | 48 | public void initRecycleview(LinearLayoutManager manager, MyRecycleviewAdapter adapter) { 49 | mRecycleview.setAdapter(adapter); 50 | mRecycleview.setLayoutManager(manager); 51 | } 52 | 53 | public void showProgress(){ 54 | progressDialog = new ProgressDialog(activity); 55 | progressDialog.show(); 56 | } 57 | 58 | public void hideProgress(){ 59 | progressDialog.hide(); 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /demo/src/main/java/com/example/zane/demo/view/MainView2.java: -------------------------------------------------------------------------------- 1 | package com.example.zane.demo.view; 2 | 3 | import android.app.Activity; 4 | import android.content.Context; 5 | import android.view.View; 6 | import android.widget.Button; 7 | import android.widget.Toast; 8 | 9 | import com.example.zane.demo.R; 10 | 11 | import com.example.zane.demo.presenter.MainActivity2; 12 | import com.example.zane.easymvp.base.IPersenter; 13 | import com.example.zane.easymvp.view.BaseViewImpl; 14 | 15 | import butterknife.Bind; 16 | 17 | 18 | /** 19 | * Created by Zane on 16/1/27. 20 | */ 21 | public class MainView2 extends BaseViewImpl { 22 | 23 | @Bind(R.id.button) 24 | Button button; 25 | @Bind(R.id.button2) 26 | Button button2; 27 | private Context context; 28 | 29 | @Override 30 | public int getRootViewId() { 31 | return R.layout.activity_2; 32 | } 33 | 34 | @Override 35 | public void injectPresenter(IPersenter persenter) { 36 | context = (Context) persenter; 37 | } 38 | 39 | @Override 40 | public void onPresenterDestory() { 41 | Toast.makeText(context, "destory", Toast.LENGTH_SHORT).show(); 42 | } 43 | 44 | public void ClickButtonShowToast() { 45 | button2.setOnClickListener(new View.OnClickListener() { 46 | @Override 47 | public void onClick(View v) { 48 | Toast.makeText(context, "传递context到View层中去", Toast.LENGTH_SHORT).show(); 49 | } 50 | }); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /demo/src/main/res/layout/activity_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 |