├── .gitignore ├── .idea ├── caches │ └── build_file_checksums.ser ├── codeStyles │ └── Project.xml ├── compiler.xml ├── encodings.xml ├── gradle.xml ├── jarRepositories.xml ├── misc.xml ├── runConfigurations.xml ├── shelf │ ├── Uncommitted_changes_before_Update_at_2_3_21_3_17_PM_[Default_Changelist] │ │ ├── build_file_checksums.ser │ │ └── shelved.patch │ └── Uncommitted_changes_before_Update_at_2_3_21_3_17_PM__Default_Changelist_.xml └── vcs.xml ├── LICENSE ├── README.md ├── abstractMvp ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ └── java │ └── robertapikyan │ └── com │ └── abstractmvp │ └── presentation │ ├── Mvp.kt │ ├── presenter │ ├── IPresenterHolder.kt │ ├── IPresenterLifecycle.kt │ ├── IPresenterLifecycleHandler.kt │ ├── Presenter.kt │ └── PresenterProxy.kt │ └── view │ ├── ActionType.kt │ ├── IView.kt │ ├── IViewAction.kt │ ├── IViewActionDispatcher.kt │ ├── IViewActionObserver.kt │ └── ViewHolder.kt ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/libraries 5 | /.idea/modules.xml 6 | /.idea/workspace.xml 7 | .DS_Store 8 | /build 9 | /captures 10 | .externalNativeBuild 11 | -------------------------------------------------------------------------------- /.idea/caches/build_file_checksums.ser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobertApikyan/AbstractMvp/b1c8edbc642efb0ec2afcb82c8c9e8f58dfc0134/.idea/caches/build_file_checksums.ser -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | xmlns:android 14 | 15 | ^$ 16 | 17 | 18 | 19 |
20 |
21 | 22 | 23 | 24 | xmlns:.* 25 | 26 | ^$ 27 | 28 | 29 | BY_NAME 30 | 31 |
32 |
33 | 34 | 35 | 36 | .*:id 37 | 38 | http://schemas.android.com/apk/res/android 39 | 40 | 41 | 42 |
43 |
44 | 45 | 46 | 47 | .*:name 48 | 49 | http://schemas.android.com/apk/res/android 50 | 51 | 52 | 53 |
54 |
55 | 56 | 57 | 58 | name 59 | 60 | ^$ 61 | 62 | 63 | 64 |
65 |
66 | 67 | 68 | 69 | style 70 | 71 | ^$ 72 | 73 | 74 | 75 |
76 |
77 | 78 | 79 | 80 | .* 81 | 82 | ^$ 83 | 84 | 85 | BY_NAME 86 | 87 |
88 |
89 | 90 | 91 | 92 | .* 93 | 94 | http://schemas.android.com/apk/res/android 95 | 96 | 97 | ANDROID_ATTRIBUTE_ORDER 98 | 99 |
100 |
101 | 102 | 103 | 104 | .* 105 | 106 | .* 107 | 108 | 109 | BY_NAME 110 | 111 |
112 |
113 |
114 |
115 |
116 |
-------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 22 | 23 | -------------------------------------------------------------------------------- /.idea/jarRepositories.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 14 | 15 | 19 | 20 | 24 | 25 | 29 | 30 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 37 | 38 | 39 | 40 | 41 | 42 | 44 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/shelf/Uncommitted_changes_before_Update_at_2_3_21_3_17_PM_[Default_Changelist]/build_file_checksums.ser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobertApikyan/AbstractMvp/b1c8edbc642efb0ec2afcb82c8c9e8f58dfc0134/.idea/shelf/Uncommitted_changes_before_Update_at_2_3_21_3_17_PM_[Default_Changelist]/build_file_checksums.ser -------------------------------------------------------------------------------- /.idea/shelf/Uncommitted_changes_before_Update_at_2_3_21_3_17_PM_[Default_Changelist]/shelved.patch: -------------------------------------------------------------------------------- 1 | Index: abstractMvp/build.gradle 2 | IDEA additional info: 3 | Subsystem: com.intellij.openapi.diff.impl.patch.BaseRevisionTextPatchEP 4 | <+>apply plugin: 'com.android.library'\napply plugin: 'kotlin-android'\n\nandroid {\n compileSdkVersion 28\n\n defaultConfig {\n minSdkVersion 14\n targetSdkVersion 28\n versionCode 1\n versionName \"1.0.5\"\n }\n\n buildTypes {\n release {\n minifyEnabled false\n proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'\n }\n }\n\n}\n\ndependencies {\n implementation fileTree(dir: 'libs', include: ['*.jar'])\n implementation \"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version\"\n}\n\nrepositories {\n mavenCentral()\n}\n 5 | Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP 6 | <+>UTF-8 7 | =================================================================== 8 | --- abstractMvp/build.gradle (revision c3e1dc26bf76e4857ce96aa9db252eb569943037) 9 | +++ abstractMvp/build.gradle (date 1612350616000) 10 | @@ -2,11 +2,11 @@ 11 | apply plugin: 'kotlin-android' 12 | 13 | android { 14 | - compileSdkVersion 28 15 | + compileSdkVersion 30 16 | 17 | defaultConfig { 18 | minSdkVersion 14 19 | - targetSdkVersion 28 20 | + targetSdkVersion 30 21 | versionCode 1 22 | versionName "1.0.5" 23 | } 24 | Index: build.gradle 25 | IDEA additional info: 26 | Subsystem: com.intellij.openapi.diff.impl.patch.BaseRevisionTextPatchEP 27 | <+>// Top-level build file where you can add configuration options common to all sub-projects/modules.\n\nbuildscript {\n ext.kotlin_version = '1.3.21'\n repositories {\n google()\n jcenter()\n }\n dependencies {\n classpath 'com.android.tools.build:gradle:3.4.0'\n classpath \"org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version\"\n\n // NOTE: Do not place your application dependencies here; they belong\n // in the individual module build.gradle files\n }\n}\n\nallprojects {\n repositories {\n google()\n jcenter()\n }\n}\n\ntask clean(type: Delete) {\n delete rootProject.buildDir\n}\n 28 | Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP 29 | <+>UTF-8 30 | =================================================================== 31 | --- build.gradle (revision c3e1dc26bf76e4857ce96aa9db252eb569943037) 32 | +++ build.gradle (date 1612350660000) 33 | @@ -1,13 +1,13 @@ 34 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 35 | 36 | buildscript { 37 | - ext.kotlin_version = '1.3.21' 38 | + ext.kotlin_version = '1.4.21' 39 | repositories { 40 | google() 41 | jcenter() 42 | } 43 | dependencies { 44 | - classpath 'com.android.tools.build:gradle:3.4.0' 45 | + classpath 'com.android.tools.build:gradle:4.1.2' 46 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 47 | 48 | // NOTE: Do not place your application dependencies here; they belong 49 | Index: .idea/compiler.xml 50 | IDEA additional info: 51 | Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP 52 | <+>UTF-8 53 | =================================================================== 54 | --- .idea/compiler.xml (date 1612350585000) 55 | +++ .idea/compiler.xml (date 1612350585000) 56 | @@ -0,0 +1,6 @@ 57 | + 58 | + 59 | + 60 | + 61 | + 62 | + 63 | \ No newline at end of file 64 | Index: .idea/gradle.xml 65 | IDEA additional info: 66 | Subsystem: com.intellij.openapi.diff.impl.patch.BaseRevisionTextPatchEP 67 | <+>\n\n \n \n \n 68 | Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP 69 | <+>UTF-8 70 | =================================================================== 71 | --- .idea/gradle.xml (revision c3e1dc26bf76e4857ce96aa9db252eb569943037) 72 | +++ .idea/gradle.xml (date 1612350585000) 73 | @@ -1,8 +1,11 @@ 74 | 75 | 76 | + 77 | 78 | 92 | 93 | Index: .idea/misc.xml 94 | IDEA additional info: 95 | Subsystem: com.intellij.openapi.diff.impl.patch.BaseRevisionTextPatchEP 96 | <+>\n\n \n \n \n \n \n \n \n \n \n 97 | Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP 98 | <+>UTF-8 99 | =================================================================== 100 | --- .idea/misc.xml (revision c3e1dc26bf76e4857ce96aa9db252eb569943037) 101 | +++ .idea/misc.xml (date 1612350585000) 102 | @@ -35,7 +35,7 @@ 103 | 104 | 105 | 106 | - 107 | + 108 | 109 | 110 | 111 | Index: .idea/jarRepositories.xml 112 | IDEA additional info: 113 | Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP 114 | <+>UTF-8 115 | =================================================================== 116 | --- .idea/jarRepositories.xml (date 1612350617000) 117 | +++ .idea/jarRepositories.xml (date 1612350617000) 118 | @@ -0,0 +1,30 @@ 119 | + 120 | + 121 | + 122 | + 123 | + 127 | + 128 | + 132 | + 133 | + 137 | + 138 | + 142 | + 143 | + 147 | + 148 | + 149 | \ No newline at end of file 150 | Index: gradle/wrapper/gradle-wrapper.properties 151 | IDEA additional info: 152 | Subsystem: com.intellij.openapi.diff.impl.patch.BaseRevisionTextPatchEP 153 | <+>#Mon Apr 22 14:49:42 AMT 2019\ndistributionBase=GRADLE_USER_HOME\ndistributionPath=wrapper/dists\nzipStoreBase=GRADLE_USER_HOME\nzipStorePath=wrapper/dists\ndistributionUrl=https\\://services.gradle.org/distributions/gradle-5.1.1-all.zip\n 154 | Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP 155 | <+>UTF-8 156 | =================================================================== 157 | --- gradle/wrapper/gradle-wrapper.properties (revision c3e1dc26bf76e4857ce96aa9db252eb569943037) 158 | +++ gradle/wrapper/gradle-wrapper.properties (date 1612350669000) 159 | @@ -1,6 +1,6 @@ 160 | -#Mon Apr 22 14:49:42 AMT 2019 161 | +#Wed Feb 03 15:11:09 AMT 2021 162 | distributionBase=GRADLE_USER_HOME 163 | distributionPath=wrapper/dists 164 | zipStoreBase=GRADLE_USER_HOME 165 | zipStorePath=wrapper/dists 166 | -distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip 167 | +distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip 168 | -------------------------------------------------------------------------------- /.idea/shelf/Uncommitted_changes_before_Update_at_2_3_21_3_17_PM__Default_Changelist_.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![N|Solid](https://github.com/RobertApikyan/AbstractMvp/blob/develop/intro/cover.png?raw=true) 2 | 3 | ### MinSDK 14+ 4 | [![](https://jitpack.io/v/RobertApikyan/AbstractMvp.svg)](https://jitpack.io/#RobertApikyan/AbstractMvp) 5 | [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) 6 | 7 | ## AbstractMvp 8 | 9 | AbstractMvp is a library that provides abstract components for MVP architecture realization, with problems solutions that are exist in classic MVP. 10 | 11 | ## CLASSIC MVP ISSUES THAT ARE SOLVED IN ABSTRACT MVP 12 | 13 | #### Nullable View instance 14 | In classic MVP realisation we attach the view instance to the presenter and detach it when view is going to be destroyed, so at some point the view instance inside presenter will be null and every time before accessing the view instance we need to make null check, in order to avoid NullPointerException. This behavior is secure, but it requires additional null check. To overcome with this, AbstractMvp library provides ViewActions, which are closures, that will be executed only when the view is not null. (later, detailed about ViewAction). 15 | 16 | #### Lost UI updates 17 | After performing some background jobs presenter needs to update ui, but at that point view instance is null. Since view is null, the UI updates will not be executed. AbstractMvp provides ViewActionDispatcher as a solution, which is another abstraction layer and it knows when the view is attached or not, and if it is not attached the viewAction will be cached inside ViewActionDispatcher, and executed when view become attached again. 18 | 19 | #### Not Persistence Presenter 20 | Usually presenter instance is inside our viewController (Activity or Fragment), and it will be destroyed with viewController. To overcome this, and make presenter instance persistence per viewController life scope, AbstractMvp provides PresenterHolder abstraction, which can be implemented with android ViewModels, Loaders and other lifecycle persistence mechanisms. 21 | 22 | ## ABSTRACT MVP WORKING MECHANISM 23 | 24 | Here we have a View interface that is implemented by viewController (Activity or Fragment) and a Presenter. View contains some methods methodA(), methodB(), ... methodN() that are implemented by viewController. When presenter getting created, it start some background jobs, after finishing them, it notifies UI about new changes by calling view.methodB() method. Below is the rough description of steps how viewAction with methodB() will be delivered to UI. 25 | 26 | ![N|Solid](https://github.com/RobertApikyan/AbstractMvp/blob/develop/intro/structure.png?raw=true) 27 | 28 | 1. Presenter creates new ViewAction closure with methodB() and send it via ViewActionDispatcher. Code snippet with Kotlin will look like this 29 | ```kotlin 30 | // Create the ViewAction for methodB 31 | val actionMethodB = IViewAction.fromLambda() { view -> 32 | view.methodB() 33 | } 34 | // Notify viewActionDispatcher about actionMethodB 35 | viewActionDispatcher.onViewAction(actionMethodB) 36 | ``` 37 | 2. ViewActionDispatcher will send the viewAction to ViewActionObserver, which contains view instance. Depending from ViewActionDispatcher implementation, viewActions can be cached, if the view is detached, and will be sent to UI when the view will become attached again. 38 | ```kotlin 39 | // Sending actionMethodB to ViewActionObserver 40 | viewActionObserver.onInvoke(actionMethodB) 41 | ``` 42 | 3. After receiving actionMethodB instance, ViewActionObserver executes it by passing the view instance. 43 | ```kotlin 44 | // Executing actionMethodB inside ViewActionObserver 45 | val view = viewHolder.get() // recieving view instance 46 | actionMethodB.invoke(view) // executing actionMehtodB ViewAction 47 | ``` 48 | 4. When actionMethodB is getting executed, the methodB() will be called on our viewController (Activity or Fragment) 49 | 50 | ## ABSTRACT MVP MAIN COMPONENTS 51 | Abstract MVP is consist from a several abstract components, that need to be implemented. Here is the list of them 52 | 53 | ### Components That are related with View 54 | #### 1. ViewAction 55 | #### 2. ViewActionDispatcher 56 | #### 3. ViewActionObserver 57 | ### Components That are related with Presenter 58 | #### 1. PresenterHolder 59 | #### 2. PresenterLifecycleHandler 60 | 61 | Lets Discuss them separately. 62 | 63 | 64 | ### ViewAction 65 | 66 | ViewAction is a generic interface [```IViewAction```](https://github.com/RobertApikyan/AbstractMvp/blob/master/abstractMvp/src/main/java/robertapikyan/com/abstractmvp/presentation/view/IViewAction.kt) with single method invoke(view: V) where V is the generic type that is inherited from the base IView interface. ViewActions are created inside presenter and passed to viewActionDispatcher. ViewActionDispatcher send them to ViewActionObserver, where invoke(view: V) method will be called. 67 | 68 | 69 | ### ViewActionDispatcher 70 | 71 | ViewActionDipatcher is a generic interface [```IViewActionDispatcher```](https://github.com/RobertApikyan/AbstractMvp/blob/master/abstractMvp/src/main/java/robertapikyan/com/abstractmvp/presentation/view/IViewActionDispatcher.kt) responsible for viewActions delivery to ViewActionObserver. This interface contains two methods. 72 | First one is ``` setViewActionObserver(viewHolder: ViewHolder, viewActionObserver: IViewActionObserver) ``` which is called every time when new view is attached. With First argument [viewholder](https://github.com/RobertApikyan/AbstractMvp/blob/master/abstractMvp/src/main/java/robertapikyan/com/abstractmvp/presentation/view/ViewHolder.kt) we can get view instance by calling viewHolder.get() method. When the viewController will be destroyed view instance will be automatically removed from viewHolder container. Second argument is viewActionObserver instance. We can send view actions to viewActionObserver by calling viewActionObserver.onInvoke(viewAction) and passing viewAction instance. 73 | Second method is ``` onViewAction(actionType: ActionType, viewAction: IViewAction) ```, which is calling from presenter, every time when we need to pass new viewAction. [ActionType](https://github.com/RobertApikyan/AbstractMvp/blob/master/abstractMvp/src/main/java/robertapikyan/com/abstractmvp/presentation/view/ActionType.kt) is an enum with values are ```STICKY``` and ```IMMEDIATE```. 74 | ```STICKY``` - When viewActionDispatcher receives viewActions and in that time the view is already detached, the viewActions will be added in to queue and delivered when the view will become attached again. 75 | ```IMMEDIATE``` - ViewActions will be delivered only if view is attached. If view is detached action will be lost. 76 | 77 | ViewActionDispatcher can be implemented with RxJava or with a LiveData from Android arcitecture components. 78 | 79 | ### ViewActionObserver 80 | 81 | ViewActionObserver is a generic interface [```IViewActionObserver ```](https://github.com/RobertApikyan/AbstractMvp/blob/master/abstractMvp/src/main/java/robertapikyan/com/abstractmvp/presentation/view/IViewActionObserver.kt) with two methods. 82 | First one is ```onCreate(viewHolder:ViewHolder)``` which is calling by framework. Here ```viewHolder``` instance we need for invoking received ```viewActions``` . 83 | Second one is ```onInvoke(viewAction: IViewAction)``` this method is called by viewActionDispatcher. 84 | 85 | ### PresenterHolder 86 | 87 | PresenterHolder is a generic interface [```IPresenterHolder>```](https://github.com/RobertApikyan/AbstractMvp/blob/master/abstractMvp/src/main/java/robertapikyan/com/abstractmvp/presentation/presenter/IPresenterHolder.kt) with tree methods (put, get, hasPresenter). All this methods are going to be called by framework. The main point of this container class is to make presenter instance persistence from viewController lifecycle scope. This Interface can be implemented with Android Loaders api or with ViewModels from Android arcitecture components. 88 | 89 | ### PresenterLifecycleHandler 90 | 91 | PresenterLifecycleHandler an interface [IPresenterLifecycleHandler](https://github.com/RobertApikyan/AbstractMvp/blob/master/abstractMvp/src/main/java/robertapikyan/com/abstractmvp/presentation/presenter/IPresenterLifecycleHandler.kt) with one method ```onCreate(presenterLifecycle: IPresenterLifecycle)```. This method is called by framework. Here we receive [presenterLifecycle](https://github.com/RobertApikyan/AbstractMvp/blob/master/abstractMvp/src/main/java/robertapikyan/com/abstractmvp/presentation/presenter/IPresenterLifecycle.kt) instance, which has four methods 92 | ```kotlin 93 | /** 94 | * onViewAttach, will be called with activity onCreate 95 | */ 96 | fun onViewAttach() 97 | 98 | /** 99 | * onViewStop, will be called with activity onStart 100 | */ 101 | fun onViewStart() 102 | 103 | /** 104 | * onViewStop, will be called with activity onStop 105 | */ 106 | fun onViewStop() 107 | 108 | /** 109 | * onViewDetach, will be called with activity onDestroy 110 | */ 111 | fun onViewDetach() 112 | ``` 113 | PresenterLifecycleHandler's implementation can be done with custom activity lifecycle callback mechanism or it will be more easy to implement with a Lifecycle component from Android arcitecture components. 114 | 115 | Presenter also have one more lifecycle method ```onCreate()```, which is called by framework only once, when presenter instance is created, and all components are bound together. 116 | 117 | ### BINDING ALL TOGETHER 118 | 119 | AbstractMvp library provides [Mvp.Factory>](https://github.com/RobertApikyan/AbstractMvp/blob/master/abstractMvp/src/main/java/robertapikyan/com/abstractmvp/presentation/Mvp.kt) generic interface. Factory class must implement from [Mvp.Factory>](https://github.com/RobertApikyan/AbstractMvp/blob/master/abstractMvp/src/main/java/robertapikyan/com/abstractmvp/presentation/Mvp.kt) and override all methods and returns already implemented components. 120 | To get presenter instance call ```Mvp.from(factory:Factory)``` method and pass your factory instance. 121 | 122 | ## SUMMARY 123 | 124 | #### AbstractMvp is The abstraction layer for MVP architecture. It provides the base structure for MVP and allow to define custom MVP implementation. 125 | 126 | ## [AbstractMvp Implementation With Android Arcitecture components](https://github.com/RobertApikyan/LifecycleMvp) 127 | 128 | ## Download 129 | ### Gradle 130 | #### Add to project level build.gradle 131 | ```groovy 132 | allprojects { 133 | repositories { 134 | ... 135 | maven { url 'https://jitpack.io' } 136 | } 137 | } 138 | ``` 139 | #### Add dependency to app module level build.gradle 140 | ```groovy 141 | dependencies { 142 | implementation 'com.github.RobertApikyan:AbstractMvp:1.0.6' 143 | } 144 | ``` 145 | ### Maven 146 | ```xml 147 | 148 | 149 | jitpack.io 150 | https://jitpack.io 151 | 152 | 153 | ``` 154 | #### Add dependency 155 | ```xml 156 | 157 | com.github.RobertApikyan 158 | AbstractMvp 159 | 1.0.6 160 | 161 | ``` 162 | 163 | 164 | ### Done. 165 | 166 | [![View Robert Apikyan profile on LinkedIn](https://www.linkedin.com/img/webpromo/btn_viewmy_160x33.png)](https://www.linkedin.com/in/robert-apikyan-24b915130/) 167 | 168 | License 169 | ------- 170 | 171 | Copyright 2018 Robert Apikyan 172 | 173 | Licensed under the Apache License, Version 2.0 (the "License"); 174 | you may not use this file except in compliance with the License. 175 | You may obtain a copy of the License at 176 | 177 | http://www.apache.org/licenses/LICENSE-2.0 178 | 179 | Unless required by applicable law or agreed to in writing, software 180 | distributed under the License is distributed on an "AS IS" BASIS, 181 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 182 | See the License for the specific language governing permissions and 183 | limitations under the License. 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | -------------------------------------------------------------------------------- /abstractMvp/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /abstractMvp/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'kotlin-android' 3 | 4 | android { 5 | compileSdkVersion 30 6 | 7 | defaultConfig { 8 | minSdkVersion 14 9 | targetSdkVersion 30 10 | versionCode 1 11 | versionName "1.0.6" 12 | } 13 | 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | 21 | } 22 | 23 | dependencies { 24 | implementation fileTree(dir: 'libs', include: ['*.jar']) 25 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 26 | } 27 | 28 | repositories { 29 | mavenCentral() 30 | } 31 | -------------------------------------------------------------------------------- /abstractMvp/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /abstractMvp/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /abstractMvp/src/main/java/robertapikyan/com/abstractmvp/presentation/Mvp.kt: -------------------------------------------------------------------------------- 1 | package robertapikyan.com.abstractmvp.presentation 2 | 3 | import robertapikyan.com.abstractmvp.presentation.presenter.IPresenterHolder 4 | import robertapikyan.com.abstractmvp.presentation.presenter.IPresenterLifecycleHandler 5 | import robertapikyan.com.abstractmvp.presentation.presenter.Presenter 6 | import robertapikyan.com.abstractmvp.presentation.presenter.PresenterProxy 7 | import robertapikyan.com.abstractmvp.presentation.view.IView 8 | import robertapikyan.com.abstractmvp.presentation.view.IViewActionDispatcher 9 | import robertapikyan.com.abstractmvp.presentation.view.IViewActionObserver 10 | import robertapikyan.com.abstractmvp.presentation.view.ViewHolder 11 | 12 | class Mvp { 13 | 14 | /** 15 | * One of the important interface for MVP library. 16 | * This is the starting point for MVP implementation 17 | * Inherit from this Factory, and provide your custom implementations 18 | * for IViewActionDispatcher, IViewActionObserver, IPresenterHolder, IPresenterLifecycleHandler ... 19 | */ 20 | interface Factory> { 21 | fun getView(): V 22 | fun getViewActionDispatcher(): IViewActionDispatcher 23 | fun getViewActionObserver(): IViewActionObserver 24 | fun getPresenter(): P 25 | fun getPresenterHolder(): IPresenterHolder 26 | fun getPresenterLifecycleHandler(): IPresenterLifecycleHandler 27 | } 28 | 29 | companion object { 30 | /** 31 | * Use this method in order to receive your presenter instance 32 | * based on you Factory implementation 33 | */ 34 | fun > from(factory: Factory): P { 35 | // View 36 | val view = factory.getView() 37 | val viewHolder = ViewHolder() 38 | 39 | // Presenter 40 | val presenter by lazy { factory.getPresenter() } 41 | val presenterHolder = factory.getPresenterHolder() 42 | val presenterProxy by lazy { PresenterProxy(presenterHolder.get()) } 43 | val presenterLifecycleHandler by lazy { factory.getPresenterLifecycleHandler() } 44 | 45 | // Action dispatcher and observable 46 | val viewActionObserver = factory.getViewActionObserver() 47 | val viewActionDispatcher by lazy { factory.getViewActionDispatcher() } 48 | 49 | // holds state whatever presenter is created or restored 50 | val isPresenterCreated = !presenterHolder.hasPresenter() 51 | 52 | // if holder is empty, we create new presenter instance 53 | if (!presenterHolder.hasPresenter()) { 54 | presenterHolder.put(presenter) 55 | } 56 | 57 | // set the viewHolder instance, 58 | // in order to clear it when view scope is going to be destroyed 59 | presenterProxy.viewHolder = viewHolder 60 | 61 | viewHolder.putView(view) 62 | 63 | // pass the presenterProxy instance as PresenterLifecycle 64 | presenterLifecycleHandler.onCreate(presenterProxy) 65 | 66 | viewActionObserver.onCreate(viewHolder) 67 | 68 | // now if presenter is created we set viewActionObserver instance to viewActionDispatcher, 69 | // pass the viewActionDispatcher instance to presenter, 70 | // and call presenter.onCreate(). At this point presenter is ready 71 | if (isPresenterCreated) { 72 | viewActionDispatcher.setViewActionObserver(viewHolder, viewActionObserver) 73 | presenter._viewActionDispatcher = viewActionDispatcher 74 | presenter.onCreate() 75 | } else { 76 | // if presenter instance is restored, we just set viewActionObserver to viewActionDispatcher, 77 | // and call presenter.onRestore() 78 | presenterHolder.get() 79 | ._viewActionDispatcher 80 | .setViewActionObserver(viewHolder, viewActionObserver) 81 | presenterHolder.get().onRestore() 82 | } 83 | 84 | // return the presenter instance 85 | return presenterHolder.get() 86 | } 87 | } 88 | } -------------------------------------------------------------------------------- /abstractMvp/src/main/java/robertapikyan/com/abstractmvp/presentation/presenter/IPresenterHolder.kt: -------------------------------------------------------------------------------- 1 | package robertapikyan.com.abstractmvp.presentation.presenter 2 | 3 | import robertapikyan.com.abstractmvp.presentation.view.IView 4 | 5 | /** 6 | * IPresenterHolder represent's holder container for Presenter instance, 7 | * It receive's presenter instance via put() method, and provide's the same instance 8 | * via get() method 9 | * The main point of this class is to inherit from android lifecycle persistence objects such as 10 | * Loaders and ViewModels and every time provide the same presenter instance 11 | */ 12 | interface IPresenterHolder> { 13 | fun hasPresenter(): Boolean 14 | fun put(presenter: P) 15 | fun get(): P 16 | } -------------------------------------------------------------------------------- /abstractMvp/src/main/java/robertapikyan/com/abstractmvp/presentation/presenter/IPresenterLifecycle.kt: -------------------------------------------------------------------------------- 1 | package robertapikyan.com.abstractmvp.presentation.presenter 2 | 3 | /** 4 | * IPresenterLifecycle is Presenter lifecycle representation 5 | */ 6 | interface IPresenterLifecycle { 7 | 8 | /** 9 | * onViewAttach, will be called with activity onCreate 10 | */ 11 | fun onViewAttach() 12 | 13 | /** 14 | * onViewStop, will be called with activity onStart 15 | */ 16 | fun onViewStart() 17 | 18 | /** 19 | * onViewStop, will be called with activity onStop 20 | */ 21 | fun onViewStop() 22 | 23 | /** 24 | * onViewDetach, will be called with activity onDestroy 25 | */ 26 | fun onViewDetach() 27 | } -------------------------------------------------------------------------------- /abstractMvp/src/main/java/robertapikyan/com/abstractmvp/presentation/presenter/IPresenterLifecycleHandler.kt: -------------------------------------------------------------------------------- 1 | package robertapikyan.com.abstractmvp.presentation.presenter 2 | 3 | /** 4 | * IPresenterLifecycleHandler is responsible for presenter lifecycle handling 5 | * Receive presenter lifecycle instance via setViewActionObserver method, 6 | * All lifecycle methods will be called by PresenterLifecycleHandler except Lifecycle::setViewActionObserver method, 7 | * this method will be called by MVP framework 8 | */ 9 | interface IPresenterLifecycleHandler { 10 | fun onCreate(presenterLifecycle: IPresenterLifecycle) 11 | } -------------------------------------------------------------------------------- /abstractMvp/src/main/java/robertapikyan/com/abstractmvp/presentation/presenter/Presenter.kt: -------------------------------------------------------------------------------- 1 | package robertapikyan.com.abstractmvp.presentation.presenter 2 | 3 | import robertapikyan.com.abstractmvp.presentation.view.IView 4 | import robertapikyan.com.abstractmvp.presentation.view.IViewActionDispatcher 5 | 6 | /** 7 | * Presenter, receive view action dispatcher instance via setViewActionObserver lifecycle method 8 | */ 9 | abstract class Presenter : IPresenterLifecycle { 10 | 11 | /** 12 | * Presenter Factory interface, usually will be 13 | * implemented by activity or fragment, in order to call presenter constructor and 14 | * provide it's instance 15 | */ 16 | interface Factory> { 17 | 18 | fun createPresenter(): P 19 | 20 | companion object { 21 | /** 22 | * Presenter Factory, with lambda expression 23 | */ 24 | fun > fromLambda(factory: () -> P) = object : Factory { 25 | override fun createPresenter() = factory() 26 | } 27 | } 28 | } 29 | 30 | internal lateinit var _viewActionDispatcher: IViewActionDispatcher 31 | 32 | /** 33 | * Dispatch view actions via calling viewActionDispatcher::onViewAction method 34 | */ 35 | protected val viewActionDispatcher: IViewActionDispatcher 36 | get() { 37 | assertNullableViewActionDispatcher() 38 | return _viewActionDispatcher 39 | } 40 | 41 | /** 42 | * This method is called only once when the presenter instance is created, 43 | * Depended on IPresenterHolder implementation, if presenter is some scope persistence (such as 44 | * android activity lifecycle) onCreate is called only once when presenter instance is created, 45 | * after that onRestore() method will be called when we fetch the presenter instance from 46 | * IPresenterHolder 47 | */ 48 | open fun onCreate() {} 49 | 50 | /** 51 | * This method is called when presenter's already created instance is fetched 52 | * from IPresenterHolder 53 | */ 54 | open fun onRestore() {} 55 | 56 | /** 57 | * onViewAttach, will be called with activity setViewActionObserver 58 | */ 59 | override fun onViewAttach() {} 60 | 61 | /** 62 | * onViewStop, will be called with activity onStart 63 | */ 64 | override fun onViewStart() {} 65 | 66 | /** 67 | * onViewStop, will be called with activity onStop 68 | */ 69 | override fun onViewStop() {} 70 | 71 | /** 72 | * onViewDetach, will be called with activity onDestroy 73 | */ 74 | override fun onViewDetach() {} 75 | 76 | /** 77 | * onDestroy, will be called with activity onDestroy, when the activity will not be recreated. 78 | * Clean resources here 79 | */ 80 | open fun onDestroy(){} 81 | 82 | /** 83 | * If viewActionDispatcher is not initialized yet, IllegalStateException will be thrown, in order 84 | * to indicate that viewActionDispatcher is get accessed before presenter::onCreate method call. 85 | * Usually This is happening when viewActionDispatcher is get accessed from 86 | * presenter constructor, or from class member fields. 87 | * If you do not want to throw IllegalStateException in this case, override this method and 88 | * return false. 89 | */ 90 | protected open fun throwIfPresenterIsNotCreated() = true 91 | 92 | private fun assertNullableViewActionDispatcher() { 93 | if (throwIfPresenterIsNotCreated() && !::_viewActionDispatcher.isInitialized) 94 | throw IllegalStateException("Presenter is not created, or " + 95 | "super.setViewActionObserver(viewActionDispatcher) is not called yet") 96 | } 97 | 98 | } -------------------------------------------------------------------------------- /abstractMvp/src/main/java/robertapikyan/com/abstractmvp/presentation/presenter/PresenterProxy.kt: -------------------------------------------------------------------------------- 1 | package robertapikyan.com.abstractmvp.presentation.presenter 2 | 3 | import robertapikyan.com.abstractmvp.presentation.view.ViewHolder 4 | 5 | internal class PresenterProxy( 6 | private val presenterLifecycle: IPresenterLifecycle) : IPresenterLifecycle { 7 | 8 | lateinit var viewHolder: ViewHolder<*> 9 | 10 | override fun onViewAttach() = presenterLifecycle.onViewAttach() 11 | 12 | override fun onViewStart() = presenterLifecycle.onViewStart() 13 | 14 | override fun onViewStop() = presenterLifecycle.onViewStop() 15 | 16 | override fun onViewDetach() { 17 | presenterLifecycle.onViewDetach() 18 | if (::viewHolder.isInitialized) 19 | viewHolder.clear() 20 | } 21 | } -------------------------------------------------------------------------------- /abstractMvp/src/main/java/robertapikyan/com/abstractmvp/presentation/view/ActionType.kt: -------------------------------------------------------------------------------- 1 | package robertapikyan.com.abstractmvp.presentation.view 2 | 3 | enum class ActionType { 4 | /** 5 | * If View is not active viewActions with STICKY type will be placed in queue and 6 | * delivered to view controller after it become active. 7 | */ 8 | STICKY, 9 | /** 10 | * ViewAction will be delivered only if view is active. 11 | */ 12 | IMMEDIATE, 13 | } -------------------------------------------------------------------------------- /abstractMvp/src/main/java/robertapikyan/com/abstractmvp/presentation/view/IView.kt: -------------------------------------------------------------------------------- 1 | package robertapikyan.com.abstractmvp.presentation.view 2 | 3 | /** 4 | * Base View interface 5 | */ 6 | interface IView -------------------------------------------------------------------------------- /abstractMvp/src/main/java/robertapikyan/com/abstractmvp/presentation/view/IViewAction.kt: -------------------------------------------------------------------------------- 1 | package robertapikyan.com.abstractmvp.presentation.view 2 | 3 | /** 4 | * Base view action, 5 | * invoke method will be called only if view is attached 6 | */ 7 | interface IViewAction { 8 | fun invoke(view: V) 9 | 10 | companion object { 11 | fun fromLambda(action: (V) -> Unit) = object : IViewAction { 12 | override fun invoke(view: V) = action.invoke(view) 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /abstractMvp/src/main/java/robertapikyan/com/abstractmvp/presentation/view/IViewActionDispatcher.kt: -------------------------------------------------------------------------------- 1 | package robertapikyan.com.abstractmvp.presentation.view 2 | 3 | /** 4 | * IViewActionDispatcher main purpose is viewActions delivery to IViewActionObserver where 5 | * ViewActions will be invoked 6 | */ 7 | interface IViewActionDispatcher { 8 | 9 | /** 10 | * Receive viewHolder and viewActionObserver instances. 11 | * Access to view via viewHolder.get() method and dispatch viewAction via 12 | * Dispatch view actions via viewActionObserver.invoke(viewAction) method 13 | */ 14 | fun setViewActionObserver(viewHolder: ViewHolder, viewActionObserver: IViewActionObserver) 15 | 16 | /** 17 | * Call this method inside presenter, in order to send viewAction to view 18 | * @param actionType, implement you realization for each actionType 19 | * @param viewAction from presenter 20 | */ 21 | fun onViewAction( 22 | actionType: ActionType, 23 | viewAction: IViewAction 24 | ) 25 | } -------------------------------------------------------------------------------- /abstractMvp/src/main/java/robertapikyan/com/abstractmvp/presentation/view/IViewActionObserver.kt: -------------------------------------------------------------------------------- 1 | package robertapikyan.com.abstractmvp.presentation.view 2 | 3 | /** 4 | * IViewActionObserver is receiving viewActions from IViewActionDispatcher via onInvoke method, 5 | * Get access to view via viewHolder.get() method and invoke view actions via 6 | * viewAction.invoke(viewHolder.get()) method 7 | */ 8 | interface IViewActionObserver { 9 | 10 | fun onCreate(viewHolder: ViewHolder) 11 | 12 | /** 13 | * This method is calling by IViewActionDispatcher 14 | */ 15 | fun onInvoke(viewAction: IViewAction) 16 | } -------------------------------------------------------------------------------- /abstractMvp/src/main/java/robertapikyan/com/abstractmvp/presentation/view/ViewHolder.kt: -------------------------------------------------------------------------------- 1 | package robertapikyan.com.abstractmvp.presentation.view 2 | 3 | /** 4 | * This call is holder container for view. 5 | * View instance will be automatically cleared from ViewHolder with activity onDestroy() method 6 | */ 7 | class ViewHolder { 8 | 9 | private var _view: V? = null 10 | 11 | internal fun putView(view: V) { 12 | _view = view 13 | } 14 | 15 | /** 16 | * Clear will be called by Mvp library 17 | */ 18 | internal fun clear() { 19 | _view = null 20 | } 21 | 22 | /** 23 | * @return view nullable instance 24 | */ 25 | fun getView() = _view 26 | 27 | /** 28 | * Check for view is null 29 | */ 30 | fun hasView() = _view != null 31 | } -------------------------------------------------------------------------------- /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.4.21' 5 | repositories { 6 | google() 7 | jcenter() 8 | } 9 | dependencies { 10 | classpath 'com.android.tools.build:gradle:4.1.2' 11 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 12 | 13 | // NOTE: Do not place your application dependencies here; they belong 14 | // in the individual module build.gradle files 15 | } 16 | } 17 | 18 | allprojects { 19 | repositories { 20 | google() 21 | jcenter() 22 | } 23 | } 24 | 25 | task clean(type: Delete) { 26 | delete rootProject.buildDir 27 | } 28 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobertApikyan/AbstractMvp/b1c8edbc642efb0ec2afcb82c8c9e8f58dfc0134/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Feb 03 15:11:09 AMT 2021 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-6.5-bin.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /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 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 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 Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':abstractMvp' 2 | --------------------------------------------------------------------------------