-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bfdfaf3
commit d451a31
Showing
32 changed files
with
873 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/libraries | ||
/.idea/modules.xml | ||
/.idea/workspace.xml | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild |
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
apply plugin: 'com.android.library' | ||
apply plugin: 'kotlin-android' | ||
|
||
android { | ||
compileSdkVersion 28 | ||
|
||
|
||
|
||
defaultConfig { | ||
minSdkVersion 15 | ||
targetSdkVersion 28 | ||
versionCode 1 | ||
versionName "1.0" | ||
|
||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
|
||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
|
||
} | ||
|
||
dependencies { | ||
implementation fileTree(dir: 'libs', include: ['*.jar']) | ||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
26 changes: 26 additions & 0 deletions
26
abstractMvp/src/androidTest/java/robertapikyan/com/abstractmvp/ExampleInstrumentedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package robertapikyan.com.abstractmvp; | ||
|
||
import android.content.Context; | ||
import android.support.test.InstrumentationRegistry; | ||
import android.support.test.runner.AndroidJUnit4; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> | ||
*/ | ||
@RunWith(AndroidJUnit4.class) | ||
public class ExampleInstrumentedTest { | ||
@Test | ||
public void useAppContext() { | ||
// Context of the app under test. | ||
Context appContext = InstrumentationRegistry.getTargetContext(); | ||
|
||
assertEquals("robertapikyan.com.abstractmvp.test", appContext.getPackageName()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<manifest package="robertapikyan.com.abstractmvp" /> |
88 changes: 88 additions & 0 deletions
88
abstractMvp/src/main/java/robertapikyan/com/abstractmvp/presentation/Mvp.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package com.robertapikyan.abstractmvp.presentation | ||
|
||
import com.robertapikyan.abstractmvp.presentation.presenter.IPresenterHolder | ||
import com.robertapikyan.abstractmvp.presentation.presenter.IPresenterLifecycleHandler | ||
import com.robertapikyan.abstractmvp.presentation.presenter.Presenter | ||
import com.robertapikyan.abstractmvp.presentation.presenter.PresenterProxy | ||
import com.robertapikyan.abstractmvp.presentation.view.IView | ||
import com.robertapikyan.abstractmvp.presentation.view.IViewActionDispatcher | ||
import com.robertapikyan.abstractmvp.presentation.view.IViewActionObserver | ||
import com.robertapikyan.abstractmvp.presentation.view.ViewHolder | ||
|
||
class Mvp { | ||
|
||
/** | ||
* One of the important interface for MVP library. | ||
* This is the starting point for MVP implementation | ||
* Inherit from this Factory, and provide your custom implementations | ||
* for IViewActionDispatcher, IViewActionObserver, IPresenterHolder, IPresenterLifecycleHandler ... | ||
*/ | ||
interface Factory<V : IView, P : Presenter<V>> { | ||
fun getView(): V | ||
fun getViewActionDispatcher(): IViewActionDispatcher<V> | ||
fun getViewActionObserver(): IViewActionObserver<V> | ||
fun getPresenter(): P | ||
fun getPresenterHolder(): IPresenterHolder<V, P> | ||
fun getPresenterLifecycleHandler(): IPresenterLifecycleHandler | ||
} | ||
|
||
companion object { | ||
/** | ||
* Use this method in order to receive your presenter instance | ||
* based on you Factory implementation | ||
*/ | ||
fun <V : IView, P : Presenter<V>> from(factory: Factory<V, P>): P { | ||
// View | ||
val view = factory.getView() | ||
val viewHolder = ViewHolder<V>() | ||
|
||
// Presenter | ||
val presenter by lazy { factory.getPresenter() } | ||
val presenterHolder = factory.getPresenterHolder() | ||
val presenterProxy by lazy { PresenterProxy(presenterHolder.get()) } | ||
val presenterLifecycleHandler by lazy { factory.getPresenterLifecycleHandler() } | ||
|
||
// Action dispatcher and observable | ||
val viewActionObserver = factory.getViewActionObserver() | ||
val viewActionDispatcher by lazy { factory.getViewActionDispatcher() } | ||
|
||
// holds state whatever presenter is created or restored | ||
val isPresenterCreated = !presenterHolder.hasPresenter() | ||
|
||
// if holder is empty, we create new presenter instance | ||
if (!presenterHolder.hasPresenter()) { | ||
presenterHolder.put(presenter) | ||
} | ||
|
||
// set the viewHolder instance, | ||
// in order to clear it when view scope is going to be destroyed | ||
presenterProxy.viewHolder = viewHolder | ||
|
||
viewHolder.putView(view) | ||
|
||
// pass the presenterProxy instance as PresenterLifecycle | ||
presenterLifecycleHandler.onCreate(presenterProxy) | ||
|
||
viewActionObserver.onCreate(viewHolder) | ||
|
||
// now if presenter is created we set viewActionObserver instance to viewActionDispatcher, | ||
// pass the viewActionDispatcher instance to presenter, | ||
// and call presenter.onCreate(). At this point presenter is ready | ||
if (isPresenterCreated) { | ||
viewActionDispatcher.setViewActionObserver(viewHolder, viewActionObserver) | ||
presenter._viewActionDispatcher = viewActionDispatcher | ||
presenter.onCreate() | ||
} else { | ||
// if presenter instance is restored, we just set viewActionObserver to viewActionDispatcher, | ||
// and call presenter.onRestore() | ||
presenterHolder.get() | ||
._viewActionDispatcher | ||
.setViewActionObserver(viewHolder, viewActionObserver) | ||
presenterHolder.get().onRestore() | ||
} | ||
|
||
// return the presenter instance | ||
return presenterHolder.get() | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...vp/src/main/java/robertapikyan/com/abstractmvp/presentation/presenter/IPresenterHolder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.robertapikyan.abstractmvp.presentation.presenter | ||
|
||
import com.robertapikyan.abstractmvp.presentation.view.IView | ||
|
||
/** | ||
* IPresenterHolder represent's holder container for Presenter instance, | ||
* It receive's presenter instance via put() method, and provide's the same instance | ||
* via get() method | ||
* The main point of this class is to inherit from android lifecycle persistence objects such as | ||
* Loaders and ViewModels and every time provide the same presenter instance | ||
*/ | ||
interface IPresenterHolder<V : IView, P : Presenter<V>> { | ||
fun hasPresenter(): Boolean | ||
fun put(presenter: P) | ||
fun get(): P | ||
} |
27 changes: 27 additions & 0 deletions
27
...src/main/java/robertapikyan/com/abstractmvp/presentation/presenter/IPresenterLifecycle.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.robertapikyan.abstractmvp.presentation.presenter | ||
|
||
/** | ||
* IPresenterLifecycle is Presenter lifecycle representation | ||
*/ | ||
interface IPresenterLifecycle { | ||
|
||
/** | ||
* onViewAttach, will be called with activity setViewActionObserver | ||
*/ | ||
fun onViewAttach() | ||
|
||
/** | ||
* onViewStop, will be called with activity onStart | ||
*/ | ||
fun onViewStart() | ||
|
||
/** | ||
* onViewStop, will be called with activity onStop | ||
*/ | ||
fun onViewStop() | ||
|
||
/** | ||
* onViewDetach, will be called with activity onDestroy | ||
*/ | ||
fun onViewDetach() | ||
} |
11 changes: 11 additions & 0 deletions
11
...n/java/robertapikyan/com/abstractmvp/presentation/presenter/IPresenterLifecycleHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.robertapikyan.abstractmvp.presentation.presenter | ||
|
||
/** | ||
* IPresenterLifecycleHandler is responsible for presenter lifecycle handling | ||
* Receive presenter lifecycle instance via setViewActionObserver method, | ||
* All lifecycle methods will be called by PresenterLifecycleHandler except Lifecycle::setViewActionObserver method, | ||
* this method will be called by MVP framework | ||
*/ | ||
interface IPresenterLifecycleHandler { | ||
fun onCreate(presenterLifecycle: IPresenterLifecycle) | ||
} |
Oops, something went wrong.