├── .gitignore ├── README.md ├── build.gradle ├── dagger-mvp ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── be │ │ │ └── vergauwen │ │ │ └── simon │ │ │ └── daggermvp │ │ │ ├── MVPApplication.java │ │ │ ├── di │ │ │ ├── ActivityScope.java │ │ │ ├── ApplicationComponent.java │ │ │ ├── ApplicationModule.java │ │ │ └── ApplicationScope.java │ │ │ └── ui │ │ │ ├── TestActivity.java │ │ │ ├── TestComponent.java │ │ │ ├── TestContract.java │ │ │ └── TestPresenter.java │ └── res │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── be │ └── vergauwen │ └── simon │ └── daggermvp │ ├── RobolectricUnitTestRunner.java │ └── ui │ └── TestActivityTest.java ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── himura-kt ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── kotlin │ └── be │ │ └── vergauwen │ │ └── simon │ │ └── himurakotlin │ │ ├── MVPActivity.kt │ │ ├── MVPContract.kt │ │ ├── MVPDaggerActivity.kt │ │ └── MVPPresenter.kt │ └── res │ └── values │ └── strings.xml ├── himura ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── be │ │ └── vergauwen │ │ └── simon │ │ └── himura │ │ ├── MVPActivity.java │ │ ├── MVPContract.java │ │ ├── MVPDaggerActivity.java │ │ └── MVPPresenter.java │ └── res │ └── values │ └── strings.xml ├── kotlin-dagger-mvp ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── main │ ├── AndroidManifest.xml │ ├── kotlin │ │ └── be │ │ │ └── vergauwen │ │ │ └── simon │ │ │ └── kotlindaggermvp │ │ │ ├── MVPApplication.kt │ │ │ ├── di │ │ │ ├── ActivityScope.kt │ │ │ ├── ApplicationComponent.kt │ │ │ ├── ApplicationModule.kt │ │ │ └── ApplicationScope.kt │ │ │ └── ui │ │ │ ├── TestActivity.kt │ │ │ ├── TestComponent.kt │ │ │ ├── TestContract.kt │ │ │ └── TestPresenter.kt │ └── res │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── kotlin │ └── be │ └── vergauwen │ └── simon │ └── kotlindaggermvp │ └── ui │ └── TestActivityTest.kt ├── kotlin-vanilla-mvp ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── main │ ├── AndroidManifest.xml │ ├── kotlin │ │ └── be │ │ │ └── vergauwen │ │ │ └── simon │ │ │ └── kotlinvanillamvp │ │ │ ├── MVPApplication.kt │ │ │ └── ui │ │ │ ├── TestActivity.kt │ │ │ ├── TestContract.kt │ │ │ └── TestPresenter.kt │ └── res │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── kotlin │ └── be │ └── vergauwen │ └── simon │ └── kotlinvanillamvp │ └── ui │ └── TestActivityTest.kt ├── save&restore-state.png ├── settings.gradle └── vanilla-mvp ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src ├── main ├── AndroidManifest.xml ├── java │ └── be │ │ └── vergauwen │ │ └── simon │ │ └── cleanmvp │ │ ├── MVPApplication.java │ │ └── ui │ │ ├── TestActivity.java │ │ ├── TestContract.java │ │ └── TestPresenter.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 │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml └── test └── java └── be └── vergauwen └── simon └── cleanmvp ├── RobolectricUnitTestRunner.java └── ui └── TestActivityTest.java /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/* 5 | .idea/ 6 | .DS_Store 7 | /build 8 | /captures 9 | *.apk 10 | *.ap_ 11 | *.dex 12 | *.class 13 | bin/ 14 | gen/ 15 | out/ 16 | .gradle/ 17 | build/ 18 | local.properties 19 | proguard/ 20 | *.log 21 | .navigation/ 22 | captures/ 23 | *.jks 24 | gen-external-apklibs 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AndroidCleanMVP 2 | 3 | In the text below you will find all info about the demo. 4 | We will not discuss the model as this is the structure of your data and is pretty straight forward. 5 | 6 | ## vanilla-mvp / kotlin-vanilla-mvp 7 | 8 | * There is a different setup for Java/Kotlin because generics are handled differently. Kotlin is stricter than Java when it comes to generics. More about that below. 9 | 10 | * A setup with no libs. 11 | 12 | * Presenter instance does not get retained over config change. 13 | * Presenter should not be responsible for retaining data during config change (Single responsibility principle by Robert C. Martin). The presenter should only be responsible for business logic, it can load/save states but does not retain them. Retaining data during config change is out of the scope of this demos, there are many different possibilities and many different use cases so think carefully before choosing a solution. 14 | 15 | ### Usage 16 | ##### MVPContract 17 | The `MVPContract` is the contract between View & Presenter. This means the contract of what functionality (methods) the view can rely on the presenter for and the other way around. 18 | ``` 19 | interface ExampleContract { 20 | interface View extends MVPContract.View { 21 | void showThings(); 22 | } 23 | 24 | interface Presenter extends MVPContract.Presenter { 25 | void loadThings(); 26 | } 27 | } 28 | ``` 29 | In the above shown code, the view can rely on the presenter to retrieve (load) things. And in return when the presenter has retrieved things, it can rely on the view to show them. 30 | 31 | Since the Java/Kotlin code for the contract solely consist of interfaces, we will not discuss this any further. 32 | 33 | ##### MVPActivity 34 | 35 | There is a very important difference between the Java and Kotlin code here. As mentioned above, Kotlin and Java handle generics differently. In the code comparison below it will become clear. 36 | ``` 37 | Java: 38 | public abstract class MVPActivity

extends AppCompatActivity implements MVPContract.View 39 | 40 | Kotlin: 41 | abstract class MVPAppCompatActivity> : AppCompatActivity(), MVPContract.View 42 | ``` 43 | When we inspect the base `MVPContract` you'll notice that the `Presenter` has a generic type, in Kotlin we're required to specify this generic type. And as a result we have to explicitly cast `MVPAppCompatActivity` to `V` when attaching it to the presenter. 44 | ``` 45 | public interface MVPContract { 46 | interface View {} 47 | 48 | interface Presenter { 49 | V getView(); 50 | void attachView(V view); 51 | void detachView(); 52 | } 53 | ``` 54 | 55 | In contrast to Kotlin Java will cast `MVPAppCompatActivity` to `V` under the hood, and for that reason you don't have to specify the generic the of the `Presenter`. 56 | 57 | **All that is left to do is override the abstract class createPresenter() when defining your Activity and you're good to go** 58 | 59 | ##### MVPPresenter 60 | 61 | ``` 62 | Java: 63 | public abstract class MVPPresenter implements MVPContract.Presenter 64 | 65 | Kotlin: 66 | abstract class MVPPresenter : MVPContract.Presenter 67 | ``` 68 | 69 | There is no difference between the definition of the `MVPPresenter` in Java or Kotlin. All you need to do to setup your Presenter is extend the abstract class and override the methods you have defined in the contract. 70 | 71 | 72 | ## dagger-mvp / kotlin-dagger-mvp 73 | 74 | * A setup with dagger. Presenter gets created by dagger with the necessary dependencies. 75 | 76 | * All the principles from above remain the same. But to make this setup truly wonderful, we can use dagger to automatically create the presenters and inject them with the dependencies that we want. 77 | 78 | * Again in this setup there is a minor difference between Kotlin and Java. The reason is the same as above 79 | >You'll notice that the Presenter has a generic type, in Kotlin we're required to specify this generic type. 80 | 81 | * We add the following to the MVPContract, and when creating the view specific `Component` you can specify the dependencies your view requires in this component. But more about that below. 82 | ``` 83 | Java: 84 | interface Component

{ 85 | P presenter(); 86 | } 87 | 88 | Kotlin: 89 | interface Component> { 90 | fun presenter(): P 91 | } 92 | ``` 93 | 94 | That was pretty straight forward, a minor change is also visible in the definition of the abstract BaseActivity class. 95 | 96 | ``` 97 | Java: 98 | public abstract class MVPDaggerBaseActivity

> extends AppCompatActivity implements MVPContract.View 99 | 100 | Kotlin: 101 | abstract class MVPDaggerBaseActivity, C : MVPContract.Component> : AppCompatActivity(), MVPContract.View 102 | ``` 103 | 104 | ##### MVPComponent 105 | 106 | Now what is this magic MVPComponent? 107 | The `MVPComponent`, is the component that belongs to your activity and that takes care of making presenter for you. And injects the `Presenter` with the dependencies that you want in your `Presenter`. 108 | 109 | The `MVPComponent` does more than just that! (ノ◕ヮ◕)ノ*:・゚✧ 110 | 111 | The MVPComponent 112 | ``` 113 | @ActivityScope 114 | @Component(dependencies = ApplicationComponent.class) 115 | public interface TestComponent extends MVPContract.Component { 116 | TestPresenter presenter(); 117 | Context applicationContext(); 118 | } 119 | ``` 120 | 121 | The constructor of TestPresenter 122 | ``` 123 | @Inject 124 | public TestPresenter(TestDependency testDependency) { 125 | this.testDependency = testDependency; 126 | } 127 | ``` 128 | 129 | The ApplicationComponent 130 | ``` 131 | @ApplicationScope 132 | @Component(modules = ApplicationModule.class) 133 | public interface ApplicationComponent { 134 | Context getApplicationContext(); 135 | TestDependency getTestDependency(); 136 | } 137 | ``` 138 | 139 | Dagger sees that you need a `TestPresenter`, defined in `TestComponent` and wants to create it for you. While doing so, Dagger sees that your `TestPresenter` has a constructor annotated with the `@Inject` annotation and will see if it has any matching dependencies. Since `TestComponent` depends on `ApplicationComponent` the dependency `TestDependency` defined in `ApplicationComponent` will be provided/injected into the constructor of TestPresenter and **poof** you have a `TestPresenter` instance that is injected with the `TestDependency` instance created in our ApplicationModule. 140 | 141 | Now we have the created `TestPresenter` available in our view trough the component. 142 | 143 | **This method works extremely well to inject instances in your presenter, that can easily be mocked out for tests** 144 | 145 | ## Important notes 146 | 147 | 1. Calling view methods 148 | * There is a key difference between the Kotlin and the Java example. Kotlin has Null safety, and therefor when a view method gets called from the presenter an error should never occur. `.?` takes care of that for you. If the view is null, the method will simply not be called and there is no problem. 149 | 150 | * The same approach doesn't work in Java. When the view is null you will get a `NullPointerException`. Ah, our dear friend finally appears. No problem, just do a null check before calling the method or add a `boolean isViewAttached()` method to our `MVPPresenter` base class. 151 | 152 | 2. View lifecycle 153 | * With previous discussed issue, we are sure that when a view method gets called it occurs between `onCreate()` and `onDestroy()`. Another issue is the issue of state loss, `java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState`. There are other side effects that can occur because not building in protection for this, an example is launching an activity when the app is in background. But that topic is out of scope for this repo. Let's just say we want to prevent this. 154 | 155 | Save & restore state 156 | 157 | * As you can see in the above shown diagram `onRestoreInstanceState()` gets called between `onStart()` and `onResume()`, so the earliest point we should **resume** normal behavior is when `onResume()` gets called. The reasoning can be applied for `onSaveInstanceState()`, we will **pause** normal behavior when `onPause()` gets called. 158 | 159 | * Earlier I mentioned the single responsibility rule, the same applies here. The view should only handle UI, saving data state or other business logic that the presenter should deal with can still proceed as otherwise. For example, a network call can return a result after the view went in the background. Saving this data might be essential in order to show the correct data when the view comes into the foreground again. 160 | 161 | * There are serveral methods to solve this problem but they're out of the scope of this demo. The question you should ask yourself is, who (what) is responsible for solving this problem. 162 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | ext.kotlin_version = '1.0.1-2' 5 | 6 | repositories { 7 | jcenter() 8 | mavenCentral() 9 | maven { url 'http://oss.sonatype.org/content/repositories/snapshots' } 10 | } 11 | dependencies { 12 | classpath 'com.android.tools.build:gradle:2.1.2' 13 | classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4' 14 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 15 | classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version" 16 | 17 | // NOTE: Do not place your application dependencies here; they belong 18 | // in the individual module build.gradle files 19 | } 20 | } 21 | 22 | allprojects { 23 | repositories { 24 | jcenter() 25 | mavenCentral() 26 | maven { url 'http://oss.sonatype.org/content/repositories/snapshots' } 27 | } 28 | } 29 | 30 | task clean(type: Delete) { 31 | delete rootProject.buildDir 32 | } 33 | -------------------------------------------------------------------------------- /dagger-mvp/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /dagger-mvp/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'com.neenbedankt.android-apt' 3 | 4 | android { 5 | compileSdkVersion 23 6 | buildToolsVersion "23.0.2" 7 | 8 | defaultConfig { 9 | applicationId "be.vergauwen.simon.daggermvp" 10 | minSdkVersion 7 11 | targetSdkVersion 23 12 | versionCode 1 13 | versionName "1.0" 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 | compile project(':himura') 26 | 27 | testCompile('junit:junit:4.12', "org.robolectric:robolectric:3.0") 28 | 29 | compile 'com.android.support:appcompat-v7:23.3.0' 30 | 31 | compile 'com.google.dagger:dagger:2.0.1' 32 | apt "com.google.dagger:dagger-compiler:2.0.1" 33 | compile 'javax.annotation:jsr250-api:1.0' 34 | } 35 | -------------------------------------------------------------------------------- /dagger-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 /Users/simonvergauwen/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /dagger-mvp/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /dagger-mvp/src/main/java/be/vergauwen/simon/daggermvp/MVPApplication.java: -------------------------------------------------------------------------------- 1 | package be.vergauwen.simon.daggermvp; 2 | 3 | import android.app.Application; 4 | import be.vergauwen.simon.daggermvp.di.ApplicationComponent; 5 | import be.vergauwen.simon.daggermvp.di.ApplicationModule; 6 | import be.vergauwen.simon.daggermvp.di.DaggerApplicationComponent; 7 | 8 | public class MVPApplication extends Application { 9 | 10 | private static ApplicationComponent component; 11 | 12 | @Override 13 | public void onCreate() { 14 | super.onCreate(); 15 | 16 | component = DaggerApplicationComponent.builder() 17 | .applicationModule(new ApplicationModule(this)) 18 | .build(); 19 | } 20 | 21 | public static ApplicationComponent getComponent() { 22 | return component; 23 | } 24 | } -------------------------------------------------------------------------------- /dagger-mvp/src/main/java/be/vergauwen/simon/daggermvp/di/ActivityScope.java: -------------------------------------------------------------------------------- 1 | package be.vergauwen.simon.daggermvp.di; 2 | 3 | import java.lang.annotation.Retention; 4 | import java.lang.annotation.RetentionPolicy; 5 | import javax.inject.Scope; 6 | 7 | @Scope 8 | @Retention(RetentionPolicy.RUNTIME) 9 | public @interface ActivityScope {} 10 | -------------------------------------------------------------------------------- /dagger-mvp/src/main/java/be/vergauwen/simon/daggermvp/di/ApplicationComponent.java: -------------------------------------------------------------------------------- 1 | package be.vergauwen.simon.daggermvp.di; 2 | 3 | import android.content.Context; 4 | import dagger.Component; 5 | 6 | @ApplicationScope 7 | @Component(modules = ApplicationModule.class) 8 | public interface ApplicationComponent { 9 | Context getApplicationContext(); 10 | } -------------------------------------------------------------------------------- /dagger-mvp/src/main/java/be/vergauwen/simon/daggermvp/di/ApplicationModule.java: -------------------------------------------------------------------------------- 1 | package be.vergauwen.simon.daggermvp.di; 2 | 3 | import android.content.Context; 4 | import be.vergauwen.simon.daggermvp.MVPApplication; 5 | import dagger.Module; 6 | import dagger.Provides; 7 | 8 | @Module 9 | public class ApplicationModule { 10 | private MVPApplication application; 11 | 12 | public ApplicationModule(MVPApplication application) { 13 | this.application = application; 14 | } 15 | 16 | @Provides 17 | @ApplicationScope 18 | public Context provideApplicationContext() { 19 | return application; 20 | } 21 | } -------------------------------------------------------------------------------- /dagger-mvp/src/main/java/be/vergauwen/simon/daggermvp/di/ApplicationScope.java: -------------------------------------------------------------------------------- 1 | package be.vergauwen.simon.daggermvp.di; 2 | 3 | import java.lang.annotation.Retention; 4 | import java.lang.annotation.RetentionPolicy; 5 | import javax.inject.Scope; 6 | 7 | @Scope 8 | @Retention(RetentionPolicy.RUNTIME) 9 | public @interface ApplicationScope {} 10 | -------------------------------------------------------------------------------- /dagger-mvp/src/main/java/be/vergauwen/simon/daggermvp/ui/TestActivity.java: -------------------------------------------------------------------------------- 1 | package be.vergauwen.simon.daggermvp.ui; 2 | 3 | import android.os.Bundle; 4 | import android.util.Log; 5 | import be.vergauwen.simon.daggermvp.MVPApplication; 6 | import be.vergauwen.simon.himura.MVPDaggerActivity; 7 | 8 | public class TestActivity extends MVPDaggerActivity 9 | implements TestContract.View { 10 | 11 | private final static String TAG = TestActivity.class.getName(); 12 | 13 | private boolean thingsShown = false; 14 | 15 | @Override 16 | protected void createComponent() { 17 | component = DaggerTestComponent.builder() 18 | .applicationComponent(MVPApplication.getComponent()) 19 | .build(); 20 | } 21 | 22 | @Override 23 | protected void onCreate(Bundle savedInstanceState) { 24 | super.onCreate(savedInstanceState); 25 | Log.e(TAG, "onCreate()"); 26 | } 27 | 28 | @Override 29 | protected void onResume() { 30 | super.onResume(); 31 | presenter.loadThings(); 32 | } 33 | 34 | @Override 35 | protected void onDestroy() { 36 | Log.e(TAG, "onDestroy()"); 37 | super.onDestroy(); 38 | 39 | } 40 | 41 | @Override 42 | public void showThings() { 43 | Log.e(TAG, ".showThings()"); 44 | thingsShown = true; 45 | } 46 | 47 | public boolean isThingsShown() { 48 | return thingsShown; 49 | } 50 | 51 | public TestPresenter getPresenter() { 52 | return presenter; 53 | } 54 | } -------------------------------------------------------------------------------- /dagger-mvp/src/main/java/be/vergauwen/simon/daggermvp/ui/TestComponent.java: -------------------------------------------------------------------------------- 1 | package be.vergauwen.simon.daggermvp.ui; 2 | 3 | import be.vergauwen.simon.daggermvp.di.ActivityScope; 4 | import be.vergauwen.simon.daggermvp.di.ApplicationComponent; 5 | import be.vergauwen.simon.himura.MVPContract; 6 | import dagger.Component; 7 | 8 | @ActivityScope 9 | @Component(dependencies = ApplicationComponent.class) 10 | public interface TestComponent extends MVPContract.Component { 11 | TestPresenter presenter(); 12 | } -------------------------------------------------------------------------------- /dagger-mvp/src/main/java/be/vergauwen/simon/daggermvp/ui/TestContract.java: -------------------------------------------------------------------------------- 1 | package be.vergauwen.simon.daggermvp.ui; 2 | 3 | import be.vergauwen.simon.himura.MVPContract; 4 | 5 | public interface TestContract { 6 | interface View extends MVPContract.View { 7 | void showThings(); 8 | } 9 | 10 | interface Presenter extends MVPContract.Presenter { 11 | void loadThings(); 12 | } 13 | 14 | interface Component extends MVPContract.Component {} 15 | } -------------------------------------------------------------------------------- /dagger-mvp/src/main/java/be/vergauwen/simon/daggermvp/ui/TestPresenter.java: -------------------------------------------------------------------------------- 1 | package be.vergauwen.simon.daggermvp.ui; 2 | 3 | import android.content.Context; 4 | import android.util.Log; 5 | import be.vergauwen.simon.himura.MVPPresenter; 6 | import javax.inject.Inject; 7 | 8 | public class TestPresenter extends MVPPresenter 9 | implements TestContract.Presenter { 10 | 11 | private Context context; 12 | 13 | @Inject 14 | public TestPresenter(Context context) { 15 | this.context = context; 16 | } 17 | 18 | @Override 19 | public void attachView(TestContract.View view) { 20 | super.attachView(view); 21 | } 22 | 23 | @Override 24 | public void loadThings() { 25 | Log.e("TestPresenter", ".loadThings()"); 26 | getView().showThings(); 27 | } 28 | } -------------------------------------------------------------------------------- /dagger-mvp/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomisRev/AndroidCleanMVP/61254c4d5df07fc7c72b8826f428bd09761a8f0e/dagger-mvp/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /dagger-mvp/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomisRev/AndroidCleanMVP/61254c4d5df07fc7c72b8826f428bd09761a8f0e/dagger-mvp/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /dagger-mvp/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomisRev/AndroidCleanMVP/61254c4d5df07fc7c72b8826f428bd09761a8f0e/dagger-mvp/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /dagger-mvp/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomisRev/AndroidCleanMVP/61254c4d5df07fc7c72b8826f428bd09761a8f0e/dagger-mvp/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /dagger-mvp/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomisRev/AndroidCleanMVP/61254c4d5df07fc7c72b8826f428bd09761a8f0e/dagger-mvp/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /dagger-mvp/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /dagger-mvp/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | DaggerMVP 3 | 4 | -------------------------------------------------------------------------------- /dagger-mvp/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /dagger-mvp/src/test/java/be/vergauwen/simon/daggermvp/RobolectricUnitTestRunner.java: -------------------------------------------------------------------------------- 1 | package be.vergauwen.simon.daggermvp; 2 | 3 | import android.support.annotation.NonNull; 4 | import java.lang.reflect.Method; 5 | import org.robolectric.RobolectricGradleTestRunner; 6 | import org.robolectric.annotation.Config; 7 | 8 | // Custom runner allows us set config in one place instead of setting it in each test class. 9 | public class RobolectricUnitTestRunner extends RobolectricGradleTestRunner { 10 | 11 | // This value should be changed as soon as Robolectric will support newer api. 12 | private static final int SDK_EMULATE_LEVEL = 21; 13 | 14 | public RobolectricUnitTestRunner(@NonNull Class aClass) throws Exception { 15 | super(aClass); 16 | } 17 | 18 | @Override 19 | public Config getConfig(@NonNull Method method) { 20 | final Config defaultConfig = super.getConfig(method); 21 | return new Config.Implementation( 22 | new int[]{SDK_EMULATE_LEVEL}, 23 | defaultConfig.manifest(), 24 | defaultConfig.qualifiers(), 25 | defaultConfig.packageName(), 26 | defaultConfig.resourceDir(), 27 | defaultConfig.assetDir(), 28 | defaultConfig.shadows(), 29 | MVPApplication.class, // Notice that we override real application class for Unit tests. 30 | defaultConfig.libraries(), 31 | defaultConfig.constants() == Void.class ? BuildConfig.class : defaultConfig.constants() 32 | ); 33 | } 34 | } -------------------------------------------------------------------------------- /dagger-mvp/src/test/java/be/vergauwen/simon/daggermvp/ui/TestActivityTest.java: -------------------------------------------------------------------------------- 1 | package be.vergauwen.simon.daggermvp.ui; 2 | 3 | import android.app.Activity; 4 | import be.vergauwen.simon.daggermvp.BuildConfig; 5 | import be.vergauwen.simon.daggermvp.RobolectricUnitTestRunner; 6 | import org.junit.Before; 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | import org.robolectric.Robolectric; 10 | import org.robolectric.annotation.Config; 11 | 12 | import static org.junit.Assert.assertFalse; 13 | import static org.junit.Assert.assertNotNull; 14 | import static org.junit.Assert.assertTrue; 15 | 16 | @RunWith(RobolectricUnitTestRunner.class) 17 | @Config(constants = BuildConfig.class) 18 | public class TestActivityTest { 19 | 20 | @Before 21 | public void setUp() throws Exception {} 22 | 23 | @Test 24 | public void preConditions() throws Exception { 25 | Activity activity = Robolectric.buildActivity(TestActivity.class).get(); 26 | assertNotNull(activity); 27 | } 28 | 29 | @Test 30 | public void testPresenterAfterOnCreate() throws Exception { 31 | TestActivity activity = Robolectric.buildActivity(TestActivity.class).create().get(); 32 | assertNotNull(activity.getPresenter()); 33 | } 34 | 35 | @Test 36 | public void testPresenter() throws Exception { 37 | TestActivity activity = Robolectric.buildActivity(TestActivity.class).create().get(); 38 | assertFalse(activity.isThingsShown()); 39 | activity.showThings(); 40 | assertTrue(activity.isThingsShown()); 41 | } 42 | 43 | @Test 44 | public void testOnResume() throws Exception { 45 | TestActivity activity = 46 | Robolectric.buildActivity(TestActivity.class).create().start().resume().get(); 47 | assertTrue(activity.isThingsShown()); 48 | } 49 | 50 | @Test 51 | public void testOnDestroy() throws Exception { 52 | TestActivity activity = Robolectric.buildActivity(TestActivity.class) 53 | .create() 54 | .start() 55 | .resume() 56 | .pause() 57 | .stop() 58 | .destroy() 59 | .get(); 60 | assertTrue(activity.isDestroyed()); 61 | } 62 | } -------------------------------------------------------------------------------- /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 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomisRev/AndroidCleanMVP/61254c4d5df07fc7c72b8826f428bd09761a8f0e/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Dec 28 10:00:20 PST 2015 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-2.10-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /himura-kt/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /himura-kt/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'kotlin-android' 3 | 4 | android { 5 | compileSdkVersion 23 6 | buildToolsVersion "23.0.2" 7 | 8 | defaultConfig { 9 | minSdkVersion 7 10 | targetSdkVersion 23 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | sourceSets { 21 | main.java.srcDirs += 'src/main/kotlin' 22 | } 23 | } 24 | 25 | dependencies { 26 | compile fileTree(dir: 'libs', include: ['*.jar']) 27 | provided 'com.android.support:appcompat-v7:23.3.0' 28 | provided "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" 29 | provided "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" 30 | } 31 | -------------------------------------------------------------------------------- /himura-kt/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/simonvergauwen/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /himura-kt/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /himura-kt/src/main/kotlin/be/vergauwen/simon/himurakotlin/MVPActivity.kt: -------------------------------------------------------------------------------- 1 | package be.vergauwen.simon.himurakotlin 2 | 3 | import android.os.Bundle 4 | import android.support.v7.app.AppCompatActivity 5 | 6 | abstract class MVPActivity> : AppCompatActivity(), MVPContract.View { 7 | 8 | protected val presenter: P by lazy { createPresenter() } 9 | protected abstract fun createPresenter(): P 10 | 11 | //This happens under the hood in java. 12 | @Suppress("UNCHECKED_CAST") 13 | override fun onCreate(savedInstanceState: Bundle?) { 14 | super.onCreate(savedInstanceState) 15 | presenter.attachView(this as V) 16 | } 17 | 18 | override fun onDestroy() { 19 | super.onDestroy() 20 | presenter.detachView() 21 | } 22 | } -------------------------------------------------------------------------------- /himura-kt/src/main/kotlin/be/vergauwen/simon/himurakotlin/MVPContract.kt: -------------------------------------------------------------------------------- 1 | package be.vergauwen.simon.himurakotlin 2 | 3 | interface MVPContract { 4 | interface View 5 | 6 | interface Presenter { 7 | fun getView(): V? 8 | fun attachView(view: V) 9 | fun detachView() 10 | } 11 | 12 | interface Component> { 13 | fun presenter(): P 14 | } 15 | } -------------------------------------------------------------------------------- /himura-kt/src/main/kotlin/be/vergauwen/simon/himurakotlin/MVPDaggerActivity.kt: -------------------------------------------------------------------------------- 1 | package be.vergauwen.simon.himurakotlin 2 | 3 | import android.os.Bundle 4 | import android.support.v7.app.AppCompatActivity 5 | 6 | abstract class MVPDaggerActivity, 7 | C : MVPContract.Component> : AppCompatActivity(), MVPContract.View { 8 | 9 | protected val presenter: P by lazy { component.presenter() } 10 | protected val component: C by lazy { createComponent() } 11 | 12 | protected abstract fun createComponent(): C 13 | 14 | //This happens under the hood in java. 15 | @Suppress("UNCHECKED_CAST") 16 | override fun onCreate(savedInstanceState: Bundle?) { 17 | super.onCreate(savedInstanceState) 18 | presenter.attachView(this as V) 19 | } 20 | 21 | override fun onDestroy() { 22 | super.onDestroy() 23 | presenter.detachView() 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /himura-kt/src/main/kotlin/be/vergauwen/simon/himurakotlin/MVPPresenter.kt: -------------------------------------------------------------------------------- 1 | package be.vergauwen.simon.himurakotlin 2 | 3 | import java.lang.ref.WeakReference 4 | 5 | 6 | abstract class MVPPresenter : MVPContract.Presenter { 7 | private var viewRef: WeakReference? = null 8 | 9 | override fun getView(): V? = if (viewRef == null) null else viewRef?.get() 10 | 11 | override fun attachView(view: V) { 12 | viewRef = WeakReference(view) 13 | } 14 | 15 | override fun detachView() { 16 | viewRef?.clear() 17 | viewRef = null 18 | } 19 | } -------------------------------------------------------------------------------- /himura-kt/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Himura Kotlin 3 | 4 | -------------------------------------------------------------------------------- /himura/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /himura/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.2" 6 | 7 | defaultConfig { 8 | minSdkVersion 7 9 | targetSdkVersion 23 10 | versionCode 1 11 | versionName "1.0" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | compile fileTree(dir: 'libs', include: ['*.jar']) 23 | provided 'com.android.support:appcompat-v7:23.3.0' 24 | } 25 | -------------------------------------------------------------------------------- /himura/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/simonvergauwen/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /himura/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /himura/src/main/java/be/vergauwen/simon/himura/MVPActivity.java: -------------------------------------------------------------------------------- 1 | package be.vergauwen.simon.himura; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | 6 | public abstract class MVPActivity

extends AppCompatActivity 7 | implements MVPContract.View { 8 | 9 | protected P presenter; 10 | 11 | protected abstract P createPresenter(); 12 | 13 | @Override 14 | @SuppressWarnings("unchecked") 15 | protected void onCreate(Bundle savedInstanceState) { 16 | super.onCreate(savedInstanceState); 17 | presenter = createPresenter(); 18 | presenter.attachView(this); 19 | } 20 | 21 | @Override 22 | protected void onDestroy() { 23 | presenter.detachView(); 24 | super.onDestroy(); 25 | } 26 | } -------------------------------------------------------------------------------- /himura/src/main/java/be/vergauwen/simon/himura/MVPContract.java: -------------------------------------------------------------------------------- 1 | package be.vergauwen.simon.himura; 2 | 3 | public interface MVPContract { 4 | interface View {} 5 | 6 | interface Presenter { 7 | V getView(); 8 | void attachView(V view); 9 | void detachView(); 10 | } 11 | 12 | interface Component

{ 13 | P presenter(); 14 | } 15 | } -------------------------------------------------------------------------------- /himura/src/main/java/be/vergauwen/simon/himura/MVPDaggerActivity.java: -------------------------------------------------------------------------------- 1 | package be.vergauwen.simon.himura; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | 6 | public abstract class MVPDaggerActivity

> 7 | extends AppCompatActivity implements MVPContract.View { 8 | protected P presenter; 9 | protected C component; 10 | 11 | protected abstract void createComponent(); 12 | 13 | protected P createPresenter() { 14 | return component.presenter(); 15 | } 16 | 17 | @Override 18 | @SuppressWarnings("unchecked") 19 | protected void onCreate(Bundle savedInstanceState) { 20 | super.onCreate(savedInstanceState); 21 | createComponent(); 22 | presenter = createPresenter(); 23 | presenter.attachView(this); 24 | } 25 | 26 | @Override 27 | protected void onDestroy() { 28 | super.onDestroy(); 29 | presenter.detachView(); 30 | } 31 | } 32 | 33 | -------------------------------------------------------------------------------- /himura/src/main/java/be/vergauwen/simon/himura/MVPPresenter.java: -------------------------------------------------------------------------------- 1 | package be.vergauwen.simon.himura; 2 | 3 | import java.lang.ref.WeakReference; 4 | 5 | public abstract class MVPPresenter implements MVPContract.Presenter { 6 | private WeakReference viewRef; 7 | 8 | @Override 9 | public V getView() { 10 | return viewRef == null ? null : viewRef.get(); 11 | } 12 | 13 | @Override 14 | public void attachView(V view) { 15 | viewRef = new WeakReference<>(view); 16 | } 17 | 18 | @Override 19 | public void detachView() { 20 | if (viewRef != null) { 21 | viewRef.clear(); 22 | viewRef = null; 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /himura/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Himura 3 | 4 | -------------------------------------------------------------------------------- /kotlin-dagger-mvp/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /kotlin-dagger-mvp/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'kotlin-android' 3 | apply plugin: 'kotlin-android-extensions' 4 | 5 | android { 6 | compileSdkVersion 23 7 | buildToolsVersion "23.0.2" 8 | 9 | defaultConfig { 10 | applicationId "be.vergauwen.simon.kotlindaggermvp" 11 | minSdkVersion 7 12 | targetSdkVersion 23 13 | versionCode 1 14 | versionName "1.0" 15 | } 16 | buildTypes { 17 | release { 18 | minifyEnabled false 19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 20 | } 21 | } 22 | sourceSets { 23 | main.java.srcDirs += 'src/main/kotlin' 24 | test.java.srcDirs += 'src/test/kotlin' 25 | } 26 | } 27 | 28 | kapt { 29 | generateStubs = true 30 | } 31 | 32 | dependencies { 33 | compile fileTree(dir: 'libs', include: ['*.jar']) 34 | compile project(':himura-kt') 35 | 36 | testCompile('junit:junit:4.12', "org.robolectric:robolectric:3.0") 37 | 38 | compile 'com.android.support:appcompat-v7:23.3.0' 39 | compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" 40 | 41 | compile 'com.google.dagger:dagger:2.0' 42 | kapt 'com.google.dagger:dagger-compiler:2.0' 43 | compile 'javax.annotation:jsr250-api:1.0' 44 | } 45 | -------------------------------------------------------------------------------- /kotlin-dagger-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 /Users/simonvergauwen/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /kotlin-dagger-mvp/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /kotlin-dagger-mvp/src/main/kotlin/be/vergauwen/simon/kotlindaggermvp/MVPApplication.kt: -------------------------------------------------------------------------------- 1 | package be.vergauwen.simon.kotlindaggermvp 2 | 3 | import android.app.Application 4 | import be.vergauwen.simon.kotlindaggermvp.di.ApplicationComponent 5 | import be.vergauwen.simon.kotlindaggermvp.di.ApplicationModule 6 | import be.vergauwen.simon.kotlindaggermvp.di.DaggerApplicationComponent 7 | 8 | internal class MVPApplication : Application() { 9 | 10 | companion object { 11 | @JvmStatic lateinit var component: ApplicationComponent 12 | } 13 | 14 | override fun onCreate() { 15 | super.onCreate() 16 | 17 | component = DaggerApplicationComponent.builder() 18 | .applicationModule(ApplicationModule(this)) 19 | .build() 20 | } 21 | } -------------------------------------------------------------------------------- /kotlin-dagger-mvp/src/main/kotlin/be/vergauwen/simon/kotlindaggermvp/di/ActivityScope.kt: -------------------------------------------------------------------------------- 1 | package be.vergauwen.simon.kotlindaggermvp.di 2 | 3 | import javax.inject.Scope 4 | 5 | @Scope 6 | @kotlin.annotation.Retention 7 | annotation class ActivityScope -------------------------------------------------------------------------------- /kotlin-dagger-mvp/src/main/kotlin/be/vergauwen/simon/kotlindaggermvp/di/ApplicationComponent.kt: -------------------------------------------------------------------------------- 1 | package be.vergauwen.simon.kotlindaggermvp.di 2 | 3 | import android.content.Context 4 | import dagger.Component 5 | 6 | @ApplicationScope 7 | @Component(modules = arrayOf(ApplicationModule::class)) 8 | interface ApplicationComponent { 9 | val applicationContext: Context 10 | } -------------------------------------------------------------------------------- /kotlin-dagger-mvp/src/main/kotlin/be/vergauwen/simon/kotlindaggermvp/di/ApplicationModule.kt: -------------------------------------------------------------------------------- 1 | package be.vergauwen.simon.kotlindaggermvp.di 2 | 3 | import android.app.Application 4 | import android.content.Context 5 | import dagger.Module 6 | import dagger.Provides 7 | 8 | @Module 9 | class ApplicationModule(private val application: Application) { 10 | 11 | @ApplicationScope 12 | @Provides 13 | fun provideApplicationContext(): Context { 14 | return application 15 | } 16 | } -------------------------------------------------------------------------------- /kotlin-dagger-mvp/src/main/kotlin/be/vergauwen/simon/kotlindaggermvp/di/ApplicationScope.kt: -------------------------------------------------------------------------------- 1 | package be.vergauwen.simon.kotlindaggermvp.di 2 | 3 | import javax.inject.Scope 4 | 5 | @Scope 6 | @kotlin.annotation.Retention 7 | annotation class ApplicationScope -------------------------------------------------------------------------------- /kotlin-dagger-mvp/src/main/kotlin/be/vergauwen/simon/kotlindaggermvp/ui/TestActivity.kt: -------------------------------------------------------------------------------- 1 | package be.vergauwen.simon.kotlindaggermvp.ui 2 | 3 | import android.os.Bundle 4 | import android.util.Log 5 | import be.vergauwen.simon.himurakotlin.MVPDaggerActivity 6 | import be.vergauwen.simon.kotlindaggermvp.MVPApplication 7 | 8 | class TestActivity : MVPDaggerActivity(), TestContract.View { 9 | 10 | var isThingsShown = false 11 | private set 12 | 13 | override fun createComponent(): TestComponent = 14 | DaggerTestComponent.builder().applicationComponent(MVPApplication.component).build() 15 | 16 | override fun onCreate(savedInstanceState: Bundle?) { 17 | super.onCreate(savedInstanceState) 18 | Log.e("TestActivity", "onCreate()") 19 | } 20 | 21 | override fun onResume() { 22 | super.onResume() 23 | presenter.loadThings() 24 | } 25 | 26 | override fun onDestroy() { 27 | Log.e("TestActivity", "onDestroy()") 28 | super.onDestroy() 29 | 30 | } 31 | 32 | override fun showThings() { 33 | Log.e("TestActivity", ".showThings()") 34 | isThingsShown = true 35 | } 36 | 37 | fun presenterLoadThings() { 38 | presenter.loadThings() 39 | } 40 | 41 | fun testPresenterNotNull(): Boolean { 42 | return presenter != null; 43 | } 44 | } -------------------------------------------------------------------------------- /kotlin-dagger-mvp/src/main/kotlin/be/vergauwen/simon/kotlindaggermvp/ui/TestComponent.kt: -------------------------------------------------------------------------------- 1 | package be.vergauwen.simon.kotlindaggermvp.ui 2 | 3 | import be.vergauwen.simon.kotlindaggermvp.di.ActivityScope 4 | import be.vergauwen.simon.kotlindaggermvp.di.ApplicationComponent 5 | import dagger.Component 6 | 7 | @ActivityScope 8 | @Component(dependencies = arrayOf(ApplicationComponent::class)) 9 | interface TestComponent : TestContract.Component { 10 | override fun presenter(): TestPresenter 11 | } -------------------------------------------------------------------------------- /kotlin-dagger-mvp/src/main/kotlin/be/vergauwen/simon/kotlindaggermvp/ui/TestContract.kt: -------------------------------------------------------------------------------- 1 | package be.vergauwen.simon.kotlindaggermvp.ui 2 | 3 | import be.vergauwen.simon.himurakotlin.MVPContract 4 | 5 | interface TestContract { 6 | interface View : MVPContract.View { 7 | fun showThings() 8 | } 9 | 10 | interface Presenter : MVPContract.Presenter { 11 | fun loadThings() 12 | } 13 | 14 | interface Component> : MVPContract.Component 15 | } -------------------------------------------------------------------------------- /kotlin-dagger-mvp/src/main/kotlin/be/vergauwen/simon/kotlindaggermvp/ui/TestPresenter.kt: -------------------------------------------------------------------------------- 1 | package be.vergauwen.simon.kotlindaggermvp.ui 2 | 3 | import android.content.Context 4 | import android.util.Log 5 | import be.vergauwen.simon.himurakotlin.MVPPresenter 6 | import javax.inject.Inject 7 | 8 | 9 | class TestPresenter 10 | @Inject 11 | constructor(private val context: Context) : MVPPresenter(), TestContract.Presenter { 12 | 13 | override fun loadThings() { 14 | Log.e("TestPresenter", ".loadThings()") 15 | getView()?.showThings() 16 | } 17 | } -------------------------------------------------------------------------------- /kotlin-dagger-mvp/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomisRev/AndroidCleanMVP/61254c4d5df07fc7c72b8826f428bd09761a8f0e/kotlin-dagger-mvp/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /kotlin-dagger-mvp/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomisRev/AndroidCleanMVP/61254c4d5df07fc7c72b8826f428bd09761a8f0e/kotlin-dagger-mvp/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /kotlin-dagger-mvp/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomisRev/AndroidCleanMVP/61254c4d5df07fc7c72b8826f428bd09761a8f0e/kotlin-dagger-mvp/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /kotlin-dagger-mvp/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomisRev/AndroidCleanMVP/61254c4d5df07fc7c72b8826f428bd09761a8f0e/kotlin-dagger-mvp/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /kotlin-dagger-mvp/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomisRev/AndroidCleanMVP/61254c4d5df07fc7c72b8826f428bd09761a8f0e/kotlin-dagger-mvp/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /kotlin-dagger-mvp/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /kotlin-dagger-mvp/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Kotlin Dagger MVP 3 | 4 | -------------------------------------------------------------------------------- /kotlin-dagger-mvp/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /kotlin-dagger-mvp/src/test/kotlin/be/vergauwen/simon/kotlindaggermvp/ui/TestActivityTest.kt: -------------------------------------------------------------------------------- 1 | package be.vergauwen.simon.kotlindaggermvp.ui 2 | 3 | import be.vergauwen.simon.kotlindaggermvp.BuildConfig 4 | import org.junit.Assert.assertFalse 5 | import org.junit.Assert.assertTrue 6 | import org.junit.Before 7 | import org.junit.Test 8 | import org.junit.runner.RunWith 9 | import org.robolectric.Robolectric 10 | import org.robolectric.RobolectricGradleTestRunner 11 | import org.robolectric.annotation.Config 12 | 13 | @RunWith(RobolectricGradleTestRunner::class) 14 | @Config(constants = BuildConfig::class , sdk = intArrayOf(21)) 15 | class TestActivityTest { 16 | 17 | @Before 18 | fun setUp() { } 19 | 20 | @Test 21 | fun preConditions() { 22 | val activity = Robolectric.buildActivity(TestActivity::class.java).get() 23 | assertFalse(activity.isThingsShown) 24 | } 25 | 26 | @Test 27 | fun testPresenterLazyAssignment() { 28 | val activity = Robolectric.buildActivity(TestActivity::class.java).get() 29 | assertTrue(activity.testPresenterNotNull()) 30 | } 31 | 32 | @Test 33 | fun testShowThings() { 34 | val activity = Robolectric.buildActivity(TestActivity::class.java).create().get() 35 | assertFalse(activity.isThingsShown) 36 | activity.showThings() 37 | assertTrue(activity.isThingsShown) 38 | } 39 | 40 | @Test 41 | fun testPresenterLoadThings() { 42 | val activity = Robolectric.buildActivity(TestActivity::class.java).create().get() 43 | assertFalse(activity.isThingsShown) 44 | activity.presenterLoadThings() 45 | assertTrue(activity.isThingsShown) 46 | } 47 | 48 | @Test 49 | fun testOnResume() { 50 | val activity = Robolectric.buildActivity( 51 | TestActivity::class.java).create().start().resume().get() 52 | assertTrue(activity.isThingsShown) 53 | } 54 | 55 | @Test 56 | fun testOnDestroy() { 57 | val activity = Robolectric.buildActivity( 58 | TestActivity::class.java).create().start().resume().pause().stop().destroy().get() 59 | assertTrue(activity.isDestroyed) 60 | } 61 | } -------------------------------------------------------------------------------- /kotlin-vanilla-mvp/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /kotlin-vanilla-mvp/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'kotlin-android' 3 | 4 | android { 5 | compileSdkVersion 23 6 | buildToolsVersion "23.0.2" 7 | 8 | defaultConfig { 9 | applicationId "be.vergauwen.simon.kotlinvanillamvp" 10 | minSdkVersion 7 11 | targetSdkVersion 23 12 | versionCode 1 13 | versionName "1.0" 14 | } 15 | buildTypes { 16 | release { 17 | minifyEnabled false 18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 19 | } 20 | } 21 | sourceSets { 22 | main.java.srcDirs += 'src/main/kotlin' 23 | test.java.srcDirs += 'src/test/kotlin' 24 | } 25 | } 26 | 27 | dependencies { 28 | compile fileTree(dir: 'libs', include: ['*.jar']) 29 | compile project(':himura-kt') 30 | 31 | testCompile('junit:junit:4.12', "org.robolectric:robolectric:3.0") 32 | 33 | compile 'com.android.support:appcompat-v7:23.3.0' 34 | compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" 35 | } 36 | -------------------------------------------------------------------------------- /kotlin-vanilla-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 /Users/simonvergauwen/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /kotlin-vanilla-mvp/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /kotlin-vanilla-mvp/src/main/kotlin/be/vergauwen/simon/kotlinvanillamvp/MVPApplication.kt: -------------------------------------------------------------------------------- 1 | package be.vergauwen.simon.kotlinvanillamvp 2 | 3 | import android.app.Application 4 | 5 | class MVPApplication : Application() -------------------------------------------------------------------------------- /kotlin-vanilla-mvp/src/main/kotlin/be/vergauwen/simon/kotlinvanillamvp/ui/TestActivity.kt: -------------------------------------------------------------------------------- 1 | package be.vergauwen.simon.kotlinvanillamvp.ui 2 | 3 | import android.os.Bundle 4 | import android.util.Log 5 | import be.vergauwen.simon.himurakotlin.MVPActivity 6 | 7 | class TestActivity : MVPActivity(), TestContract.View { 8 | 9 | ////////////////////////////////////////////////////////////////////////////////////////////////// 10 | // MVPAppCompatActivity Impl 11 | override fun createPresenter(): TestPresenter { 12 | return TestPresenter() 13 | } 14 | 15 | ////////////////////////////////////////////////////////////////////////////////////////////////// 16 | // TestActivity Impl 17 | 18 | override fun onCreate(savedInstanceState: Bundle?) { 19 | super.onCreate(savedInstanceState) 20 | Log.e("TestActivity", "onCreate()") 21 | } 22 | 23 | override fun onResume() { 24 | super.onResume() 25 | presenter.loadThings() 26 | } 27 | 28 | override fun onDestroy() { 29 | Log.e("TestActivity", "onDestroy()") 30 | super.onDestroy() 31 | } 32 | 33 | ////////////////////////////////////////////////////////////////////////////////////////////////// 34 | // TestContract.View Impl 35 | 36 | override fun showThings() { 37 | Log.e("TestActivity", ".showThings()") 38 | isThingsShown = true 39 | } 40 | 41 | ////////////////////////////////////////////////////////////////////////////////////////////////// 42 | // For testing purpose only!!! When using this lib in the future you may assume this works!! 43 | 44 | var isThingsShown = false 45 | private set 46 | 47 | @Suppress("SENSELESS_COMPARISON") //Useless in kotlin => lazy assignment 48 | fun testPresenterNotNull() : Boolean{ 49 | return presenter != null; 50 | } 51 | 52 | fun presenterLoadThings() { 53 | presenter.loadThings() 54 | } 55 | } -------------------------------------------------------------------------------- /kotlin-vanilla-mvp/src/main/kotlin/be/vergauwen/simon/kotlinvanillamvp/ui/TestContract.kt: -------------------------------------------------------------------------------- 1 | package be.vergauwen.simon.kotlinvanillamvp.ui 2 | 3 | import be.vergauwen.simon.himurakotlin.MVPContract 4 | 5 | 6 | interface TestContract{ 7 | interface View : MVPContract.View{ 8 | fun showThings() 9 | } 10 | 11 | interface Presenter : MVPContract.Presenter{ 12 | fun loadThings() 13 | } 14 | } -------------------------------------------------------------------------------- /kotlin-vanilla-mvp/src/main/kotlin/be/vergauwen/simon/kotlinvanillamvp/ui/TestPresenter.kt: -------------------------------------------------------------------------------- 1 | package be.vergauwen.simon.kotlinvanillamvp.ui 2 | 3 | import android.util.Log 4 | import be.vergauwen.simon.himurakotlin.MVPPresenter 5 | 6 | class TestPresenter : MVPPresenter(), TestContract.Presenter { 7 | 8 | ////////////////////////////////////////////////////////////////////////////////////////////////// 9 | // TestContract.Presenter Impl 10 | 11 | override fun loadThings() { 12 | Log.e("TestPresenter", ".loadThings()") 13 | getView()?.showThings() 14 | } 15 | } -------------------------------------------------------------------------------- /kotlin-vanilla-mvp/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomisRev/AndroidCleanMVP/61254c4d5df07fc7c72b8826f428bd09761a8f0e/kotlin-vanilla-mvp/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /kotlin-vanilla-mvp/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomisRev/AndroidCleanMVP/61254c4d5df07fc7c72b8826f428bd09761a8f0e/kotlin-vanilla-mvp/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /kotlin-vanilla-mvp/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomisRev/AndroidCleanMVP/61254c4d5df07fc7c72b8826f428bd09761a8f0e/kotlin-vanilla-mvp/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /kotlin-vanilla-mvp/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomisRev/AndroidCleanMVP/61254c4d5df07fc7c72b8826f428bd09761a8f0e/kotlin-vanilla-mvp/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /kotlin-vanilla-mvp/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomisRev/AndroidCleanMVP/61254c4d5df07fc7c72b8826f428bd09761a8f0e/kotlin-vanilla-mvp/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /kotlin-vanilla-mvp/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /kotlin-vanilla-mvp/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Kotlin Vanilla MVP 3 | 4 | -------------------------------------------------------------------------------- /kotlin-vanilla-mvp/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /kotlin-vanilla-mvp/src/test/kotlin/be/vergauwen/simon/kotlinvanillamvp/ui/TestActivityTest.kt: -------------------------------------------------------------------------------- 1 | package be.vergauwen.simon.kotlinvanillamvp.ui 2 | 3 | import be.vergauwen.simon.kotlinvanillamvp.BuildConfig 4 | import org.junit.Assert.assertFalse 5 | import org.junit.Assert.assertTrue 6 | import org.junit.Before 7 | import org.junit.Test 8 | import org.junit.runner.RunWith 9 | import org.robolectric.Robolectric 10 | import org.robolectric.RobolectricGradleTestRunner 11 | import org.robolectric.annotation.Config 12 | 13 | @RunWith(RobolectricGradleTestRunner::class) 14 | @Config(constants = BuildConfig::class , sdk = intArrayOf(21)) 15 | class TestActivityTest { 16 | 17 | @Before 18 | fun setUp() { } 19 | 20 | @Test 21 | fun preConditions() { 22 | val activity = Robolectric.buildActivity(TestActivity::class.java).get() 23 | assertFalse(activity.isThingsShown) 24 | } 25 | 26 | @Test 27 | fun testPresenterLazyAssignment() { 28 | val activity = Robolectric.buildActivity(TestActivity::class.java).get() 29 | assertTrue(activity.testPresenterNotNull()) 30 | } 31 | 32 | @Test 33 | fun testShowThings() { 34 | val activity = Robolectric.buildActivity(TestActivity::class.java).create().get() 35 | assertFalse(activity.isThingsShown) 36 | activity.showThings() 37 | assertTrue(activity.isThingsShown) 38 | } 39 | 40 | @Test 41 | fun testPresenterLoadThings() { 42 | val activity = Robolectric.buildActivity(TestActivity::class.java).create().get() 43 | assertFalse(activity.isThingsShown) 44 | activity.presenterLoadThings() 45 | assertTrue(activity.isThingsShown) 46 | } 47 | 48 | @Test 49 | fun testOnResume() { 50 | val activity = Robolectric.buildActivity( 51 | TestActivity::class.java).create().start().resume().get() 52 | assertTrue(activity.isThingsShown) 53 | } 54 | 55 | @Test 56 | fun testOnDestroy() { 57 | val activity = Robolectric.buildActivity( 58 | TestActivity::class.java).create().start().resume().pause().stop().destroy().get() 59 | assertTrue(activity.isDestroyed) 60 | } 61 | } -------------------------------------------------------------------------------- /save&restore-state.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomisRev/AndroidCleanMVP/61254c4d5df07fc7c72b8826f428bd09761a8f0e/save&restore-state.png -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':vanilla-mvp', ':himura', ':dagger-mvp', ':himura-kt', ':kotlin-vanilla-mvp', 2 | ':kotlin-dagger-mvp' 3 | -------------------------------------------------------------------------------- /vanilla-mvp/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /vanilla-mvp/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.2" 6 | 7 | defaultConfig { 8 | applicationId "be.vergauwen.simon.cleanmvp" 9 | minSdkVersion 18 10 | targetSdkVersion 23 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | compile project(':himura') 25 | 26 | testCompile('junit:junit:4.12', "org.robolectric:robolectric:3.0") 27 | 28 | compile 'com.android.support:appcompat-v7:23.3.0' 29 | } 30 | -------------------------------------------------------------------------------- /vanilla-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 /Users/simonvergauwen/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /vanilla-mvp/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /vanilla-mvp/src/main/java/be/vergauwen/simon/cleanmvp/MVPApplication.java: -------------------------------------------------------------------------------- 1 | package be.vergauwen.simon.cleanmvp; 2 | 3 | import android.app.Application; 4 | 5 | public class MVPApplication extends Application { 6 | 7 | @Override 8 | public void onCreate() { 9 | super.onCreate(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /vanilla-mvp/src/main/java/be/vergauwen/simon/cleanmvp/ui/TestActivity.java: -------------------------------------------------------------------------------- 1 | package be.vergauwen.simon.cleanmvp.ui; 2 | 3 | import android.os.Bundle; 4 | import android.util.Log; 5 | import be.vergauwen.simon.himura.MVPActivity; 6 | 7 | public class TestActivity extends MVPActivity implements TestContract.View { 8 | 9 | private final static String TAG = TestActivity.class.getName(); 10 | private boolean thingsShown = false; 11 | 12 | @Override 13 | protected TestPresenter createPresenter() { 14 | return new TestPresenter(); 15 | } 16 | 17 | @Override 18 | protected void onCreate(Bundle savedInstanceState) { 19 | super.onCreate(savedInstanceState); 20 | Log.e(TAG, "onCreate()"); 21 | } 22 | 23 | @Override 24 | protected void onResume() { 25 | super.onResume(); 26 | presenter.loadThings(); 27 | } 28 | 29 | @Override 30 | protected void onDestroy() { 31 | Log.e(TAG, "onDestroy()"); 32 | super.onDestroy(); 33 | } 34 | 35 | @Override 36 | public void showThings() { 37 | Log.e(TAG, ".showThings()"); 38 | thingsShown = true; 39 | } 40 | 41 | public boolean isThingsShown() { 42 | return thingsShown; 43 | } 44 | 45 | public TestPresenter getPresenter() { 46 | return presenter; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /vanilla-mvp/src/main/java/be/vergauwen/simon/cleanmvp/ui/TestContract.java: -------------------------------------------------------------------------------- 1 | package be.vergauwen.simon.cleanmvp.ui; 2 | 3 | import be.vergauwen.simon.himura.MVPContract; 4 | 5 | interface TestContract { 6 | interface View extends MVPContract.View { 7 | void showThings(); 8 | } 9 | 10 | interface Presenter extends MVPContract.Presenter { 11 | void loadThings(); 12 | } 13 | } -------------------------------------------------------------------------------- /vanilla-mvp/src/main/java/be/vergauwen/simon/cleanmvp/ui/TestPresenter.java: -------------------------------------------------------------------------------- 1 | package be.vergauwen.simon.cleanmvp.ui; 2 | 3 | import android.util.Log; 4 | import be.vergauwen.simon.himura.MVPPresenter; 5 | 6 | public class TestPresenter extends MVPPresenter 7 | implements TestContract.Presenter { 8 | 9 | @Override 10 | public void loadThings() { 11 | Log.e("TestPresenter",".loadThings()"); 12 | getView().showThings(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /vanilla-mvp/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /vanilla-mvp/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomisRev/AndroidCleanMVP/61254c4d5df07fc7c72b8826f428bd09761a8f0e/vanilla-mvp/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /vanilla-mvp/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomisRev/AndroidCleanMVP/61254c4d5df07fc7c72b8826f428bd09761a8f0e/vanilla-mvp/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /vanilla-mvp/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomisRev/AndroidCleanMVP/61254c4d5df07fc7c72b8826f428bd09761a8f0e/vanilla-mvp/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /vanilla-mvp/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomisRev/AndroidCleanMVP/61254c4d5df07fc7c72b8826f428bd09761a8f0e/vanilla-mvp/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /vanilla-mvp/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomisRev/AndroidCleanMVP/61254c4d5df07fc7c72b8826f428bd09761a8f0e/vanilla-mvp/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /vanilla-mvp/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /vanilla-mvp/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /vanilla-mvp/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /vanilla-mvp/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | CleanMVP 3 | 4 | -------------------------------------------------------------------------------- /vanilla-mvp/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /vanilla-mvp/src/test/java/be/vergauwen/simon/cleanmvp/RobolectricUnitTestRunner.java: -------------------------------------------------------------------------------- 1 | package be.vergauwen.simon.cleanmvp; 2 | 3 | import android.support.annotation.NonNull; 4 | import java.lang.reflect.Method; 5 | import org.robolectric.RobolectricGradleTestRunner; 6 | import org.robolectric.annotation.Config; 7 | 8 | // Custom runner allows us set config in one place instead of setting it in each test class. 9 | public class RobolectricUnitTestRunner extends RobolectricGradleTestRunner { 10 | 11 | // This value should be changed as soon as Robolectric will support newer api. 12 | private static final int SDK_EMULATE_LEVEL = 21; 13 | 14 | public RobolectricUnitTestRunner(@NonNull Class aClass) throws Exception { 15 | super(aClass); 16 | } 17 | 18 | @Override 19 | public Config getConfig(@NonNull Method method) { 20 | final Config defaultConfig = super.getConfig(method); 21 | return new Config.Implementation( 22 | new int[]{SDK_EMULATE_LEVEL}, 23 | defaultConfig.manifest(), 24 | defaultConfig.qualifiers(), 25 | defaultConfig.packageName(), 26 | defaultConfig.resourceDir(), 27 | defaultConfig.assetDir(), 28 | defaultConfig.shadows(), 29 | MVPApplication.class, // Notice that we override real application class for Unit tests. 30 | defaultConfig.libraries(), 31 | defaultConfig.constants() == Void.class ? BuildConfig.class : defaultConfig.constants() 32 | ); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /vanilla-mvp/src/test/java/be/vergauwen/simon/cleanmvp/ui/TestActivityTest.java: -------------------------------------------------------------------------------- 1 | package be.vergauwen.simon.cleanmvp.ui; 2 | 3 | import android.app.Activity; 4 | import be.vergauwen.simon.cleanmvp.BuildConfig; 5 | import be.vergauwen.simon.cleanmvp.RobolectricUnitTestRunner; 6 | import org.junit.Before; 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | import org.robolectric.Robolectric; 10 | import org.robolectric.annotation.Config; 11 | 12 | import static org.junit.Assert.assertFalse; 13 | import static org.junit.Assert.assertNotNull; 14 | import static org.junit.Assert.assertTrue; 15 | 16 | @RunWith(RobolectricUnitTestRunner.class) 17 | @Config(constants = BuildConfig.class) 18 | public class TestActivityTest { 19 | 20 | @Before 21 | public void setUp() throws Exception {} 22 | 23 | @Test 24 | public void preConditions() throws Exception { 25 | Activity activity = Robolectric.buildActivity(TestActivity.class).get(); 26 | assertNotNull(activity); 27 | } 28 | 29 | @Test 30 | public void testPresenterAfterOnCreate() throws Exception { 31 | TestActivity activity = Robolectric.buildActivity(TestActivity.class).create().get(); 32 | assertNotNull(activity.getPresenter()); 33 | } 34 | 35 | @Test 36 | public void testPresenter() throws Exception { 37 | TestActivity activity = Robolectric.buildActivity(TestActivity.class).create().get(); 38 | assertFalse(activity.isThingsShown()); 39 | activity.showThings(); 40 | assertTrue(activity.isThingsShown()); 41 | } 42 | 43 | @Test 44 | public void testOnResume() throws Exception { 45 | TestActivity activity = 46 | Robolectric.buildActivity(TestActivity.class).create().start().resume().get(); 47 | assertTrue(activity.isThingsShown()); 48 | } 49 | 50 | @Test 51 | public void testOnDestroy() throws Exception { 52 | TestActivity activity = Robolectric.buildActivity(TestActivity.class) 53 | .create() 54 | .start() 55 | .resume() 56 | .pause() 57 | .stop() 58 | .destroy() 59 | .get(); 60 | assertTrue(activity.isDestroyed()); 61 | } 62 | } 63 | --------------------------------------------------------------------------------