├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── colors.xml │ │ │ │ └── styles.xml │ │ │ ├── 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 │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ ├── layout │ │ │ │ ├── activity_mvp_login.xml │ │ │ │ ├── activity_mvvm_login.xml │ │ │ │ ├── activity_mvc_login.xml │ │ │ │ ├── activity_main.xml │ │ │ │ └── include_login_view.xml │ │ │ ├── drawable-v24 │ │ │ │ └── ic_launcher_foreground.xml │ │ │ └── drawable │ │ │ │ └── ic_launcher_background.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── mvcmvpmvvm │ │ │ │ ├── mvp │ │ │ │ ├── model │ │ │ │ │ ├── IUserBiz.java │ │ │ │ │ ├── UserBiz.java │ │ │ │ │ └── User.java │ │ │ │ ├── view │ │ │ │ │ ├── IMvpLoginView.java │ │ │ │ │ └── MvpLoginActivity.java │ │ │ │ └── presenter │ │ │ │ │ └── LoginPresenter.java │ │ │ │ ├── mvc │ │ │ │ ├── Model │ │ │ │ │ └── User.java │ │ │ │ └── controller │ │ │ │ │ └── MvcLoginActivity.java │ │ │ │ ├── mvvm │ │ │ │ ├── model │ │ │ │ │ └── User.java │ │ │ │ ├── viewmodel │ │ │ │ │ └── LoginViewModel.java │ │ │ │ └── view │ │ │ │ │ └── MvvmLoginActivity.java │ │ │ │ └── MainActivity.java │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── mvcmvpmvvm │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── example │ │ └── mvcmvpmvvm │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .idea ├── vcs.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml ├── inspectionProfiles │ └── Project_Default.xml └── codeStyles │ └── Project.xml ├── README.md ├── gradle.properties ├── .gitignore ├── gradlew.bat └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Mvc Mvp Mvvm 3 | 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JereChen11/Android-MVC-MVP-MVVM-Simple-Demo/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JereChen11/Android-MVC-MVP-MVVM-Simple-Demo/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JereChen11/Android-MVC-MVP-MVVM-Simple-Demo/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JereChen11/Android-MVC-MVP-MVVM-Simple-Demo/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JereChen11/Android-MVC-MVP-MVVM-Simple-Demo/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JereChen11/Android-MVC-MVP-MVVM-Simple-Demo/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JereChen11/Android-MVC-MVP-MVVM-Simple-Demo/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/JereChen11/Android-MVC-MVP-MVVM-Simple-Demo/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/JereChen11/Android-MVC-MVP-MVVM-Simple-Demo/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/JereChen11/Android-MVC-MVP-MVVM-Simple-Demo/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/JereChen11/Android-MVC-MVP-MVVM-Simple-Demo/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/mvcmvpmvvm/mvp/model/IUserBiz.java: -------------------------------------------------------------------------------- 1 | package com.example.mvcmvpmvvm.mvp.model; 2 | 3 | /** 4 | * @author jere 5 | */ 6 | public interface IUserBiz { 7 | boolean login(String userName, String password); 8 | } 9 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #008577 4 | #00574B 5 | #D81B60 6 | 7 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Aug 20 23:43:38 CST 2019 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-4.10.1-all.zip 7 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/mvcmvpmvvm/mvp/view/IMvpLoginView.java: -------------------------------------------------------------------------------- 1 | package com.example.mvcmvpmvvm.mvp.view; 2 | 3 | /** 4 | * @author jere 5 | */ 6 | public interface IMvpLoginView { 7 | String getUserName(); 8 | 9 | String getPassword(); 10 | 11 | void onLoginResult(Boolean isLoginSuccess); 12 | } 13 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Android-MVC-MVP-MVVM-Simple-Demo 2 | Android MVC MVP MVVM design pattern learning 3 | 4 | The project using **MVC/MVP/MVVM** design pattern creating a simple Demo about **User Login feature**. More detail info you can refer my blog [Android MVC MVP MVVM简单例子](https://blog.csdn.net/jerechen/article/details/100058519). These code is my points about **MVC/MVP/MVVM** design pattern understanding, so.. if you have any issue, feel free to tell me. 5 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/test/java/com/example/mvcmvpmvvm/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.example.mvcmvpmvvm; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /app/src/main/java/com/example/mvcmvpmvvm/mvp/model/UserBiz.java: -------------------------------------------------------------------------------- 1 | package com.example.mvcmvpmvvm.mvp.model; 2 | 3 | /** 4 | * @author jere 5 | */ 6 | public class UserBiz implements IUserBiz { 7 | 8 | @Override 9 | public boolean login(String userName, String password) { 10 | 11 | if (userName.equals("jere") && password.equals("123")) { 12 | User user = new User(); 13 | user.setUserName(userName); 14 | user.setPassword(password); 15 | return true; 16 | } 17 | return false; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/mvcmvpmvvm/mvc/Model/User.java: -------------------------------------------------------------------------------- 1 | package com.example.mvcmvpmvvm.mvc.Model; 2 | 3 | public class User { 4 | private String userName; 5 | private String password; 6 | 7 | public String getUserName() { 8 | return userName; 9 | } 10 | 11 | public void setUserName(String userName) { 12 | this.userName = userName; 13 | } 14 | 15 | public String getPassword() { 16 | return password; 17 | } 18 | 19 | public void setPassword(String password) { 20 | this.password = password; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/mvcmvpmvvm/mvp/model/User.java: -------------------------------------------------------------------------------- 1 | package com.example.mvcmvpmvvm.mvp.model; 2 | 3 | /** 4 | * @author jere 5 | */ 6 | public class User { 7 | private String userName; 8 | private String password; 9 | 10 | public String getUserName() { 11 | return userName; 12 | } 13 | 14 | public void setUserName(String userName) { 15 | this.userName = userName; 16 | } 17 | 18 | public String getPassword() { 19 | return password; 20 | } 21 | 22 | public void setPassword(String password) { 23 | this.password = password; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/mvcmvpmvvm/mvvm/model/User.java: -------------------------------------------------------------------------------- 1 | package com.example.mvcmvpmvvm.mvvm.model; 2 | 3 | /** 4 | * @author jere 5 | */ 6 | public class User { 7 | private String userName; 8 | private String password; 9 | 10 | public String getUserName() { 11 | return userName; 12 | } 13 | 14 | public void setUserName(String userName) { 15 | this.userName = userName; 16 | } 17 | 18 | public String getPassword() { 19 | return password; 20 | } 21 | 22 | public void setPassword(String password) { 23 | this.password = password; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | 15 | 16 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/example/mvcmvpmvvm/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.example.mvcmvpmvvm; 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 | * Instrumented 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() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.example.mvpdesignpatterndemo", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/mvcmvpmvvm/mvp/presenter/LoginPresenter.java: -------------------------------------------------------------------------------- 1 | package com.example.mvcmvpmvvm.mvp.presenter; 2 | 3 | import com.example.mvcmvpmvvm.mvp.model.User; 4 | import com.example.mvcmvpmvvm.mvp.model.UserBiz; 5 | import com.example.mvcmvpmvvm.mvp.view.IMvpLoginView; 6 | 7 | /** 8 | * @author jere 9 | */ 10 | public class LoginPresenter{ 11 | private UserBiz userBiz; 12 | private IMvpLoginView iMvpLoginView; 13 | 14 | public LoginPresenter(IMvpLoginView iMvpLoginView) { 15 | this.iMvpLoginView = iMvpLoginView; 16 | this.userBiz = new UserBiz(); 17 | } 18 | 19 | public void login() { 20 | String userName = iMvpLoginView.getUserName(); 21 | String password = iMvpLoginView.getPassword(); 22 | boolean isLoginSuccessful = userBiz.login(userName, password); 23 | iMvpLoginView.onLoginResult(isLoginSuccessful); 24 | } 25 | 26 | 27 | } 28 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_mvp_login.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_mvvm_login.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_mvc_login.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 29 5 | defaultConfig { 6 | applicationId "com.example.mvpdesignpatterndemo" 7 | minSdkVersion 26 8 | targetSdkVersion 29 9 | versionCode 1 10 | versionName "1.0" 11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | implementation fileTree(dir: 'libs', include: ['*.jar']) 23 | implementation 'com.android.support:appcompat-v7:27.0.2' 24 | implementation 'com.android.support.constraint:constraint-layout:1.1.3' 25 | implementation "android.arch.lifecycle:viewmodel:1.1.1" 26 | implementation "android.arch.lifecycle:runtime:1.1.1" 27 | implementation "android.arch.lifecycle:extensions:1.1.1" 28 | testImplementation 'junit:junit:4.12' 29 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 30 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 31 | } 32 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the ART/Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | out/ 15 | 16 | # Gradle files 17 | .gradle/ 18 | build/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Log Files 27 | *.log 28 | 29 | # Android Studio Navigation editor temp files 30 | .navigation/ 31 | 32 | # Android Studio captures folder 33 | captures/ 34 | 35 | # IntelliJ 36 | *.iml 37 | .idea/workspace.xml 38 | .idea/tasks.xml 39 | .idea/gradle.xml 40 | .idea/assetWizardSettings.xml 41 | .idea/dictionaries 42 | .idea/libraries 43 | .idea/caches 44 | 45 | # Keystore files 46 | # Uncomment the following line if you do not want to check your keystore files in. 47 | #*.jks 48 | 49 | # External native build folder generated in Android Studio 2.2 and later 50 | .externalNativeBuild 51 | 52 | # Google Services (e.g. APIs or Firebase) 53 | google-services.json 54 | 55 | # Freeline 56 | freeline.py 57 | freeline/ 58 | freeline_project_description.json 59 | 60 | # fastlane 61 | fastlane/report.xml 62 | fastlane/Preview.html 63 | fastlane/screenshots 64 | fastlane/test_output 65 | fastlane/readme.md 66 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/mvcmvpmvvm/mvvm/viewmodel/LoginViewModel.java: -------------------------------------------------------------------------------- 1 | package com.example.mvcmvpmvvm.mvvm.viewmodel; 2 | 3 | import android.arch.lifecycle.MutableLiveData; 4 | import android.arch.lifecycle.ViewModel; 5 | 6 | import com.example.mvcmvpmvvm.mvvm.model.User; 7 | 8 | 9 | /** 10 | * @author jere 11 | */ 12 | public class LoginViewModel extends ViewModel { 13 | private User user; 14 | private MutableLiveData isLoginSuccessfulLD; 15 | 16 | public LoginViewModel() { 17 | this.isLoginSuccessfulLD = new MutableLiveData<>(); 18 | user = new User(); 19 | } 20 | 21 | public MutableLiveData getIsLoginSuccessfulLD() { 22 | return isLoginSuccessfulLD; 23 | } 24 | 25 | public void setIsLoginSuccessfulLD(boolean isLoginSuccessful) { 26 | isLoginSuccessfulLD.postValue(isLoginSuccessful); 27 | } 28 | 29 | public void login(String userName, String password) { 30 | if (userName.equals("jere") && password.equals("123")) { 31 | user.setUserName(userName); 32 | user.setPassword(password); 33 | setIsLoginSuccessfulLD(true); 34 | } else { 35 | setIsLoginSuccessfulLD(false); 36 | } 37 | } 38 | 39 | public String getUserName() { 40 | return user.getUserName(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 36 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 13 | 14 |