├── .gitignore
├── .travis.yml
├── LICENSE
├── README.md
├── app
├── .gitignore
├── build.gradle
├── gradleScript
│ └── dependencies.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── woua
│ │ └── mvvm
│ │ └── clean
│ │ └── ExampleInstrumentedTest.kt
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── woua
│ │ │ └── mvvm
│ │ │ └── clean
│ │ │ ├── FooActivity.kt
│ │ │ ├── FooApplication.kt
│ │ │ ├── FooViewModel.kt
│ │ │ └── injection
│ │ │ ├── ActivityBuilder.kt
│ │ │ ├── AppComponent.kt
│ │ │ ├── AppModule.kt
│ │ │ ├── ApplicationScoped.kt
│ │ │ ├── BaseFactory.kt
│ │ │ ├── Module.kt
│ │ │ ├── ViewModelFactory.kt
│ │ │ ├── ViewModelKey.kt
│ │ │ └── ViewModelModule.kt
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ └── ic_launcher_background.xml
│ │ ├── layout
│ │ └── activity_main.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── woua
│ └── mvvm
│ └── clean
│ └── ExampleUnitTest.kt
├── architecture_diagram.png
├── build.gradle
├── buildSrc
├── .gitignore
├── build.gradle.kts
└── src
│ └── main
│ └── java
│ └── dependencies
│ ├── Deps.kt
│ └── Version.kt
├── cache
├── .gitignore
├── build.gradle
├── consumer-rules.pro
├── gradleScript
│ └── dependencies.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── woua
│ │ └── mvvm
│ │ └── clean
│ │ └── cache
│ │ └── ExampleInstrumentedTest.kt
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── woua
│ │ │ └── mvvm
│ │ │ └── clean
│ │ │ └── cache
│ │ │ ├── BaseDao.kt
│ │ │ ├── CacheSource.kt
│ │ │ ├── CacheSourceImpl.kt
│ │ │ ├── ContactDao.kt
│ │ │ ├── ContactEntity.kt
│ │ │ └── Database.kt
│ └── res
│ │ └── values
│ │ └── strings.xml
│ └── test
│ └── java
│ └── com
│ └── woua
│ └── mvvm
│ └── clean
│ └── remote
│ └── ExampleUnitTest.kt
├── common
├── codestyle
│ └── kotlin_android.xml
└── gradle
│ └── root.gradle
├── data
├── .gitignore
├── build.gradle
├── consumer-rules.pro
├── gradleScript
│ └── dependencies.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── woua
│ │ └── mvvm
│ │ └── clean
│ │ └── domain
│ │ └── ExampleInstrumentedTest.kt
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── woua
│ │ │ └── mvvm
│ │ │ └── clean
│ │ │ └── data
│ │ │ ├── DataSource.kt
│ │ │ ├── DataSourceImpl.kt
│ │ │ ├── JobExecutor.kt
│ │ │ ├── RepositoryImpl.kt
│ │ │ ├── SingletonHolder.kt
│ │ │ └── UiThread.kt
│ └── res
│ │ └── values
│ │ └── strings.xml
│ └── test
│ └── java
│ └── com
│ └── woua
│ └── mvvm
│ └── clean
│ └── domain
│ └── ExampleUnitTest.kt
├── domain
├── .gitignore
├── build.gradle
├── consumer-rules.pro
├── gradleScript
│ └── dependencies.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── woua
│ │ └── mvvm
│ │ └── clean
│ │ └── domain
│ │ └── ExampleInstrumentedTest.kt
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── woua
│ │ │ └── mvvm
│ │ │ └── clean
│ │ │ └── domain
│ │ │ ├── ContactListUsecase.kt
│ │ │ ├── PostExecutionThread.kt
│ │ │ ├── Repository.kt
│ │ │ ├── ThreadExecutor.kt
│ │ │ ├── UseCase.kt
│ │ │ └── UseCaseHandler.kt
│ └── res
│ │ └── values
│ │ └── strings.xml
│ └── test
│ └── java
│ └── com
│ └── woua
│ └── mvvm
│ └── clean
│ └── domain
│ └── ExampleUnitTest.kt
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── remote
├── .gitignore
├── build.gradle
├── consumer-rules.pro
├── gradleScript
│ └── dependencies.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── woua
│ │ └── mvvm
│ │ └── clean
│ │ └── remote
│ │ └── ExampleInstrumentedTest.kt
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── woua
│ │ │ └── mvvm
│ │ │ └── clean
│ │ │ └── remote
│ │ │ ├── ApiHandler.kt
│ │ │ ├── ApiHandlerImpl.kt
│ │ │ ├── RemoteSource.kt
│ │ │ ├── RemoteSourceImpl.kt
│ │ │ ├── Response.kt
│ │ │ └── RestApi.kt
│ └── res
│ │ └── values
│ │ └── strings.xml
│ └── test
│ └── java
│ └── com
│ └── woua
│ └── mvvm
│ └── clean
│ └── remote
│ └── ExampleUnitTest.kt
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | /.idea/navEditor.xml
9 | /.idea/assetWizardSettings.xml
10 | /.idea/*
11 | .DS_Store
12 | /build
13 | /captures
14 | .externalNativeBuild
15 | .cxx
16 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: android
2 | android:
3 | components:
4 | - tools
5 | - platform-tools
6 | - build-tools-28.0.3
7 | - android-29
8 | - extra-android-m2repository
9 | - extra-google-m2repository
10 | jdk:
11 | - oraclejdk8
12 | script:
13 | - ./gradlew test
14 | before_cache:
15 | - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
16 | sudo: false
17 | cache:
18 | directories:
19 | - $HOME/.m2
20 | - $HOME/.gradle/caches/
21 | - $HOME/.gradle/wrapper/
22 |
--------------------------------------------------------------------------------
/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 | # Android MVVM + Clean Architecture + Kotlin
2 |
3 | This repository contains a sample app skeleton that implements **MVVM + Clean architecture in Kotlin** along with **Dagger, Room, RxJava2 and Retrofit**.
4 |
5 | Using this combination of MVVM + Clean architecture enhances the separation of concerns with modular approach.
6 |
7 | **Plug and play this skeleton to build great apps in Kotlin ;)**
8 |
9 | ## Architecture Block diagram ##
10 | 
11 |
12 |
13 | ## Project structure ##
14 |
15 | The project is simple containing Contacts API client, storing the response in Room and observing the Live data in the View.
16 | The app has following modules
17 | 1. Cache – Persistent database layer using Room
18 | 2. Data – A single point of contact for data accessing from a data source (cache/remote)
19 | 3. Domain – Use cases (Please explain this)
20 | 4. Remote – Network layer using Retrofit
21 |
22 | ## Library references ##
23 | 1. Retrofit
24 | 2. Dagger2
25 | 3. Room
26 | 4. RxJava
27 | 5. KotlinDSL
28 |
29 | ### License
30 | ```
31 | Copyright (C) 2019 WouaLabs
32 |
33 | Licensed under the Apache License, Version 2.0 (the "License");
34 | you may not use this file except in compliance with the License.
35 | You may obtain a copy of the License at
36 |
37 | http://www.apache.org/licenses/LICENSE-2.0
38 |
39 | Unless required by applicable law or agreed to in writing, software
40 | distributed under the License is distributed on an "AS IS" BASIS,
41 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
42 | See the License for the specific language governing permissions and
43 | limitations under the License.
44 | ```
45 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | import dependencies.*
2 |
3 | apply plugin: 'com.android.application'
4 |
5 | apply plugin: 'kotlin-android'
6 |
7 | apply plugin: 'kotlin-android-extensions'
8 |
9 | apply plugin: 'kotlin-kapt'
10 | apply from: Deps.dependency
11 |
12 | android {
13 | compileSdkVersion Version.compileSdk
14 | defaultConfig {
15 | applicationId "com.woua.mvvm.clean"
16 | minSdkVersion Version.minSdk
17 | targetSdkVersion Version.targetSdk
18 | versionCode 1
19 | versionName "1.0"
20 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
21 | }
22 | buildTypes {
23 | release {
24 | minifyEnabled false
25 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
26 | }
27 | }
28 | }
29 |
30 |
--------------------------------------------------------------------------------
/app/gradleScript/dependencies.gradle:
--------------------------------------------------------------------------------
1 | import dependencies.*
2 |
3 | apply from: Deps.common
4 |
5 | dependencies {
6 |
7 | implementation project(Deps.Module.domain)
8 | implementation project(Deps.Module.data)
9 | implementation project(Deps.Module.remote)
10 |
11 | //Android X
12 | implementation Deps.AndroidX.appcompat
13 | implementation Deps.AndroidX.constraintlayout
14 | implementation Deps.AndroidX.core
15 |
16 | //Dagger2
17 | implementation Deps.Dagger.dagger2
18 | implementation Deps.Dagger.daggerAndroid
19 | implementation Deps.Dagger.daggerAndroidSupport
20 | kapt Deps.Dagger.processor
21 | kapt Deps.Dagger.compiler
22 |
23 | //RxJava
24 | implementation Deps.RxJava.rxAndroid
25 | implementation Deps.RxJava.rxjava2
26 |
27 | //LifeCycle
28 | implementation Deps.lifeCycleExtension
29 | }
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/woua/mvvm/clean/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.woua.mvvm.clean
2 |
3 | import androidx.test.platform.app.InstrumentationRegistry
4 | import androidx.test.ext.junit.runners.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22 | assertEquals("com.woua.mvvm.clean", appContext.packageName)
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/java/com/woua/mvvm/clean/FooActivity.kt:
--------------------------------------------------------------------------------
1 | package com.woua.mvvm.clean
2 |
3 | import android.os.Bundle
4 | import android.widget.Toast
5 | import androidx.appcompat.app.AppCompatActivity
6 | import androidx.lifecycle.Observer
7 | import androidx.lifecycle.ViewModelProvider
8 | import androidx.lifecycle.ViewModelProviders
9 | import dagger.android.AndroidInjection
10 | import javax.inject.Inject
11 |
12 | class FooActivity : AppCompatActivity() {
13 |
14 | private var fooViewModel: FooViewModel? = null
15 |
16 | @Inject
17 | lateinit var viewModelFactory: ViewModelProvider.Factory
18 |
19 | override fun onCreate(savedInstanceState: Bundle?) {
20 | AndroidInjection.inject(this)
21 | super.onCreate(savedInstanceState)
22 | setContentView(R.layout.activity_main)
23 |
24 | fooViewModel = ViewModelProviders.of(this, viewModelFactory).get(FooViewModel::class.java)
25 |
26 | fooViewModel?.contactList()?.observe(this, Observer {
27 | if (it) {
28 | Toast.makeText(this, "Remote data fetched and same store in the DB", Toast.LENGTH_SHORT)
29 | .show()
30 | } else {
31 | Toast.makeText(this, "Unable to fecth data", Toast.LENGTH_SHORT).show()
32 | }
33 | })
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/app/src/main/java/com/woua/mvvm/clean/FooApplication.kt:
--------------------------------------------------------------------------------
1 | package com.woua.mvvm.clean
2 |
3 | import android.app.Activity
4 | import android.app.Application
5 | import com.woua.mvvm.clean.injection.DaggerAppComponent
6 | import dagger.android.AndroidInjector
7 | import dagger.android.DispatchingAndroidInjector
8 | import dagger.android.HasActivityInjector
9 | import javax.inject.Inject
10 |
11 | class FooApplication : Application(), HasActivityInjector {
12 |
13 | @Inject
14 | lateinit var activityInjector: DispatchingAndroidInjector
15 |
16 | override fun activityInjector(): AndroidInjector? = activityInjector
17 |
18 | override fun onCreate() {
19 | super.onCreate()
20 | DaggerAppComponent.builder().application(this).build().inject(this)
21 | }
22 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/woua/mvvm/clean/FooViewModel.kt:
--------------------------------------------------------------------------------
1 | package com.woua.mvvm.clean
2 |
3 | import androidx.lifecycle.MutableLiveData
4 | import androidx.lifecycle.ViewModel
5 | import com.woua.mvvm.clean.domain.ContactListUsecase
6 | import com.woua.mvvm.clean.domain.UseCaseHandler
7 | import io.reactivex.observers.DisposableSingleObserver
8 | import javax.inject.Inject
9 |
10 | class FooViewModel @Inject constructor(
11 | private val handler: UseCaseHandler,
12 | private val contactListUsecase: ContactListUsecase
13 | ) : ViewModel() {
14 |
15 | private val mutableLiveData = MutableLiveData()
16 |
17 | fun contactList(): MutableLiveData {
18 |
19 | val disposableSingleObserver = object :
20 | DisposableSingleObserver() {
21 | override fun onSuccess(responseValues: ContactListUsecase.ResponseValues) {
22 | mutableLiveData.postValue(responseValues.isSuccess)
23 | }
24 |
25 | override fun onError(e: Throwable) {
26 | mutableLiveData.postValue(false)
27 | }
28 | }
29 | handler.execute(
30 | contactListUsecase,
31 | ContactListUsecase.RequestValues(),
32 | disposableSingleObserver
33 | )
34 |
35 | return mutableLiveData
36 | }
37 |
38 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/woua/mvvm/clean/injection/ActivityBuilder.kt:
--------------------------------------------------------------------------------
1 | package com.woua.mvvm.clean.injection
2 |
3 | import com.woua.mvvm.clean.FooActivity
4 | import dagger.Module
5 | import dagger.android.ContributesAndroidInjector
6 |
7 | @Module(
8 | includes = [ViewModelModule::class, com.woua.mvvm.clean.injection.Module::class]
9 | )
10 | abstract class ActivityBuilder {
11 |
12 | @ContributesAndroidInjector
13 | abstract fun foo(): FooActivity
14 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/woua/mvvm/clean/injection/AppComponent.kt:
--------------------------------------------------------------------------------
1 | package com.woua.mvvm.clean.injection
2 |
3 | import com.woua.mvvm.clean.FooApplication
4 | import dagger.BindsInstance
5 | import dagger.Component
6 | import dagger.android.support.AndroidSupportInjectionModule
7 |
8 | @ApplicationScoped
9 | @Component(modules = [AppModule::class, ActivityBuilder::class, AndroidSupportInjectionModule::class])
10 | interface AppComponent {
11 |
12 | fun inject(application: FooApplication)
13 |
14 | @Component.Builder
15 | interface Builder {
16 |
17 | @BindsInstance
18 | fun application(application: FooApplication): Builder
19 |
20 | fun build(): AppComponent
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/app/src/main/java/com/woua/mvvm/clean/injection/AppModule.kt:
--------------------------------------------------------------------------------
1 | package com.woua.mvvm.clean.injection
2 |
3 | import android.content.Context
4 | import com.woua.mvvm.clean.FooApplication
5 | import com.woua.mvvm.clean.data.DataSource
6 | import com.woua.mvvm.clean.data.DataSourceImpl
7 | import com.woua.mvvm.clean.data.JobExecutor
8 | import com.woua.mvvm.clean.data.UiThread
9 | import com.woua.mvvm.clean.domain.PostExecutionThread
10 | import com.woua.mvvm.clean.domain.ThreadExecutor
11 | import com.woua.mvvm.clean.domain.UseCaseHandler
12 | import dagger.Module
13 | import dagger.Provides
14 |
15 | @Module
16 | open class AppModule {
17 | @Provides
18 | @ApplicationScoped
19 | fun application(application: FooApplication): Context {
20 | return application
21 | }
22 |
23 | @Provides
24 | @ApplicationScoped
25 | fun dataSource(context: Context): DataSource {
26 | return DataSourceImpl.getInstance(context)
27 | }
28 |
29 | @ApplicationScoped
30 | @Provides
31 | fun jobExecutor(jobExecutor: JobExecutor): ThreadExecutor {
32 | return jobExecutor
33 | }
34 |
35 | @ApplicationScoped
36 | @Provides
37 | fun uiThread(uiThread: UiThread): PostExecutionThread {
38 | return uiThread
39 | }
40 |
41 | @ApplicationScoped
42 | @Provides
43 | fun usecaseHandler(): UseCaseHandler {
44 | return UseCaseHandler.getInstance
45 | }
46 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/woua/mvvm/clean/injection/ApplicationScoped.kt:
--------------------------------------------------------------------------------
1 | package com.woua.mvvm.clean.injection
2 |
3 | import javax.inject.Scope
4 |
5 | @Scope
6 | @Retention(AnnotationRetention.RUNTIME)
7 | annotation class ApplicationScoped
8 |
--------------------------------------------------------------------------------
/app/src/main/java/com/woua/mvvm/clean/injection/BaseFactory.kt:
--------------------------------------------------------------------------------
1 | package com.woua.mvvm.clean.injection
2 |
3 | import androidx.lifecycle.ViewModelProvider
4 | import dagger.Binds
5 | import dagger.Module
6 |
7 | @Module
8 | abstract class BaseFactory {
9 | @Binds
10 | abstract fun bindViewModelFactory(factory: ViewModelFactory): ViewModelProvider.Factory
11 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/woua/mvvm/clean/injection/Module.kt:
--------------------------------------------------------------------------------
1 | package com.woua.mvvm.clean.injection
2 |
3 | import com.woua.mvvm.clean.data.RepositoryImpl
4 | import com.woua.mvvm.clean.domain.Repository
5 | import dagger.Module
6 | import dagger.Provides
7 |
8 | @Module
9 | open class Module {
10 | @Provides
11 | fun repository(repositoryImpl: RepositoryImpl): Repository = repositoryImpl
12 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/woua/mvvm/clean/injection/ViewModelFactory.kt:
--------------------------------------------------------------------------------
1 | package com.woua.mvvm.clean.injection
2 |
3 | import androidx.lifecycle.ViewModel
4 | import androidx.lifecycle.ViewModelProvider
5 | import javax.inject.Inject
6 | import javax.inject.Provider
7 |
8 | class ViewModelFactory @Inject constructor(
9 | private val creators: Map, @JvmSuppressWildcards Provider>
10 | ) : ViewModelProvider.Factory {
11 | override fun create(modelClass: Class): T {
12 | val creator = creators[modelClass] ?: creators.entries.firstOrNull {
13 | modelClass.isAssignableFrom(it.key)
14 | }?.value ?: throw IllegalArgumentException("unknown model class $modelClass")
15 | try {
16 | @Suppress("UNCHECKED_CAST") return creator.get() as T
17 | } catch (e: Exception) {
18 | throw RuntimeException(e)
19 | }
20 |
21 | }
22 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/woua/mvvm/clean/injection/ViewModelKey.kt:
--------------------------------------------------------------------------------
1 | package com.woua.mvvm.clean.injection
2 |
3 | import androidx.lifecycle.ViewModel
4 | import dagger.MapKey
5 | import kotlin.reflect.KClass
6 |
7 | @MustBeDocumented
8 | @Target(
9 | AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER
10 | )
11 | @Retention(AnnotationRetention.RUNTIME)
12 | @MapKey
13 | annotation class ViewModelKey(val value: KClass)
--------------------------------------------------------------------------------
/app/src/main/java/com/woua/mvvm/clean/injection/ViewModelModule.kt:
--------------------------------------------------------------------------------
1 | package com.woua.mvvm.clean.injection
2 |
3 | import androidx.lifecycle.ViewModel
4 | import com.woua.mvvm.clean.FooViewModel
5 | import dagger.Binds
6 | import dagger.Module
7 | import dagger.multibindings.IntoMap
8 |
9 | @Module
10 | abstract class ViewModelModule : BaseFactory() {
11 | @Binds
12 | @IntoMap
13 | @ViewModelKey(FooViewModel::class)
14 | abstract fun fooViewModel(fooViewModel: FooViewModel): ViewModel
15 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
17 |
18 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dxaicorelabs/android-mvvm-clean/c788c14e6cbbd284d698fec8ab08fd818422cb7d/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dxaicorelabs/android-mvvm-clean/c788c14e6cbbd284d698fec8ab08fd818422cb7d/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dxaicorelabs/android-mvvm-clean/c788c14e6cbbd284d698fec8ab08fd818422cb7d/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dxaicorelabs/android-mvvm-clean/c788c14e6cbbd284d698fec8ab08fd818422cb7d/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dxaicorelabs/android-mvvm-clean/c788c14e6cbbd284d698fec8ab08fd818422cb7d/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dxaicorelabs/android-mvvm-clean/c788c14e6cbbd284d698fec8ab08fd818422cb7d/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dxaicorelabs/android-mvvm-clean/c788c14e6cbbd284d698fec8ab08fd818422cb7d/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dxaicorelabs/android-mvvm-clean/c788c14e6cbbd284d698fec8ab08fd818422cb7d/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dxaicorelabs/android-mvvm-clean/c788c14e6cbbd284d698fec8ab08fd818422cb7d/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dxaicorelabs/android-mvvm-clean/c788c14e6cbbd284d698fec8ab08fd818422cb7d/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #008577
4 | #00574B
5 | #D81B60
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | android-mvvm-clean
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/woua/mvvm/clean/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.woua.mvvm.clean
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/architecture_diagram.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dxaicorelabs/android-mvvm-clean/c788c14e6cbbd284d698fec8ab08fd818422cb7d/architecture_diagram.png
--------------------------------------------------------------------------------
/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.3.41'
5 | repositories {
6 | google()
7 | jcenter()
8 |
9 | }
10 | dependencies {
11 | classpath 'com.android.tools.build:gradle:3.5.0'
12 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
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 |
26 | task clean(type: Delete) {
27 | delete rootProject.buildDir
28 | }
29 |
--------------------------------------------------------------------------------
/buildSrc/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/buildSrc/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | `kotlin-dsl`
3 | }
4 |
5 | repositories {
6 | jcenter()
7 | }
--------------------------------------------------------------------------------
/buildSrc/src/main/java/dependencies/Deps.kt:
--------------------------------------------------------------------------------
1 | package dependencies
2 |
3 |
4 | object Deps {
5 | private const val path = "../common/gradle/"
6 | const val dependency = "./gradleScript/dependencies.gradle"
7 | val common = "${path}root.gradle"
8 |
9 | object Module {
10 | val remote = ":remote"
11 | val domain = ":domain"
12 | val data = ":data"
13 | val cache = ":cache"
14 | }
15 |
16 | object Kotlin {
17 | val kotlin_stdlib_jdk7 = "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${Version.kotlin}"
18 | }
19 |
20 | object Test {
21 | val test_junit = "junit:junit:${Version.junit}"
22 | val android_test_espresso_core =
23 | "com.android.support.test.espresso:espresso-core:${Version.espresso}"
24 | val android_test_rules = "com.android.support.test:rules:${Version.rules}"
25 | val android_test_runner = "com.android.support.test:runner:${Version.runner}"
26 | }
27 |
28 | object AndroidX {
29 | val fragment = "androidx.fragment:fragment:${Version.androidx}"
30 | val annotation = "androidx.annotation:annotation:${Version.androidx}"
31 | val core = "androidx.core:core:${Version.androidx}"
32 | val constraintlayout = "androidx.constraintlayout:constraintlayout:${Version.androidx_113}"
33 | val appcompat = "androidx.appcompat:appcompat:${Version.androidx}"
34 | }
35 |
36 | object OkHttp3 {
37 | val loggingInterceptor = "com.squareup.okhttp3:logging-interceptor:${Version.retrofit_log}"
38 | val okHttp3 = "com.squareup.okhttp3:okhttp:3.12.1"
39 | }
40 |
41 | object Retrofit2 {
42 | val adapterRxjava2 = "com.squareup.retrofit2:adapter-rxjava2:${Version.retrofit}"
43 | val converterGson = "com.squareup.retrofit2:converter-gson:${Version.retrofit}"
44 | val retrofit = "com.squareup.retrofit2:retrofit:${Version.retrofit}"
45 | }
46 |
47 | object RxJava {
48 | val rxAndroid = "io.reactivex.rxjava2:rxandroid:${Version.rxAndroid}"
49 | val rxjava2 = "io.reactivex.rxjava2:rxjava:${Version.rx}"
50 | }
51 |
52 | object Dagger {
53 | val dagger2 = "com.google.dagger:dagger:${Version.dagger2}"
54 | val daggerAndroid = "com.google.dagger:dagger-android:${Version.dagger2}"
55 | val daggerAndroidSupport = "com.google.dagger:dagger-android-support:${Version.dagger2}"
56 | val processor = "com.google.dagger:dagger-android-processor:${Version.dagger2}"
57 | val compiler = "com.google.dagger:dagger-compiler:${Version.dagger2}"
58 | }
59 |
60 | object Room {
61 | val runtime = "androidx.room:room-runtime:${Version.room}"
62 | val rxjava2 = "androidx.room:room-rxjava2:${Version.room}"
63 | val annotationProcessor = "androidx.room:room-compiler:${Version.room}"
64 | }
65 |
66 | val javax = "javax.inject:javax.inject:${Version.javaxInject}"
67 |
68 | val lifeCycleExtension = "androidx.lifecycle:lifecycle-extensions:2.0.0"
69 | }
--------------------------------------------------------------------------------
/buildSrc/src/main/java/dependencies/Version.kt:
--------------------------------------------------------------------------------
1 | package dependencies
2 |
3 |
4 | object Version {
5 | const val buildTools = "28.0.3"
6 | const val compileSdk = 29
7 | const val minSdk = 21
8 | const val targetSdk = 29
9 |
10 | const val glide = "4.9.0"
11 | const val gson = "2.8.5"
12 | const val junit = "4.12"
13 | const val kotlin = "1.3.41"
14 | const val espresso = "3.0.2"
15 | const val rules = "0.5"
16 | const val runner = "1.0.2"
17 | const val androidx = "1.0.2"
18 | const val androidx_113 = "1.1.3"
19 | const val retrofit = "2.5.0"
20 | const val retrofit_log = "3.10.0"
21 | const val rx = "2.1.0"
22 | const val rxAndroid = "2.0.1"
23 | const val rxRelay = "2.0.0"
24 | const val rxBinding = "2.0.0"
25 | const val javaxInject = "1"
26 | const val dagger2 = "2.21"
27 | const val room = "2.0.0-rc01"
28 | }
--------------------------------------------------------------------------------
/cache/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/cache/build.gradle:
--------------------------------------------------------------------------------
1 | import dependencies.*
2 |
3 | apply plugin: 'com.android.library'
4 | apply plugin: 'kotlin-android'
5 | apply plugin: 'kotlin-android-extensions'
6 | apply plugin: 'kotlin-kapt'
7 | apply from: Deps.dependency
8 | android {
9 | compileSdkVersion Version.compileSdk
10 | defaultConfig {
11 | minSdkVersion Version.minSdk
12 | targetSdkVersion Version.targetSdk
13 | versionCode 1
14 | versionName "1.0"
15 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
16 | consumerProguardFiles 'consumer-rules.pro'
17 | }
18 |
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
23 | }
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/cache/consumer-rules.pro:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dxaicorelabs/android-mvvm-clean/c788c14e6cbbd284d698fec8ab08fd818422cb7d/cache/consumer-rules.pro
--------------------------------------------------------------------------------
/cache/gradleScript/dependencies.gradle:
--------------------------------------------------------------------------------
1 | import dependencies.*
2 |
3 | apply from: Deps.common
4 |
5 | dependencies {
6 |
7 | //Room
8 | implementation Deps.Room.rxjava2
9 | implementation Deps.Room.runtime
10 | kapt Deps.Room.annotationProcessor
11 | }
--------------------------------------------------------------------------------
/cache/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 |
--------------------------------------------------------------------------------
/cache/src/androidTest/java/com/woua/mvvm/clean/cache/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.woua.mvvm.clean.cache
2 |
3 | import androidx.test.InstrumentationRegistry
4 | import androidx.test.platform.app.InstrumentationRegistry
5 | import androidx.test.ext.junit.runners.AndroidJUnit4
6 | import androidx.test.runner.AndroidJUnit4
7 |
8 | import org.junit.Test
9 | import org.junit.runner.RunWith
10 |
11 | import org.junit.Assert.*
12 |
13 | /**
14 | * Instrumented test, which will execute on an Android device.
15 | *
16 | * See [testing documentation](http://d.android.com/tools/testing).
17 | */
18 | @RunWith(AndroidJUnit4::class)
19 | class ExampleInstrumentedTest {
20 | @Test
21 | fun useAppContext() {
22 | // Context of the app under test.
23 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
24 | assertEquals("com.woua.mvvm.clean.remote.test", appContext.packageName)
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/cache/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/cache/src/main/java/com/woua/mvvm/clean/cache/BaseDao.kt:
--------------------------------------------------------------------------------
1 | package com.woua.mvvm.clean.cache
2 |
3 | import androidx.room.Delete
4 | import androidx.room.Insert
5 | import androidx.room.OnConflictStrategy
6 |
7 | interface BaseDao {
8 |
9 | @Insert
10 | fun insert(t: T)
11 |
12 | @Insert(onConflict = OnConflictStrategy.FAIL)
13 | fun insertWithFail(t: T)
14 |
15 | @Insert(onConflict = OnConflictStrategy.IGNORE)
16 | fun insertWithIgnore(t: T)
17 |
18 | @Insert(onConflict = OnConflictStrategy.REPLACE)
19 | fun insertWithReplace(t: T)
20 |
21 | @Insert(onConflict = OnConflictStrategy.ROLLBACK)
22 | fun insertWithRollback(t: T)
23 |
24 | @Insert
25 | fun insert(list: List)
26 |
27 | @Insert(onConflict = OnConflictStrategy.FAIL)
28 | fun insertWithFail(list: List)
29 |
30 | @Insert(onConflict = OnConflictStrategy.IGNORE)
31 | fun insertWithIgnore(list: List)
32 |
33 | @Insert(onConflict = OnConflictStrategy.REPLACE)
34 | fun insertWithReplace(list: List)
35 |
36 | @Insert(onConflict = OnConflictStrategy.ROLLBACK)
37 | fun insertWithRollback(list: List)
38 |
39 | @Delete
40 | fun delete(t: T)
41 |
42 | @Delete
43 | fun delete(list: List)
44 |
45 | }
--------------------------------------------------------------------------------
/cache/src/main/java/com/woua/mvvm/clean/cache/CacheSource.kt:
--------------------------------------------------------------------------------
1 | package com.woua.mvvm.clean.cache
2 |
3 | interface CacheSource {
4 | fun contact(): ContactDao
5 | }
--------------------------------------------------------------------------------
/cache/src/main/java/com/woua/mvvm/clean/cache/CacheSourceImpl.kt:
--------------------------------------------------------------------------------
1 | package com.woua.mvvm.clean.cache
2 |
3 | class CacheSourceImpl(var database: Database) : CacheSource {
4 | override fun contact(): ContactDao = database.contactDao()
5 | }
--------------------------------------------------------------------------------
/cache/src/main/java/com/woua/mvvm/clean/cache/ContactDao.kt:
--------------------------------------------------------------------------------
1 | package com.woua.mvvm.clean.cache
2 |
3 | import androidx.room.Dao
4 |
5 | @Dao
6 | interface ContactDao : BaseDao
--------------------------------------------------------------------------------
/cache/src/main/java/com/woua/mvvm/clean/cache/ContactEntity.kt:
--------------------------------------------------------------------------------
1 | package com.woua.mvvm.clean.cache
2 |
3 | import androidx.room.Entity
4 |
5 | @Entity(
6 | tableName = "contact",
7 | primaryKeys = ["id"]
8 | )
9 | //One to many relationship with address
10 | data class ContactEntity(
11 | var id: Int,
12 | var fistname: String?,
13 | var lastname: String?,
14 | var profilepic: String?
15 | )
--------------------------------------------------------------------------------
/cache/src/main/java/com/woua/mvvm/clean/cache/Database.kt:
--------------------------------------------------------------------------------
1 | package com.woua.mvvm.clean.cache
2 |
3 | import android.content.Context
4 | import androidx.room.Room
5 | import androidx.room.RoomDatabase
6 |
7 | @androidx.room.Database(
8 | entities = [ContactEntity::class],
9 | version = 1
10 | )
11 | abstract class Database : RoomDatabase() {
12 |
13 | abstract fun contactDao(): ContactDao
14 |
15 | companion object {
16 |
17 | private const val DB_NAME = "demo.db"
18 |
19 | @Volatile
20 | private var INSTANCE: Database? = null
21 |
22 | fun getInstance(context: Context): Database = INSTANCE ?: synchronized(this) {
23 | INSTANCE ?: buildDatabase(context).also { INSTANCE = it }
24 | }
25 |
26 | private fun buildDatabase(context: Context) = Room.databaseBuilder(
27 | context.applicationContext, Database::class.java, DB_NAME
28 | ).fallbackToDestructiveMigration().build()
29 |
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/cache/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | cache
3 |
4 |
--------------------------------------------------------------------------------
/cache/src/test/java/com/woua/mvvm/clean/remote/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.woua.mvvm.clean.remote
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/common/codestyle/kotlin_android.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 | xmlns:android
22 |
23 | ^$
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 | xmlns:.*
33 |
34 | ^$
35 |
36 |
37 | BY_NAME
38 |
39 |
40 |
41 |
42 |
43 |
44 | .*:id
45 |
46 | http://schemas.android.com/apk/res/android
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 | .*:name
56 |
57 | http://schemas.android.com/apk/res/android
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 | name
67 |
68 | ^$
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 | style
78 |
79 | ^$
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 | .*
89 |
90 | ^$
91 |
92 |
93 | BY_NAME
94 |
95 |
96 |
97 |
98 |
99 |
100 | .*
101 |
102 | http://schemas.android.com/apk/res/android
103 |
104 |
105 | ANDROID_ATTRIBUTE_ORDER
106 |
107 |
108 |
109 |
110 |
111 |
112 | .*
113 |
114 | .*
115 |
116 |
117 | BY_NAME
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
--------------------------------------------------------------------------------
/common/gradle/root.gradle:
--------------------------------------------------------------------------------
1 | import dependencies.*
2 |
3 | dependencies {
4 | implementation fileTree(dir: 'libs', include: ['*.jar'])
5 |
6 | implementation Deps.Kotlin.kotlin_stdlib_jdk7
7 |
8 | testImplementation Deps.Test.test_junit
9 | androidTestImplementation Deps.Test.android_test_espresso_core
10 | androidTestImplementation Deps.Test.android_test_rules
11 | androidTestImplementation Deps.Test.android_test_runner
12 | }
13 |
--------------------------------------------------------------------------------
/data/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/data/build.gradle:
--------------------------------------------------------------------------------
1 | import dependencies.*
2 |
3 | apply plugin: 'com.android.library'
4 | apply plugin: 'kotlin-android'
5 | apply plugin: 'kotlin-android-extensions'
6 | apply from: Deps.dependency
7 | android {
8 | compileSdkVersion Version.compileSdk
9 |
10 |
11 | defaultConfig {
12 | minSdkVersion Version.minSdk
13 | targetSdkVersion Version.targetSdk
14 | versionCode 1
15 | versionName "1.0"
16 |
17 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
18 | consumerProguardFiles 'consumer-rules.pro'
19 | }
20 |
21 | buildTypes {
22 | release {
23 | minifyEnabled false
24 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
25 | }
26 | }
27 |
28 | }
29 |
30 |
--------------------------------------------------------------------------------
/data/consumer-rules.pro:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dxaicorelabs/android-mvvm-clean/c788c14e6cbbd284d698fec8ab08fd818422cb7d/data/consumer-rules.pro
--------------------------------------------------------------------------------
/data/gradleScript/dependencies.gradle:
--------------------------------------------------------------------------------
1 | import dependencies.*
2 |
3 | apply from: Deps.common
4 |
5 | dependencies {
6 | implementation project(Deps.Module.cache)
7 | implementation project(Deps.Module.remote)
8 | implementation project(Deps.Module.domain)
9 |
10 | implementation Deps.RxJava.rxjava2
11 | implementation Deps.RxJava.rxAndroid
12 | implementation Deps.javax
13 | }
--------------------------------------------------------------------------------
/data/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 |
--------------------------------------------------------------------------------
/data/src/androidTest/java/com/woua/mvvm/clean/domain/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.woua.mvvm.clean.domain
2 |
3 | import androidx.test.platform.app.InstrumentationRegistry
4 | import androidx.test.ext.junit.runners.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22 | assertEquals("com.woua.mvvm.clean.domain.test", appContext.packageName)
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/data/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/data/src/main/java/com/woua/mvvm/clean/data/DataSource.kt:
--------------------------------------------------------------------------------
1 | package com.woua.mvvm.clean.data
2 |
3 | import com.woua.mvvm.clean.cache.CacheSource
4 | import com.woua.mvvm.clean.remote.RemoteSource
5 |
6 | interface DataSource {
7 | fun remote(): RemoteSource
8 | fun cache(): CacheSource
9 | }
--------------------------------------------------------------------------------
/data/src/main/java/com/woua/mvvm/clean/data/DataSourceImpl.kt:
--------------------------------------------------------------------------------
1 | package com.woua.mvvm.clean.data
2 |
3 | import android.content.Context
4 | import com.woua.mvvm.clean.cache.CacheSource
5 | import com.woua.mvvm.clean.cache.CacheSourceImpl
6 | import com.woua.mvvm.clean.cache.Database
7 | import com.woua.mvvm.clean.remote.RemoteSource
8 | import com.woua.mvvm.clean.remote.RemoteSourceImpl
9 | import javax.inject.Inject
10 |
11 | class DataSourceImpl @Inject constructor(context: Context) : DataSource {
12 |
13 | private var cache: CacheSource =
14 | CacheSourceImpl(Database.getInstance(context.applicationContext))
15 |
16 | private var remote: RemoteSource = RemoteSourceImpl()
17 |
18 | companion object : SingletonHolder(::DataSourceImpl)
19 |
20 | override fun remote(): RemoteSource = remote
21 |
22 | override fun cache(): CacheSource = cache
23 |
24 | }
--------------------------------------------------------------------------------
/data/src/main/java/com/woua/mvvm/clean/data/JobExecutor.kt:
--------------------------------------------------------------------------------
1 | package com.woua.mvvm.clean.data
2 |
3 | import com.woua.mvvm.clean.domain.ThreadExecutor
4 | import java.util.concurrent.*
5 | import javax.inject.Inject
6 |
7 | open class JobExecutor @Inject constructor() : ThreadExecutor {
8 |
9 | private val workQueue: LinkedBlockingQueue = LinkedBlockingQueue()
10 |
11 | private val threadPoolExecutor: ThreadPoolExecutor
12 |
13 | private val threadFactory: ThreadFactory
14 |
15 | init {
16 | this.threadFactory = JobThreadFactory()
17 | this.threadPoolExecutor = ThreadPoolExecutor(
18 | INITIAL_POOL_SIZE,
19 | MAX_POOL_SIZE,
20 | KEEP_ALIVE_TIME.toLong(),
21 | KEEP_ALIVE_TIME_UNIT,
22 | this.workQueue,
23 | this.threadFactory
24 | )
25 | }
26 |
27 | override fun execute(runnable: Runnable?) {
28 | requireNotNull(runnable) { "Runnable to execute cannot be null" }
29 | this.threadPoolExecutor.execute(runnable)
30 | }
31 |
32 | private class JobThreadFactory : ThreadFactory {
33 | private var counter = 0
34 |
35 | override fun newThread(runnable: Runnable): Thread {
36 | return Thread(runnable, THREAD_NAME + counter++)
37 | }
38 |
39 | companion object {
40 | private const val THREAD_NAME = "android_"
41 | }
42 | }
43 |
44 | companion object {
45 |
46 | private const val INITIAL_POOL_SIZE = 3
47 | private const val MAX_POOL_SIZE = 5
48 |
49 | // Sets the amount of time an idle thread waits before terminating
50 | private const val KEEP_ALIVE_TIME = 10
51 |
52 | // Sets the Time Unit to seconds
53 | private val KEEP_ALIVE_TIME_UNIT = TimeUnit.SECONDS
54 | }
55 | }
--------------------------------------------------------------------------------
/data/src/main/java/com/woua/mvvm/clean/data/RepositoryImpl.kt:
--------------------------------------------------------------------------------
1 | package com.woua.mvvm.clean.data
2 |
3 | import com.woua.mvvm.clean.cache.ContactEntity
4 | import com.woua.mvvm.clean.domain.ContactListUsecase
5 | import com.woua.mvvm.clean.domain.Repository
6 | import io.reactivex.Single
7 | import javax.inject.Inject
8 |
9 | class RepositoryImpl @Inject constructor(private val dataSource: DataSource) : Repository {
10 | override fun getContactList(): Single {
11 | return dataSource.remote().handler().getContactList().flatMap {
12 | val list = ArrayList()
13 | for (response in it) {
14 | list.add(
15 | ContactEntity(
16 | response.id,
17 | response.first_name,
18 | response.last_name,
19 | response.profile_pic
20 | )
21 | )
22 | }
23 | dataSource.cache().contact().insertWithReplace(list)
24 | Single.just(ContactListUsecase.ResponseValues(true))
25 | }
26 | }
27 | }
--------------------------------------------------------------------------------
/data/src/main/java/com/woua/mvvm/clean/data/SingletonHolder.kt:
--------------------------------------------------------------------------------
1 | package com.woua.mvvm.clean.data
2 |
3 | open class SingletonHolder(creator: (A) -> T) {
4 | private var creator: ((A) -> T)? = creator
5 | @Volatile
6 | private var instance: T? = null
7 |
8 | public fun getInstance(arg: A): T {
9 | var i = instance
10 | if (i != null) return i
11 | return synchronized(this) {
12 | val i2 = instance
13 | if (i2 != null) {
14 | return i2
15 | } else {
16 | val created = creator!!(arg)
17 | instance = created
18 | creator = null
19 | created
20 | }
21 | }
22 | }
23 | }
--------------------------------------------------------------------------------
/data/src/main/java/com/woua/mvvm/clean/data/UiThread.kt:
--------------------------------------------------------------------------------
1 | package com.woua.mvvm.clean.data
2 |
3 | import com.woua.mvvm.clean.domain.PostExecutionThread
4 | import io.reactivex.Scheduler
5 | import io.reactivex.android.schedulers.AndroidSchedulers
6 | import javax.inject.Inject
7 |
8 | open class UiThread @Inject constructor() : PostExecutionThread {
9 | override val scheduler: Scheduler = AndroidSchedulers.mainThread()
10 | }
11 |
--------------------------------------------------------------------------------
/data/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | data
3 |
4 |
--------------------------------------------------------------------------------
/data/src/test/java/com/woua/mvvm/clean/domain/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.woua.mvvm.clean.domain
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/domain/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/domain/build.gradle:
--------------------------------------------------------------------------------
1 | import dependencies.*
2 |
3 | apply plugin: 'com.android.library'
4 | apply plugin: 'kotlin-android'
5 | apply plugin: 'kotlin-android-extensions'
6 | apply from: Deps.dependency
7 | android {
8 | compileSdkVersion Version.compileSdk
9 |
10 |
11 | defaultConfig {
12 | minSdkVersion Version.minSdk
13 | targetSdkVersion Version.targetSdk
14 | versionCode 1
15 | versionName "1.0"
16 |
17 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
18 | consumerProguardFiles 'consumer-rules.pro'
19 | }
20 |
21 | buildTypes {
22 | release {
23 | minifyEnabled false
24 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
25 | }
26 | }
27 |
28 | }
29 |
30 |
--------------------------------------------------------------------------------
/domain/consumer-rules.pro:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dxaicorelabs/android-mvvm-clean/c788c14e6cbbd284d698fec8ab08fd818422cb7d/domain/consumer-rules.pro
--------------------------------------------------------------------------------
/domain/gradleScript/dependencies.gradle:
--------------------------------------------------------------------------------
1 | import dependencies.*
2 |
3 | apply from: Deps.common
4 |
5 | dependencies {
6 | //Rxjava
7 | implementation Deps.RxJava.rxjava2
8 |
9 | implementation Deps.javax
10 | }
--------------------------------------------------------------------------------
/domain/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 |
--------------------------------------------------------------------------------
/domain/src/androidTest/java/com/woua/mvvm/clean/domain/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.woua.mvvm.clean.domain
2 |
3 | import androidx.test.platform.app.InstrumentationRegistry
4 | import androidx.test.ext.junit.runners.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22 | assertEquals("com.woua.mvvm.clean.domain.test", appContext.packageName)
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/domain/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/domain/src/main/java/com/woua/mvvm/clean/domain/ContactListUsecase.kt:
--------------------------------------------------------------------------------
1 | package com.woua.mvvm.clean.domain
2 |
3 | import io.reactivex.Single
4 | import javax.inject.Inject
5 |
6 | class ContactListUsecase @Inject constructor(
7 | private val repository: Repository,
8 | threadExecutor: ThreadExecutor,
9 | postExecutionThread: PostExecutionThread
10 | ) : UseCase(
11 | threadExecutor, postExecutionThread
12 | ) {
13 |
14 | override fun buildUseCaseSingle(requestValues: RequestValues?): Single {
15 | return repository.getContactList()
16 | }
17 |
18 | data class RequestValues @JvmOverloads constructor(var dummy: String = "") : UseCase.RequestValues
19 |
20 | data class ResponseValues(
21 | val isSuccess: Boolean = false
22 | ) : ResponseValue
23 | }
--------------------------------------------------------------------------------
/domain/src/main/java/com/woua/mvvm/clean/domain/PostExecutionThread.kt:
--------------------------------------------------------------------------------
1 | package com.woua.mvvm.clean.domain
2 |
3 | import io.reactivex.Scheduler
4 |
5 | interface PostExecutionThread {
6 | val scheduler: Scheduler
7 | }
--------------------------------------------------------------------------------
/domain/src/main/java/com/woua/mvvm/clean/domain/Repository.kt:
--------------------------------------------------------------------------------
1 | package com.woua.mvvm.clean.domain
2 |
3 | import io.reactivex.Single
4 |
5 | interface Repository {
6 | fun getContactList(): Single
7 | }
--------------------------------------------------------------------------------
/domain/src/main/java/com/woua/mvvm/clean/domain/ThreadExecutor.kt:
--------------------------------------------------------------------------------
1 | package com.woua.mvvm.clean.domain
2 |
3 | import java.util.concurrent.Executor
4 |
5 | interface ThreadExecutor : Executor
--------------------------------------------------------------------------------
/domain/src/main/java/com/woua/mvvm/clean/domain/UseCase.kt:
--------------------------------------------------------------------------------
1 | package com.woua.mvvm.clean.domain
2 |
3 | import io.reactivex.Single
4 | import io.reactivex.disposables.CompositeDisposable
5 | import io.reactivex.disposables.Disposable
6 | import io.reactivex.observers.DisposableSingleObserver
7 | import io.reactivex.schedulers.Schedulers
8 |
9 | abstract class UseCase constructor(
10 | private val threadExecutor: ThreadExecutor, private val postExecutionThread: PostExecutionThread
11 | ) {
12 |
13 | private val disposables = CompositeDisposable()
14 |
15 | protected abstract fun buildUseCaseSingle(requestValues: REQ? = null): Single
16 |
17 | open fun execute(singleObserver: DisposableSingleObserver) {
18 | val single = this.buildUseCaseSingle(requestValues).subscribeOn(
19 | Schedulers.from(threadExecutor)
20 | ).observeOn(postExecutionThread.scheduler) as Single
21 | addDisposable(single.subscribeWith(singleObserver))
22 | }
23 |
24 | fun dispose() {
25 | if (!disposables.isDisposed) disposables.dispose()
26 | }
27 |
28 | private fun addDisposable(disposable: Disposable) {
29 | disposables.add(disposable)
30 | }
31 |
32 | var requestValues: REQ? = null
33 |
34 | interface RequestValues
35 |
36 | interface ResponseValue
37 |
38 | }
--------------------------------------------------------------------------------
/domain/src/main/java/com/woua/mvvm/clean/domain/UseCaseHandler.kt:
--------------------------------------------------------------------------------
1 | package com.woua.mvvm.clean.domain
2 |
3 | import io.reactivex.Scheduler
4 | import io.reactivex.observers.DisposableSingleObserver
5 | import javax.inject.Inject
6 |
7 | class UseCaseHandler @Inject constructor() {
8 |
9 | fun execute(
10 | useCase: UseCase, values: REQ, singleObserver: DisposableSingleObserver
11 | ) {
12 |
13 | useCase.requestValues = values
14 | useCase.execute(singleObserver)
15 | }
16 |
17 | companion object {
18 |
19 | private var INSTANCE: UseCaseHandler? = null
20 |
21 | val getInstance: UseCaseHandler
22 | get() {
23 | if (INSTANCE == null) {
24 | INSTANCE = UseCaseHandler()
25 | }
26 | return INSTANCE!!
27 | }
28 | }
29 | }
--------------------------------------------------------------------------------
/domain/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | domain
3 |
4 |
--------------------------------------------------------------------------------
/domain/src/test/java/com/woua/mvvm/clean/domain/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.woua.mvvm.clean.domain
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/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 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app's APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
20 | # Kotlin code style for this project: "official" or "obsolete":
21 | kotlin.code.style=official
22 | kapt.use.worker.api=true
23 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dxaicorelabs/android-mvvm-clean/c788c14e6cbbd284d698fec8ab08fd818422cb7d/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Oct 30 18:56:37 IST 2019
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.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 |
--------------------------------------------------------------------------------
/remote/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/remote/build.gradle:
--------------------------------------------------------------------------------
1 | import dependencies.*
2 |
3 | apply plugin: 'com.android.library'
4 | apply plugin: 'kotlin-android'
5 | apply plugin: 'kotlin-android-extensions'
6 | apply from: Deps.dependency
7 | android {
8 | compileSdkVersion Version.compileSdk
9 | defaultConfig {
10 | minSdkVersion Version.minSdk
11 | targetSdkVersion Version.targetSdk
12 | versionCode 1
13 | versionName "1.0"
14 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
15 | consumerProguardFiles 'consumer-rules.pro'
16 | }
17 |
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/remote/consumer-rules.pro:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dxaicorelabs/android-mvvm-clean/c788c14e6cbbd284d698fec8ab08fd818422cb7d/remote/consumer-rules.pro
--------------------------------------------------------------------------------
/remote/gradleScript/dependencies.gradle:
--------------------------------------------------------------------------------
1 | import dependencies.*
2 |
3 | apply from: Deps.common
4 |
5 | dependencies {
6 |
7 | //Retrofit
8 | implementation Deps.OkHttp3.loggingInterceptor
9 | implementation Deps.Retrofit2.adapterRxjava2
10 | implementation Deps.Retrofit2.converterGson
11 | implementation Deps.Retrofit2.retrofit
12 |
13 | //RxJava
14 | implementation Deps.RxJava.rxAndroid
15 | implementation Deps.RxJava.rxjava2
16 | }
--------------------------------------------------------------------------------
/remote/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 |
--------------------------------------------------------------------------------
/remote/src/androidTest/java/com/woua/mvvm/clean/remote/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.woua.mvvm.clean.remote
2 |
3 | import androidx.test.platform.app.InstrumentationRegistry
4 | import androidx.test.ext.junit.runners.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22 | assertEquals("com.woua.mvvm.clean.remote.test", appContext.packageName)
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/remote/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/remote/src/main/java/com/woua/mvvm/clean/remote/ApiHandler.kt:
--------------------------------------------------------------------------------
1 | package com.woua.mvvm.clean.remote
2 |
3 | import io.reactivex.Single
4 |
5 | interface ApiHandler {
6 | fun getContactList(): Single>
7 | }
--------------------------------------------------------------------------------
/remote/src/main/java/com/woua/mvvm/clean/remote/ApiHandlerImpl.kt:
--------------------------------------------------------------------------------
1 | package com.woua.mvvm.clean.remote
2 |
3 | class ApiHandlerImpl(private val restApi: RestApi) : ApiHandler {
4 | override fun getContactList() = restApi.getContactList()
5 | }
--------------------------------------------------------------------------------
/remote/src/main/java/com/woua/mvvm/clean/remote/RemoteSource.kt:
--------------------------------------------------------------------------------
1 | package com.woua.mvvm.clean.remote
2 |
3 | interface RemoteSource {
4 | fun handler(): ApiHandler
5 | }
--------------------------------------------------------------------------------
/remote/src/main/java/com/woua/mvvm/clean/remote/RemoteSourceImpl.kt:
--------------------------------------------------------------------------------
1 | package com.woua.mvvm.clean.remote
2 |
3 | import com.google.gson.GsonBuilder
4 | import okhttp3.OkHttpClient
5 | import okhttp3.logging.HttpLoggingInterceptor
6 | import retrofit2.Retrofit
7 | import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
8 | import retrofit2.converter.gson.GsonConverterFactory
9 | import java.util.concurrent.*
10 |
11 | class RemoteSourceImpl : RemoteSource {
12 |
13 | private val restApi: RestApi = restApi()
14 | private var apiHandler: ApiHandlerImpl = ApiHandlerImpl(restApi)
15 |
16 | companion object {
17 | const val CONNECT_TIME_OUT = 90
18 | const val READ_TIME_OUT = 90
19 | }
20 |
21 | override fun handler(): ApiHandler = apiHandler
22 |
23 | private fun restApi(): RestApi {
24 | return build(
25 | "https://firebasestorage.googleapis.com",
26 | getOkHttpClient(),
27 | createGsonConverterFactory()
28 | ).create(
29 | RestApi::class.java
30 | )
31 | }
32 |
33 | private fun build(
34 | baseUrl: String, okHttpClient: OkHttpClient, gsonConverterFactory: GsonConverterFactory
35 | ): Retrofit {
36 |
37 | return Retrofit.Builder().baseUrl(baseUrl).client(okHttpClient)
38 | .addConverterFactory(gsonConverterFactory)
39 | .addCallAdapterFactory(RxJava2CallAdapterFactory.create()).build()
40 | }
41 |
42 | private fun getOkHttpClient(): OkHttpClient {
43 | val builder = OkHttpClient.Builder()
44 | builder.connectTimeout(CONNECT_TIME_OUT.toLong(), TimeUnit.SECONDS)
45 | builder.readTimeout(READ_TIME_OUT.toLong(), TimeUnit.SECONDS)
46 |
47 | if (BuildConfig.DEBUG) {
48 | val logging = HttpLoggingInterceptor()
49 | logging.level = HttpLoggingInterceptor.Level.BODY
50 | builder.addInterceptor(logging)
51 | }
52 | // interceptor for logging
53 | return builder.build()
54 | }
55 |
56 | private fun createGsonConverterFactory(): GsonConverterFactory {
57 | val gson = GsonBuilder()
58 | .excludeFieldsWithoutExposeAnnotation().create()
59 | return GsonConverterFactory.create(gson)
60 | }
61 | }
--------------------------------------------------------------------------------
/remote/src/main/java/com/woua/mvvm/clean/remote/Response.kt:
--------------------------------------------------------------------------------
1 | package com.woua.mvvm.clean.remote
2 |
3 | import com.google.gson.annotations.Expose
4 | import com.google.gson.annotations.SerializedName
5 |
6 | data class Response(
7 | @SerializedName("id") @Expose val id: Int,
8 | @SerializedName("first_name") @Expose val first_name: String?,
9 | @SerializedName("last_name") @Expose val last_name: String?,
10 | @SerializedName("profile_pic") @Expose val profile_pic: String?
11 | )
--------------------------------------------------------------------------------
/remote/src/main/java/com/woua/mvvm/clean/remote/RestApi.kt:
--------------------------------------------------------------------------------
1 | package com.woua.mvvm.clean.remote
2 |
3 | import io.reactivex.Single
4 | import retrofit2.http.GET
5 |
6 | interface RestApi {
7 | @GET("/v0/b/api-demo-f6647.appspot.com/o/contacts.json?alt=media&token=7275ae23-3a65-49b6-8fe5-f8ff0c0cbc75")
8 | fun getContactList(): Single>
9 | }
--------------------------------------------------------------------------------
/remote/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | remote
3 |
4 |
--------------------------------------------------------------------------------
/remote/src/test/java/com/woua/mvvm/clean/remote/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.woua.mvvm.clean.remote
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':domain', ':remote', ':buildSrc', ':data', ':cache'
2 | rootProject.name='android-mvvm-clean'
3 |
--------------------------------------------------------------------------------