├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── values
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── colors.xml
│ │ │ │ ├── strings.xml
│ │ │ │ └── styles.xml
│ │ │ ├── menu
│ │ │ │ └── menu_main.xml
│ │ │ └── layout
│ │ │ │ ├── item_user_list.xml
│ │ │ │ ├── activity_user_list.xml
│ │ │ │ ├── activity_launcher.xml
│ │ │ │ └── activity_submit.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── yanzhenjie
│ │ │ │ └── mvp
│ │ │ │ └── sample
│ │ │ │ ├── fragment
│ │ │ │ ├── FragmentView.java
│ │ │ │ ├── Contract.java
│ │ │ │ └── ExampleFragment.java
│ │ │ │ ├── base
│ │ │ │ ├── BaseActivity.java
│ │ │ │ └── BaseFragment.java
│ │ │ │ ├── URLConfig.java
│ │ │ │ ├── App.java
│ │ │ │ ├── launcher
│ │ │ │ ├── Contract.java
│ │ │ │ ├── LauncherActivity.java
│ │ │ │ └── LauncherView.java
│ │ │ │ ├── submit
│ │ │ │ ├── Contract.java
│ │ │ │ ├── SubmitActivity.java
│ │ │ │ └── SubmitView.java
│ │ │ │ ├── list
│ │ │ │ ├── Contract.java
│ │ │ │ ├── ListAdapter.java
│ │ │ │ ├── UserListView.java
│ │ │ │ └── UserListActivity.java
│ │ │ │ ├── entity
│ │ │ │ ├── ListWrapper.java
│ │ │ │ ├── Page.java
│ │ │ │ └── UserInfo.java
│ │ │ │ └── http
│ │ │ │ └── HttpModel.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── yanzhenjie
│ │ │ └── mvp
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── yanzhenjie
│ │ └── mvp
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── mvp
├── .gitignore
├── src
│ ├── main
│ │ ├── AndroidManifest.xml
│ │ ├── res
│ │ │ └── values
│ │ │ │ ├── ids.xml
│ │ │ │ └── strings.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── yanzhenjie
│ │ │ └── mvp
│ │ │ ├── Bye.java
│ │ │ ├── BasePresenter.java
│ │ │ ├── request
│ │ │ └── Request.java
│ │ │ ├── BaseModel.java
│ │ │ ├── ModelResult.java
│ │ │ ├── Source.java
│ │ │ ├── ActivitySource.java
│ │ │ ├── ViewSource.java
│ │ │ └── BaseView.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── yanzhenjie
│ │ │ └── mvp
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── yanzhenjie
│ │ └── mvp
│ │ └── ExampleInstrumentedTest.java
├── build.gradle
└── proguard-rules.pro
├── settings.gradle
├── .idea
├── fileTemplates
│ ├── includes
│ │ ├── File Header.java
│ │ ├── C File Header.h
│ │ └── CopyRight.java
│ ├── internal
│ │ ├── C++ Class.cc
│ │ ├── C Source File.c
│ │ ├── C Header File.h
│ │ ├── Class.java
│ │ ├── Enum.java
│ │ ├── Interface.java
│ │ ├── AnnotationType.java
│ │ ├── C++ Class Header.h
│ │ └── XML Properties File.xml
│ ├── j2ee
│ │ ├── Remote_Interface.aidl
│ │ ├── Application.java
│ │ ├── Activity.java
│ │ ├── Service.java
│ │ ├── Broadcast_Receiver.java
│ │ ├── Fragment.java
│ │ ├── valueResourceFile.xml
│ │ ├── resourceFile.xml
│ │ ├── AndroidManifest.xml
│ │ ├── layoutResourceFile.xml
│ │ └── layoutResourceFile_vertical.xml
│ └── Singleton.java
├── copyright
│ └── profiles_settings.xml
├── modules.xml
├── runConfigurations.xml
├── gradle.xml
├── compiler.xml
└── misc.xml
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── gradle.properties
├── config.gradle
├── gradlew.bat
├── gradlew
├── LICENSE
└── README.md
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/mvp/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':mvp'
--------------------------------------------------------------------------------
/.idea/fileTemplates/includes/File Header.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by ${USER} on ${DATE}.
3 | */
--------------------------------------------------------------------------------
/.idea/fileTemplates/internal/C++ Class.cc:
--------------------------------------------------------------------------------
1 | #parse("C File Header.h")
2 | #[[#include]]# "${HEADER_FILENAME}"
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yanzhenjie/mvp-sample/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | /.idea/
3 | /build/
4 | .gradle
5 | /local.properties
6 | .DS_Store
7 | /captures
8 | .externalNativeBuild
--------------------------------------------------------------------------------
/.idea/fileTemplates/internal/C Source File.c:
--------------------------------------------------------------------------------
1 | #parse("C File Header.h")
2 | #if (${HEADER_FILENAME})
3 | #[[#include]]# "${HEADER_FILENAME}"
4 | #end
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yanzhenjie/mvp-sample/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yanzhenjie/mvp-sample/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yanzhenjie/mvp-sample/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yanzhenjie/mvp-sample/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yanzhenjie/mvp-sample/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yanzhenjie/mvp-sample/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yanzhenjie/mvp-sample/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yanzhenjie/mvp-sample/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yanzhenjie/mvp-sample/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yanzhenjie/mvp-sample/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/.idea/fileTemplates/j2ee/Remote_Interface.aidl:
--------------------------------------------------------------------------------
1 | #parse("CopyRight.java")
2 | package ${PACKAGE_NAME};
3 |
4 | #parse("File Header.java")
5 | interface ${NAME} {
6 | }
--------------------------------------------------------------------------------
/.idea/fileTemplates/internal/C Header File.h:
--------------------------------------------------------------------------------
1 | #parse("C File Header.h")
2 | #[[#ifndef]]# ${INCLUDE_GUARD}
3 | #[[#define]]# ${INCLUDE_GUARD}
4 |
5 | #[[#endif]]# //${INCLUDE_GUARD}
--------------------------------------------------------------------------------
/.idea/fileTemplates/internal/Class.java:
--------------------------------------------------------------------------------
1 | #parse("CopyRight.java")
2 | #if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
3 | #parse("File Header.java")
4 | public class ${NAME} {
5 | }
--------------------------------------------------------------------------------
/.idea/fileTemplates/internal/Enum.java:
--------------------------------------------------------------------------------
1 | #parse("CopyRight.java")
2 | #if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
3 | #parse("File Header.java")
4 | public enum ${NAME} {
5 | }
--------------------------------------------------------------------------------
/.idea/fileTemplates/internal/Interface.java:
--------------------------------------------------------------------------------
1 | #parse("CopyRight.java")
2 | #if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
3 | #parse("File Header.java")
4 | public interface ${NAME} {
5 | }
--------------------------------------------------------------------------------
/.idea/fileTemplates/internal/AnnotationType.java:
--------------------------------------------------------------------------------
1 | #parse("CopyRight.java")
2 | #if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
3 | #parse("File Header.java")
4 | public @interface ${NAME} {
5 | }
--------------------------------------------------------------------------------
/.idea/fileTemplates/j2ee/Application.java:
--------------------------------------------------------------------------------
1 | #parse("CopyRight.java")
2 | package ${PACKAGE_NAME};
3 |
4 | import android.app.Application;
5 |
6 | #parse("File Header.java")
7 | public class ${NAME} extends Application {
8 | }
--------------------------------------------------------------------------------
/.idea/fileTemplates/internal/C++ Class Header.h:
--------------------------------------------------------------------------------
1 | #parse("C File Header.h")
2 | #[[#ifndef]]# ${INCLUDE_GUARD}
3 | #[[#define]]# ${INCLUDE_GUARD}
4 |
5 | ${NAMESPACES_OPEN}
6 |
7 | class ${NAME} {
8 |
9 | };
10 |
11 | ${NAMESPACES_CLOSE}
12 |
13 | #[[#endif]]# //${INCLUDE_GUARD}
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Jan 30 13:53:27 CST 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
7 |
--------------------------------------------------------------------------------
/.idea/fileTemplates/includes/C File Header.h:
--------------------------------------------------------------------------------
1 | #if ($HEADER_COMMENTS)
2 | //
3 | // Created by $USER_NAME on ${DATE}.
4 | #if ($ORGANIZATION_NAME && $ORGANIZATION_NAME != "")
5 | // Copyright (c) $YEAR ${ORGANIZATION_NAME}#if (!$ORGANIZATION_NAME.endsWith(".")).#end All rights reserved.
6 | #end
7 | //
8 | #end
--------------------------------------------------------------------------------
/.idea/fileTemplates/j2ee/Activity.java:
--------------------------------------------------------------------------------
1 | #parse("CopyRight.java")
2 | package ${PACKAGE_NAME};
3 |
4 | import android.app.Activity;
5 | import android.os.Bundle;
6 |
7 | #parse("File Header.java")
8 | public class ${NAME} extends Activity {
9 | @Override
10 | public void onCreate(Bundle savedInstanceState) {
11 | super.onCreate(savedInstanceState);
12 | }
13 | }
--------------------------------------------------------------------------------
/.idea/fileTemplates/j2ee/Service.java:
--------------------------------------------------------------------------------
1 | #parse("CopyRight.java")
2 | package ${PACKAGE_NAME};
3 |
4 | import android.app.Service;
5 | import android.content.Intent;
6 | import android.os.IBinder;
7 |
8 | #parse("File Header.java")
9 | public class ${NAME} extends Service {
10 | @Override
11 | public IBinder onBind(Intent intent) {
12 | return null;
13 | }
14 | }
--------------------------------------------------------------------------------
/.idea/fileTemplates/Singleton.java:
--------------------------------------------------------------------------------
1 | #parse("CopyRight.java")
2 | #if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
3 | #parse("File Header.java")
4 | public class ${NAME}{
5 | private static ${NAME} ourInstance = new ${NAME}();
6 |
7 | public static ${NAME} getInstance() {
8 | return ourInstance;
9 | }
10 |
11 | private ${NAME}() {
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/.idea/fileTemplates/j2ee/Broadcast_Receiver.java:
--------------------------------------------------------------------------------
1 | #parse("CopyRight.java")
2 | package ${PACKAGE_NAME};
3 |
4 | import android.content.BroadcastReceiver;
5 | import android.content.Context;
6 | import android.content.Intent;
7 |
8 | #parse("File Header.java")
9 | public class ${NAME} extends BroadcastReceiver {
10 | @Override
11 | public void onReceive(Context context, Intent intent) {
12 | }
13 | }
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/fileTemplates/j2ee/Fragment.java:
--------------------------------------------------------------------------------
1 | #parse("CopyRight.java")
2 | package ${PACKAGE_NAME};
3 |
4 | import android.app.Fragment;
5 | import android.os.Bundle;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 |
10 | #parse("File Header.java")
11 | public class ${NAME} extends Fragment {
12 | @Override
13 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
14 | return null;
15 | }
16 | }
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/fileTemplates/includes/CopyRight.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © Yan Zhenjie
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/fileTemplates/j2ee/valueResourceFile.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
--------------------------------------------------------------------------------
/mvp/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
--------------------------------------------------------------------------------
/.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 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/mvp/src/main/res/values/ids.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 | - @+id/toolbar
19 |
--------------------------------------------------------------------------------
/.idea/fileTemplates/internal/XML Properties File.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
--------------------------------------------------------------------------------
/.idea/fileTemplates/j2ee/resourceFile.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 | <${ROOT_TAG}
18 | xmlns:android="http://schemas.android.com/apk/res/android">
19 | ${ROOT_TAG}>
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 | 16dp
19 | 10dp
20 |
21 |
--------------------------------------------------------------------------------
/mvp/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 | 取消
19 | 确定
20 |
21 |
--------------------------------------------------------------------------------
/mvp/src/main/java/com/yanzhenjie/mvp/Bye.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © Yan Zhenjie
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.yanzhenjie.mvp;
17 |
18 | /**
19 | * Created by YanZhenjie on 2017/12/27.
20 | */
21 | public interface Bye {
22 |
23 | /**
24 | * Finish.
25 | */
26 | void bye();
27 | }
--------------------------------------------------------------------------------
/.idea/fileTemplates/j2ee/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/.idea/fileTemplates/j2ee/layoutResourceFile.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 | <${ROOT_TAG}
18 | xmlns:android="http://schemas.android.com/apk/res/android"
19 | android:layout_width="${LAYOUT_WIDTH}"
20 | android:layout_height="${LAYOUT_HEIGHT}">
21 | ${ROOT_TAG}>
--------------------------------------------------------------------------------
/mvp/src/main/java/com/yanzhenjie/mvp/BasePresenter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © Yan Zhenjie
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.yanzhenjie.mvp;
17 |
18 | import android.arch.lifecycle.LifecycleOwner;
19 |
20 | /**
21 | *
Presenter of MVP.
22 | * Created by YanZhenjie on 2017/7/17.
23 | */
24 | public interface BasePresenter extends LifecycleOwner, Bye {
25 | }
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 | #3F51B5
19 | #303F9F
20 | #FF4081
21 |
22 | #333333
23 |
24 |
--------------------------------------------------------------------------------
/.idea/fileTemplates/j2ee/layoutResourceFile_vertical.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 | <${ROOT_TAG}
18 | xmlns:android="http://schemas.android.com/apk/res/android"
19 | android:orientation="vertical"
20 | android:layout_width="${LAYOUT_WIDTH}"
21 | android:layout_height="${LAYOUT_HEIGHT}">
22 | ${ROOT_TAG}>
--------------------------------------------------------------------------------
/mvp/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: rootProject.ext.plugins.library
2 | apply plugin: rootProject.ext.plugins.butterKnife
3 |
4 | android {
5 | compileSdkVersion rootProject.ext.android.compileSdkVersion
6 | buildToolsVersion rootProject.ext.android.buildToolsVersion
7 |
8 | defaultConfig {
9 | minSdkVersion rootProject.ext.android.defaultConfig.minSdkVersion
10 | targetSdkVersion rootProject.ext.android.defaultConfig.targetSdkVersion
11 | }
12 | }
13 |
14 | dependencies {
15 | compile fileTree(dir: 'libs', include: ['*.jar'])
16 | compile rootProject.ext.dependencies.appCompat
17 |
18 | compile rootProject.ext.dependencies.butterKnife
19 | annotationProcessor rootProject.ext.dependencies.butterKnifeCompiler
20 |
21 | testCompile rootProject.ext.dependencies.junit
22 | androidTestCompile(rootProject.ext.dependencies.expressoCore) {
23 | exclude group: "com.android.support", module: "support-annotations"
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/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 D:\Develop\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 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/mvp/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 D:\Develop\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 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yanzhenjie/mvp/sample/fragment/FragmentView.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © Yan Zhenjie
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.yanzhenjie.mvp.sample.fragment;
17 |
18 | import android.view.View;
19 |
20 | /**
21 | * Created by YanZhenjie on 2018/1/30.
22 | */
23 | public class FragmentView extends Contract.FragmentView {
24 |
25 | public FragmentView(View view, Contract.FragmentPresenter presenter) {
26 | super(view, presenter);
27 | }
28 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/yanzhenjie/mvp/sample/base/BaseActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © Yan Zhenjie
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.yanzhenjie.mvp.sample.base;
17 |
18 | import android.support.v7.app.AppCompatActivity;
19 |
20 | import com.yanzhenjie.mvp.BasePresenter;
21 |
22 | /**
23 | * Created by YanZhenjie on 2018/1/30.
24 | */
25 | public class BaseActivity extends AppCompatActivity implements BasePresenter {
26 |
27 | @Override
28 | public void bye() {
29 | finish();
30 | }
31 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/yanzhenjie/mvp/sample/base/BaseFragment.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © Yan Zhenjie
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.yanzhenjie.mvp.sample.base;
17 |
18 | import android.support.v4.app.Fragment;
19 |
20 | import com.yanzhenjie.mvp.BasePresenter;
21 |
22 | /**
23 | * Created by YanZhenjie on 2018/1/30.
24 | */
25 | public class BaseFragment extends Fragment implements BasePresenter {
26 |
27 | @Override
28 | public void bye() {
29 | // TODO 回退Fragment,由开发者自己实现。
30 | }
31 | }
--------------------------------------------------------------------------------
/mvp/src/main/java/com/yanzhenjie/mvp/request/Request.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © Yan Zhenjie
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.yanzhenjie.mvp.request;
17 |
18 | /**
19 | *
20 | * 这个Request只是用来模拟请求数据的,从本地或者从网络,开发者可以具体修改实现。
21 | *
22 | * Created by YanZhenjie on 2018/1/30.
23 | */
24 | public class Request {
25 |
26 | private String mUrl;
27 |
28 | public Request(String url) {
29 | this.mUrl = url;
30 | }
31 |
32 | public String getUrl() {
33 | return mUrl;
34 | }
35 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/yanzhenjie/mvp/sample/URLConfig.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © Yan Zhenjie
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.yanzhenjie.mvp.sample;
17 |
18 | /**
19 | * Created by YanZhenjie on 2018/1/30.
20 | */
21 | public final class URLConfig {
22 |
23 | /**
24 | * 请求单个用户。
25 | */
26 | public static final String URL_USER = "http://www.example.com/user";
27 |
28 | /**
29 | * 请求用户列表。
30 | */
31 | public static final String URL_USER_LIST = "http://www.example.com/user/list";
32 |
33 | }
--------------------------------------------------------------------------------
/mvp/src/main/java/com/yanzhenjie/mvp/BaseModel.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © Yan Zhenjie
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.yanzhenjie.mvp;
17 |
18 | import com.yanzhenjie.mvp.request.Request;
19 |
20 | /**
21 | * Created by YanZhenjie on 2018/1/30.
22 | */
23 | public interface BaseModel {
24 |
25 | void load(Request request, Listener listener);
26 |
27 | void loadMore(Request request, Listener listener);
28 |
29 | interface Listener {
30 | void onResult(ModelResult result);
31 | }
32 | }
--------------------------------------------------------------------------------
/app/src/test/java/com/yanzhenjie/mvp/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © Yan Zhenjie
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.yanzhenjie.mvp;
17 |
18 | import org.junit.Test;
19 |
20 | import static org.junit.Assert.*;
21 |
22 | /**
23 | * Example local unit test, which will execute on the development machine (host).
24 | *
25 | * @see Testing documentation
26 | */
27 | public class ExampleUnitTest {
28 | @Test
29 | public void addition_isCorrect() throws Exception {
30 | assertEquals(4, 2 + 2);
31 | }
32 | }
--------------------------------------------------------------------------------
/mvp/src/test/java/com/yanzhenjie/mvp/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © Yan Zhenjie
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.yanzhenjie.mvp;
17 |
18 | import org.junit.Test;
19 |
20 | import static org.junit.Assert.*;
21 |
22 | /**
23 | * Example local unit test, which will execute on the development machine (host).
24 | *
25 | * @see Testing documentation
26 | */
27 | public class ExampleUnitTest {
28 | @Test
29 | public void addition_isCorrect() throws Exception {
30 | assertEquals(4, 2 + 2);
31 | }
32 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/yanzhenjie/mvp/sample/App.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © Yan Zhenjie
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.yanzhenjie.mvp.sample;
17 |
18 | import android.app.Application;
19 |
20 | /**
21 | * Created by YanZhenjie on 2018/1/30.
22 | */
23 | public class App extends Application {
24 |
25 | private static App sApp;
26 |
27 | @Override
28 | public void onCreate() {
29 | super.onCreate();
30 | if (sApp == null) {
31 | sApp = this;
32 | }
33 | }
34 |
35 | public static App get() {
36 | return sApp;
37 | }
38 | }
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
27 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yanzhenjie/mvp/sample/fragment/Contract.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © Yan Zhenjie
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.yanzhenjie.mvp.sample.fragment;
17 |
18 | import android.view.View;
19 |
20 | import com.yanzhenjie.mvp.BasePresenter;
21 | import com.yanzhenjie.mvp.BaseView;
22 |
23 | /**
24 | * Created by YanZhenjie on 2018/1/30.
25 | */
26 | public final class Contract {
27 |
28 | public interface FragmentPresenter extends BasePresenter {
29 | }
30 |
31 | public static abstract class FragmentView extends BaseView {
32 | public FragmentView(View view, FragmentPresenter presenter) {
33 | super(view, presenter);
34 | }
35 | }
36 |
37 | }
--------------------------------------------------------------------------------
/config.gradle:
--------------------------------------------------------------------------------
1 | ext {
2 | plugins = [
3 | library : 'com.android.library',
4 | application: 'com.android.application',
5 | butterKnife: 'com.jakewharton.butterknife',
6 | ]
7 |
8 | android = [
9 | compileSdkVersion: 26,
10 | buildToolsVersion: "26.0.3",
11 |
12 | defaultConfig : [
13 | applicationId : "com.yanzhenjie.mvp.sample",
14 | minSdkVersion : 14,
15 | targetSdkVersion: 26,
16 | versionCode : 1,
17 | versionName : "1.0.0",
18 | runner : "android.support.test.runner.AndroidJUnitRunner"
19 | ]
20 | ]
21 |
22 | dependencies = [
23 | junit : 'junit:junit:4.12',
24 | expressoCore : 'com.android.support.test.espresso:espresso-core:2.2.2',
25 |
26 | appCompat : 'com.android.support:appcompat-v7:26.1.0',
27 | design : 'com.android.support:design:26.1.0',
28 |
29 | butterKnife : 'com.jakewharton:butterknife:8.8.1',
30 | butterKnifeCompiler: 'com.jakewharton:butterknife-compiler:8.8.1',
31 | swipeRecyclerView : 'com.yanzhenjie:recyclerview-swipe:1.1.4'
32 | ]
33 | }
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 | MVPSample
19 | Settings
20 | 列表形式
21 | 提交形式
22 |
23 | 列表
24 | 您点击了第%1$d个
25 |
26 | 主动提交
27 | 昵称
28 | 请输入昵称
29 | 密码
30 | 请输入密码
31 | 提交
32 | 提交成功
33 |
34 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: rootProject.ext.plugins.application
2 | apply plugin: rootProject.ext.plugins.butterKnife
3 |
4 | android {
5 | compileSdkVersion rootProject.ext.android.compileSdkVersion
6 | buildToolsVersion rootProject.ext.android.buildToolsVersion
7 |
8 | defaultConfig {
9 | applicationId rootProject.ext.android.defaultConfig.applicationId
10 | minSdkVersion rootProject.ext.android.defaultConfig.minSdkVersion
11 | targetSdkVersion rootProject.ext.android.defaultConfig.targetSdkVersion
12 | versionCode rootProject.ext.android.defaultConfig.versionCode
13 | versionName rootProject.ext.android.defaultConfig.versionName
14 | testInstrumentationRunner rootProject.ext.android.defaultConfig.runner
15 | }
16 | }
17 |
18 | dependencies {
19 | compile project(path: ':mvp')
20 |
21 | compile fileTree(dir: 'libs', include: ['*.jar'])
22 | compile rootProject.ext.dependencies.appCompat
23 | compile rootProject.ext.dependencies.design
24 |
25 | compile rootProject.ext.dependencies.butterKnife
26 | annotationProcessor rootProject.ext.dependencies.butterKnifeCompiler
27 | compile rootProject.ext.dependencies.swipeRecyclerView
28 |
29 | testCompile rootProject.ext.dependencies.junit
30 | androidTestCompile(rootProject.ext.dependencies.expressoCore) {
31 | exclude group: "com.android.support", module: "support-annotations"
32 | }
33 | }
--------------------------------------------------------------------------------
/mvp/src/main/java/com/yanzhenjie/mvp/ModelResult.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © Yan Zhenjie
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.yanzhenjie.mvp;
17 |
18 | /**
19 | * Created by YanZhenjie on 2018/1/30.
20 | */
21 | public class ModelResult {
22 |
23 | private boolean mSucceed;
24 | private Result mResult;
25 | private String mMessage;
26 |
27 | public ModelResult(Result result) {
28 | this.mSucceed = true;
29 | this.mResult = result;
30 | }
31 |
32 | public ModelResult(String message) {
33 | this.mSucceed = true;
34 | this.mMessage = message;
35 | }
36 |
37 | public boolean isSucceed() {
38 | return mSucceed;
39 | }
40 |
41 | public Result getResult() {
42 | return mResult;
43 | }
44 |
45 | public String getMessage() {
46 | return mMessage;
47 | }
48 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/yanzhenjie/mvp/sample/launcher/Contract.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © Yan Zhenjie
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.yanzhenjie.mvp.sample.launcher;
17 |
18 | import android.app.Activity;
19 |
20 | import com.yanzhenjie.mvp.BasePresenter;
21 | import com.yanzhenjie.mvp.BaseView;
22 | import com.yanzhenjie.mvp.sample.entity.UserInfo;
23 |
24 | /**
25 | * Created by YanZhenjie on 2018/1/30.
26 | */
27 | public final class Contract {
28 |
29 | public interface LauncherPresenter extends BasePresenter {
30 | }
31 |
32 | public static abstract class LauncherView extends BaseView {
33 | public LauncherView(Activity activity, LauncherPresenter presenter) {
34 | super(activity, presenter);
35 | }
36 |
37 | /**
38 | * 绑定数据源。
39 | */
40 | public abstract void bindData(UserInfo userInfo);
41 | }
42 |
43 | }
--------------------------------------------------------------------------------
/mvp/src/androidTest/java/com/yanzhenjie/mvp/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © Yan Zhenjie
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.yanzhenjie.mvp;
17 |
18 | import android.content.Context;
19 | import android.support.test.InstrumentationRegistry;
20 | import android.support.test.runner.AndroidJUnit4;
21 |
22 | import org.junit.Test;
23 | import org.junit.runner.RunWith;
24 |
25 | import static org.junit.Assert.*;
26 |
27 | /**
28 | * Instrumentation test, which will execute on an Android device.
29 | *
30 | * @see Testing documentation
31 | */
32 | @RunWith(AndroidJUnit4.class)
33 | public class ExampleInstrumentedTest {
34 | @Test
35 | public void useAppContext() throws Exception {
36 | Context appContext = InstrumentationRegistry.getTargetContext();
37 | assertEquals("com.yanzhenjie.mvp.test", appContext.getPackageName());
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 |
26 |
27 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/yanzhenjie/mvp/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © Yan Zhenjie
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.yanzhenjie.mvp;
17 |
18 | import android.content.Context;
19 | import android.support.test.InstrumentationRegistry;
20 | import android.support.test.runner.AndroidJUnit4;
21 |
22 | import org.junit.Test;
23 | import org.junit.runner.RunWith;
24 |
25 | import static org.junit.Assert.*;
26 |
27 | /**
28 | * Instrumentation test, which will execute on an Android device.
29 | *
30 | * @see Testing documentation
31 | */
32 | @RunWith(AndroidJUnit4.class)
33 | public class ExampleInstrumentedTest {
34 | @Test
35 | public void useAppContext() throws Exception {
36 | // Context of the app under test.
37 | Context appContext = InstrumentationRegistry.getTargetContext();
38 |
39 | assertEquals("com.yanzhenjie.mvp", appContext.getPackageName());
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yanzhenjie/mvp/sample/submit/Contract.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © Yan Zhenjie
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.yanzhenjie.mvp.sample.submit;
17 |
18 | import android.app.Activity;
19 |
20 | import com.yanzhenjie.mvp.BasePresenter;
21 | import com.yanzhenjie.mvp.BaseView;
22 |
23 | /**
24 | * Created by YanZhenjie on 2018/1/30.
25 | */
26 | public final class Contract {
27 |
28 | public interface SubmitPresenter extends BasePresenter {
29 | /**
30 | * 提交数据。
31 | */
32 | void submit(String name, String password);
33 | }
34 |
35 | public static abstract class SubmitView extends BaseView {
36 |
37 | public SubmitView(Activity activity, SubmitPresenter presenter) {
38 | super(activity, presenter);
39 | }
40 |
41 | /**
42 | * 用户名空。
43 | */
44 | public abstract void nameNull();
45 |
46 | /**
47 | * 密码空。
48 | */
49 | public abstract void passwordNull();
50 | }
51 |
52 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_user_list.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
25 |
26 |
31 |
32 |
37 |
38 |
43 |
44 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
20 |
21 |
29 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
44 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yanzhenjie/mvp/sample/list/Contract.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © Yan Zhenjie
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.yanzhenjie.mvp.sample.list;
17 |
18 | import android.app.Activity;
19 |
20 | import com.yanzhenjie.mvp.BasePresenter;
21 | import com.yanzhenjie.mvp.BaseView;
22 | import com.yanzhenjie.mvp.sample.entity.Page;
23 | import com.yanzhenjie.mvp.sample.entity.UserInfo;
24 |
25 | import java.util.List;
26 |
27 | /**
28 | * Created by YanZhenjie on 2018/1/30.
29 | */
30 | public final class Contract {
31 |
32 | public interface UserListPresenter extends BasePresenter {
33 |
34 | /**
35 | * 刷新数据。
36 | */
37 | void refresh();
38 |
39 | /**
40 | * 加载更多数据。
41 | */
42 | void loadMore();
43 |
44 | /**
45 | * 点击Item。
46 | */
47 | void clickItem(int position);
48 | }
49 |
50 | public static abstract class UserListView extends BaseView {
51 | public UserListView(Activity activity, UserListPresenter presenter) {
52 | super(activity, presenter);
53 | }
54 |
55 | /**
56 | * 设置View刷新状态。
57 | */
58 | public abstract void setRefresh(boolean refresh);
59 |
60 | /**
61 | * 绑定数据源。
62 | */
63 | public abstract void bindDataList(List dataList, Page page);
64 |
65 | /**
66 | * 向数据源添加数据。
67 | */
68 | public abstract void addDataList(Page page);
69 | }
70 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/yanzhenjie/mvp/sample/entity/ListWrapper.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © Yan Zhenjie
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.yanzhenjie.mvp.sample.entity;
17 |
18 | import android.os.Parcel;
19 | import android.os.Parcelable;
20 |
21 | import java.util.List;
22 |
23 | /**
24 | * Created by YanZhenjie on 2018/1/30.
25 | */
26 | public class ListWrapper implements Parcelable {
27 |
28 | private List mDataList;
29 | private Page mPage;
30 |
31 | public ListWrapper() {
32 | }
33 |
34 | protected ListWrapper(Parcel in) {
35 | mPage = in.readParcelable(Page.class.getClassLoader());
36 | }
37 |
38 | @Override
39 | public void writeToParcel(Parcel dest, int flags) {
40 | dest.writeParcelable(mPage, flags);
41 | }
42 |
43 | @Override
44 | public int describeContents() {
45 | return 0;
46 | }
47 |
48 | public static final Creator CREATOR = new Creator() {
49 | @Override
50 | public ListWrapper createFromParcel(Parcel in) {
51 | return new ListWrapper(in);
52 | }
53 |
54 | @Override
55 | public ListWrapper[] newArray(int size) {
56 | return new ListWrapper[size];
57 | }
58 | };
59 |
60 | public List getDataList() {
61 | return mDataList;
62 | }
63 |
64 | public void setDataList(List dataList) {
65 | mDataList = dataList;
66 | }
67 |
68 | public Page getPage() {
69 | return mPage;
70 | }
71 |
72 | public void setPage(Page page) {
73 | mPage = page;
74 | }
75 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/yanzhenjie/mvp/sample/fragment/ExampleFragment.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © Yan Zhenjie
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.yanzhenjie.mvp.sample.fragment;
17 |
18 | import android.os.Bundle;
19 | import android.support.annotation.Nullable;
20 | import android.view.LayoutInflater;
21 | import android.view.View;
22 | import android.view.ViewGroup;
23 |
24 | import com.yanzhenjie.mvp.BaseModel;
25 | import com.yanzhenjie.mvp.sample.R;
26 | import com.yanzhenjie.mvp.sample.base.BaseFragment;
27 | import com.yanzhenjie.mvp.sample.http.HttpModel;
28 |
29 | /**
30 | *
31 | * 这个Fragment没有被使用,这里只是给出Fragment初始化View的例子,其它用法同Activity。
32 | *
33 | * Created by YanZhenjie on 2018/1/30.
34 | */
35 | public class ExampleFragment extends BaseFragment implements Contract.FragmentPresenter {
36 |
37 | private Contract.FragmentView mView;
38 | private BaseModel mModel;
39 |
40 | @Nullable
41 | @Override
42 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
43 | return inflater.inflate(R.layout.activity_launcher, container, false);
44 | }
45 |
46 | @Override
47 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
48 | mView = new FragmentView(view, this);
49 | }
50 |
51 | @Override
52 | public void onActivityCreated(@Nullable Bundle savedInstanceState) {
53 | super.onActivityCreated(savedInstanceState);
54 | mModel = new HttpModel();
55 |
56 | request();
57 | }
58 |
59 | private void request() {
60 | // mView.set...
61 | }
62 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_user_list.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
22 |
23 |
27 |
28 |
35 |
36 |
37 |
38 |
43 |
44 |
48 |
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yanzhenjie/mvp/sample/launcher/LauncherActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © Yan Zhenjie
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.yanzhenjie.mvp.sample.launcher;
17 |
18 | import android.os.Bundle;
19 |
20 | import com.yanzhenjie.mvp.BaseModel;
21 | import com.yanzhenjie.mvp.ModelResult;
22 | import com.yanzhenjie.mvp.request.Request;
23 | import com.yanzhenjie.mvp.sample.R;
24 | import com.yanzhenjie.mvp.sample.URLConfig;
25 | import com.yanzhenjie.mvp.sample.base.BaseActivity;
26 | import com.yanzhenjie.mvp.sample.http.HttpModel;
27 | import com.yanzhenjie.mvp.sample.entity.UserInfo;
28 |
29 | /**
30 | * Created by YanZhenjie on 2018/1/30.
31 | */
32 | public class LauncherActivity extends BaseActivity implements Contract.LauncherPresenter {
33 |
34 | private Contract.LauncherView mView;
35 | private BaseModel mModel;
36 |
37 | @Override
38 | protected void onCreate(Bundle savedInstanceState) {
39 | super.onCreate(savedInstanceState);
40 | setContentView(R.layout.activity_launcher);
41 | mView = new LauncherView(this, this);
42 | mModel = new HttpModel();
43 |
44 | request();
45 | }
46 |
47 | private void request() {
48 | Request request = new Request(URLConfig.URL_USER);
49 | mModel.load(request, new BaseModel.Listener() {
50 | @Override
51 | public void onResult(ModelResult result) {
52 | if (result.isSucceed()) {
53 | UserInfo userInfo = result.getResult();
54 | mView.bindData(userInfo);
55 | } else {
56 | mView.toast(result.getMessage());
57 | }
58 | }
59 | });
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yanzhenjie/mvp/sample/submit/SubmitActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © Yan Zhenjie
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.yanzhenjie.mvp.sample.submit;
17 |
18 | import android.os.Bundle;
19 | import android.support.annotation.Nullable;
20 | import android.text.TextUtils;
21 |
22 | import com.yanzhenjie.mvp.BaseModel;
23 | import com.yanzhenjie.mvp.ModelResult;
24 | import com.yanzhenjie.mvp.request.Request;
25 | import com.yanzhenjie.mvp.sample.R;
26 | import com.yanzhenjie.mvp.sample.base.BaseActivity;
27 | import com.yanzhenjie.mvp.sample.http.HttpModel;
28 |
29 | /**
30 | * Created by YanZhenjie on 2018/1/30.
31 | */
32 | public class SubmitActivity extends BaseActivity implements Contract.SubmitPresenter {
33 |
34 | private Contract.SubmitView mView;
35 | private BaseModel mModel;
36 |
37 | @Override
38 | protected void onCreate(@Nullable Bundle savedInstanceState) {
39 | super.onCreate(savedInstanceState);
40 | setContentView(R.layout.activity_submit);
41 | mView = new SubmitView(this, this);
42 | mModel = new HttpModel();
43 | }
44 |
45 | @Override
46 | public void submit(String name, String password) {
47 | if (TextUtils.isEmpty(name)) {
48 | mView.nameNull();
49 | return;
50 | }
51 | if (TextUtils.isEmpty(password)) {
52 | mView.passwordNull();
53 | return;
54 | }
55 |
56 | Request request = new Request("");
57 | mModel.load(request, new BaseModel.Listener