├── .gitignore ├── .idea ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── misc.xml ├── modules.xml └── runConfigurations.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── example │ │ └── maat │ │ └── hello_mvp │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── maat │ │ │ └── hello_mvp │ │ │ ├── model │ │ │ └── retrofit │ │ │ │ ├── DownloadService.java │ │ │ │ └── InternetHelper.java │ │ │ ├── presenter │ │ │ └── download │ │ │ │ ├── DownloadImp.java │ │ │ │ └── DownloadInterface.java │ │ │ └── view │ │ │ └── download │ │ │ ├── MainActivity.java │ │ │ └── ViewInterface.java │ └── res │ │ ├── layout │ │ └── activity_main.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 │ │ ├── attrs.xml │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── example │ └── maat │ └── hello_mvp │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── screenshots ├── MVP1.png ├── mvp.gif ├── mvp.png └── mvp2.png └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | /.idea/ 11 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | 14 | 26 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | Android Lint 46 | 47 | 48 | General 49 | 50 | 51 | Maven 52 | 53 | 54 | 55 | 56 | AndroidLintUseCompoundDrawables 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 78 | 79 | $USER_HOME$/.subversion 80 | 81 | 82 | 83 | 84 | 85 | 1.8 86 | 87 | 92 | 93 | 94 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ##MVP 架构概述 2 | 总体思想是`横向分块,纵向分层`。纵向分为View,Presenter,Model三层,横向按功能模块划分。 3 | 4 | - View层:Activitys,Fragmengts,Adapters.主要两个作用:1、向用户显示数据。2、将用户的操作传递到Presenter并接受Presenter传回的数据(如用户的点击、输入)。 5 | - Presenter层:将View层传来的数据进行相关的处理,把请求发送到Model层,然后将Model层返回的数据做处理,交给View层呈现给用户。 6 | - Model层:数据处理中心,根据Presenter层的请求,从不同的资源中获得数据,如数据库,网络,内存等,然后再传回Presenter层。各种开源库 7 | 8 | 9 | ##screenshots 10 | 11 | 12 | 13 | 14 | ####本项目架构图 15 | 17 | 18 | 19 | ####扩展:多线程多任务下载会是这样的 20 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'android-apt' 3 | 4 | android { 5 | compileSdkVersion 24 6 | buildToolsVersion "24.0.3" 7 | defaultConfig { 8 | applicationId "com.example.maat.hello_mvp" 9 | minSdkVersion 16 10 | targetSdkVersion 24 11 | versionCode 1 12 | versionName "1.0" 13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 14 | } 15 | buildTypes { 16 | release { 17 | minifyEnabled false 18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 19 | } 20 | } 21 | } 22 | 23 | dependencies { 24 | compile fileTree(dir: 'libs', include: ['*.jar']) 25 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 26 | exclude group: 'com.android.support', module: 'support-annotations' 27 | }) 28 | compile 'com.android.support:appcompat-v7:24.2.1' 29 | testCompile 'junit:junit:4.12' 30 | compile 'com.daimajia.numberprogressbar:library:1.2@aar' 31 | 32 | compile 'com.jakewharton:butterknife:8.4.0' 33 | apt 'com.jakewharton:butterknife-compiler:8.4.0' 34 | 35 | 36 | // Because RxAndroid releases are few and far between, it is recommended you also 37 | // explicitly depend on RxJava's latest version for bug fixes and new features. 38 | compile 'io.reactivex:rxjava:1.0.14' 39 | compile 'io.reactivex:rxjava-math:1.0.0' 40 | } 41 | -------------------------------------------------------------------------------- /app/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/xinghongfei/Downloads/android-sdk--mac-r24-updated/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 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/example/maat/hello_mvp/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.example.maat.hello_mvp; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.example.maat.hello_mvp", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/maat/hello_mvp/model/retrofit/DownloadService.java: -------------------------------------------------------------------------------- 1 | package com.example.maat.hello_mvp.model.retrofit; 2 | 3 | import android.os.Handler; 4 | 5 | /** 6 | * Created by xinghongfei on 16/10/6. 7 | */ 8 | 9 | public class DownloadService { 10 | 11 | private DownloadListener mDownloadListener; 12 | private int t=0; 13 | private Handler mHandler=new Handler(); 14 | 15 | public boolean downloadFile(String s) { 16 | 17 | mHandler.postDelayed(new Runnable() { 18 | @Override 19 | public void run() { 20 | if (mDownloadListener != null) { 21 | mDownloadListener.downloding(++t); 22 | } 23 | mHandler.postDelayed(this,100); 24 | if (t==100){ 25 | mHandler.removeCallbacks(this); 26 | mDownloadListener.finished(); 27 | t=0; 28 | 29 | } 30 | } 31 | },100); 32 | 33 | return true; 34 | } 35 | 36 | public boolean pause() { 37 | return true; 38 | } 39 | 40 | public boolean cancel() { 41 | return true; 42 | } 43 | 44 | public void setDownloadListener(DownloadListener downloadListener) { 45 | mDownloadListener = downloadListener; 46 | } 47 | 48 | public interface DownloadListener { 49 | void downloding(int t); 50 | 51 | void finished(); 52 | 53 | void error(Exception e); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/maat/hello_mvp/model/retrofit/InternetHelper.java: -------------------------------------------------------------------------------- 1 | package com.example.maat.hello_mvp.model.retrofit; 2 | 3 | /** 4 | * Created by xinghongfei on 16/10/6. 5 | */ 6 | 7 | public class InternetHelper { 8 | 9 | 10 | public static boolean isWifiConnected(){ 11 | // 判断网络状态 12 | return true; 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/maat/hello_mvp/presenter/download/DownloadImp.java: -------------------------------------------------------------------------------- 1 | package com.example.maat.hello_mvp.presenter.download; 2 | 3 | import com.example.maat.hello_mvp.model.retrofit.DownloadService; 4 | import com.example.maat.hello_mvp.model.retrofit.InternetHelper; 5 | import com.example.maat.hello_mvp.view.download.ViewInterface; 6 | 7 | /** 8 | * Created by xinghongfei on 16/10/6. 9 | */ 10 | 11 | public class DownloadImp implements DownloadInterface{ 12 | 13 | private ViewInterface mViewInterface; 14 | 15 | private DownloadService mDownloadService; 16 | 17 | public DownloadImp(ViewInterface viewInterface){ 18 | mViewInterface = viewInterface; 19 | mDownloadService=new DownloadService(); 20 | } 21 | 22 | @Override 23 | public void start(String file) { 24 | if (InternetHelper.isWifiConnected()){ 25 | mDownloadService.setDownloadListener(new DownloadService.DownloadListener() { 26 | @Override 27 | public void downloding(int t) { 28 | mViewInterface.downloading(t); 29 | } 30 | 31 | @Override 32 | public void finished() { 33 | mViewInterface.completed(); 34 | } 35 | 36 | @Override 37 | public void error(Exception e) { 38 | mViewInterface.error(e); 39 | } 40 | }); 41 | mViewInterface.start(); 42 | mDownloadService.downloadFile(file); 43 | } 44 | 45 | } 46 | 47 | @Override 48 | public void pause() { 49 | mDownloadService.pause(); 50 | } 51 | 52 | @Override 53 | public void cancel() { 54 | mDownloadService.cancel(); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/maat/hello_mvp/presenter/download/DownloadInterface.java: -------------------------------------------------------------------------------- 1 | package com.example.maat.hello_mvp.presenter.download; 2 | 3 | /** 4 | * Created by xinghongfei on 16/10/6. 5 | */ 6 | 7 | public interface DownloadInterface { 8 | void start(String s); 9 | void pause(); 10 | void cancel(); 11 | } 12 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/maat/hello_mvp/view/download/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.maat.hello_mvp.view.download; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.view.View; 6 | import android.widget.Button; 7 | import android.widget.Toast; 8 | 9 | import com.daimajia.numberprogressbar.NumberProgressBar; 10 | import com.example.maat.hello_mvp.R; 11 | import com.example.maat.hello_mvp.presenter.download.DownloadImp; 12 | 13 | import butterknife.BindView; 14 | import butterknife.ButterKnife; 15 | import butterknife.OnClick; 16 | 17 | public class MainActivity extends AppCompatActivity implements ViewInterface{ 18 | 19 | @BindView(R.id.start_button) 20 | Button mStartButton; 21 | @BindView(R.id.number_progress_bar) 22 | NumberProgressBar mNumberProgressBar; 23 | DownloadImp mDownloadImp; 24 | 25 | @Override 26 | protected void onCreate(Bundle savedInstanceState) { 27 | super.onCreate(savedInstanceState); 28 | setContentView(R.layout.activity_main); 29 | ButterKnife.bind(this); 30 | mDownloadImp=new DownloadImp(this); 31 | } 32 | 33 | @OnClick(R.id.start_button) 34 | public void onClick() { 35 | mDownloadImp.start("url"); 36 | } 37 | 38 | @Override 39 | public void start() { 40 | mNumberProgressBar.setVisibility(View.VISIBLE); 41 | 42 | } 43 | 44 | @Override 45 | public void downloading(int t) { 46 | mNumberProgressBar.setProgress(t); 47 | 48 | } 49 | 50 | @Override 51 | public void error(Exception e) { 52 | mNumberProgressBar.setVisibility(View.INVISIBLE); 53 | 54 | } 55 | 56 | @Override 57 | public void completed() { 58 | mNumberProgressBar.setVisibility(View.INVISIBLE); 59 | Toast.makeText(this,"下载完成",Toast.LENGTH_LONG).show(); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/maat/hello_mvp/view/download/ViewInterface.java: -------------------------------------------------------------------------------- 1 | package com.example.maat.hello_mvp.view.download; 2 | 3 | /** 4 | * Created by xinghongfei on 16/10/6. 5 | */ 6 | 7 | public interface ViewInterface { 8 | void start(); 9 | void downloading(int t); 10 | void error(Exception e); 11 | void completed(); 12 | } 13 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 15 | 16 | 21 | 22 |