├── .gitignore
├── .idea
├── codeStyles
│ ├── Project.xml
│ └── codeStyleConfig.xml
├── gradle.xml
├── misc.xml
├── runConfigurations.xml
└── vcs.xml
├── README.md
├── architecture.png
├── build.gradle
├── clean_architecture.png
├── dagger2.png
├── data
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── example
│ │ └── data
│ │ └── ExampleInstrumentedTest.kt
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── example
│ │ │ └── data
│ │ │ ├── api
│ │ │ └── HackerNewsApi.kt
│ │ │ ├── db
│ │ │ └── MindevDataBase.kt
│ │ │ ├── entities
│ │ │ └── DataEntity.kt
│ │ │ ├── mapper
│ │ │ ├── DataHackerNewsMapper.kt
│ │ │ └── DataMapper.kt
│ │ │ ├── repository
│ │ │ └── HackerNewsRepositoryImpl.kt
│ │ │ └── source
│ │ │ └── news
│ │ │ ├── local
│ │ │ └── HackerNewsLocalDataSource.kt
│ │ │ └── remote
│ │ │ └── HackerNewsRemoteDataSource.kt
│ └── res
│ │ └── values
│ │ └── strings.xml
│ └── test
│ └── java
│ └── com
│ └── example
│ └── data
│ └── HackerNewsRepoTest.kt
├── domain
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── example
│ │ └── domain
│ │ └── ExampleInstrumentedTest.kt
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── example
│ │ │ └── domain
│ │ │ ├── HackerNewsRepository.kt
│ │ │ ├── Repository.kt
│ │ │ ├── entities
│ │ │ └── DomainEntity.kt
│ │ │ ├── extension
│ │ │ └── ReactiveExtension.kt
│ │ │ └── usecase
│ │ │ ├── BaseUseCase.kt
│ │ │ ├── ObsedrvableUseCase.kt
│ │ │ ├── SingleUseCase.kt
│ │ │ └── news
│ │ │ └── HackerNewsUseCase.kt
│ └── res
│ │ └── values
│ │ └── strings.xml
│ └── test
│ └── java
│ └── com
│ └── example
│ └── domain
│ └── HackerNewsUseCaseTest.kt
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── presentation
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── example
│ │ └── mindevandroidcleanarchitecturedemo
│ │ └── ExampleInstrumentedTest.kt
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── example
│ │ │ └── mindevandroidcleanarchitecturedemo
│ │ │ ├── MindevApplication.kt
│ │ │ ├── base
│ │ │ ├── MindevActivity.kt
│ │ │ └── MindevViewModel.kt
│ │ │ ├── di
│ │ │ ├── MindevComponent.kt
│ │ │ ├── module
│ │ │ │ ├── ActivityBindingModule.kt
│ │ │ │ ├── AppModule.kt
│ │ │ │ ├── MainViewModelFactory.kt
│ │ │ │ ├── NetWorkModule.kt
│ │ │ │ └── main
│ │ │ │ │ └── MainModule.kt
│ │ │ └── qualifier
│ │ │ │ ├── ApplicationContext.kt
│ │ │ │ ├── PerActivity.kt
│ │ │ │ └── ViewModelKey.kt
│ │ │ ├── entities
│ │ │ └── PresentationEntity.kt
│ │ │ ├── extension
│ │ │ ├── ArchitectureComponentsExtension.kt
│ │ │ └── ContextExtension.kt
│ │ │ ├── mapper
│ │ │ ├── PresentationHackerNewsMapper.kt
│ │ │ └── PresenterMapper.kt
│ │ │ ├── ui
│ │ │ ├── MainActivity.kt
│ │ │ ├── MainAdapter.kt
│ │ │ └── MainViewHolder.kt
│ │ │ └── vm
│ │ │ └── MainViewModel.kt
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ └── ic_launcher_background.xml
│ │ ├── layout
│ │ ├── activity_main.xml
│ │ └── item_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
│ └── example
│ └── mindevandroidcleanarchitecturedemo
│ └── HackerNewsVMTest.kt
├── preview.png
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | # Created by https://www.gitignore.io/api/git,java,kotlin,android,firebase,androidstudio
3 | # Edit at https://www.gitignore.io/?templates=git,java,kotlin,android,firebase,androidstudio
4 |
5 | ### Android ###
6 | # Built application files
7 | *.apk
8 | *.ap_
9 | *.aab
10 |
11 | # Files for the ART/Dalvik VM
12 | *.dex
13 |
14 | # Java class files
15 | *.class
16 |
17 | # Generated files
18 | bin/
19 | gen/
20 | out/
21 |
22 | # Gradle files
23 | .gradle/
24 | build/
25 |
26 | # Local configuration file (sdk path, etc)
27 | local.properties
28 | secret.properties
29 |
30 | # Proguard folder generated by Eclipse
31 | proguard/
32 |
33 | # Log Files
34 | *.log
35 |
36 | # Android Studio Navigation editor temp files
37 | .navigation/
38 |
39 | # Android Studio captures folder
40 | captures/
41 |
42 | # IntelliJ
43 | *.iml
44 | .idea/workspace.xml
45 | .idea/tasks.xml
46 | .idea/gradle.xml
47 | .idea/assetWizardSettings.xml
48 | .idea/dictionaries
49 | .idea/libraries
50 | .idea/caches
51 |
52 | # Keystore files
53 | # Uncomment the following lines if you do not want to check your keystore files in.
54 | #*.jks
55 | #*.keystore
56 |
57 | # External native build folder generated in Android Studio 2.2 and later
58 | .externalNativeBuild
59 |
60 | # Google Services (e.g. APIs or Firebase)
61 | google-services.json
62 |
63 | # Freeline
64 | freeline.py
65 | freeline/
66 | freeline_project_description.json
67 |
68 | # fastlane
69 | fastlane/report.xml
70 | fastlane/Preview.html
71 | fastlane/screenshots
72 | fastlane/test_output
73 | fastlane/readme.md
74 |
75 | ### Android Patch ###
76 | gen-external-apklibs
77 |
78 | ### AndroidStudio ###
79 | # Covers files to be ignored for android development using Android Studio.
80 |
81 | # Built application files
82 |
83 | # Files for the ART/Dalvik VM
84 |
85 | # Java class files
86 |
87 | # Generated files
88 |
89 | # Gradle files
90 | .gradle
91 |
92 | # Signing files
93 | .signing/
94 |
95 | # Local configuration file (sdk path, etc)
96 |
97 | # Proguard folder generated by Eclipse
98 |
99 | # Log Files
100 |
101 | # Android Studio
102 | /*/build/
103 | /*/local.properties
104 | /*/out
105 | /*/*/build
106 | /*/*/production
107 | *.ipr
108 | *~
109 | *.swp
110 |
111 | # Android Patch
112 |
113 | # External native build folder generated in Android Studio 2.2 and later
114 |
115 | # NDK
116 | obj/
117 |
118 | # IntelliJ IDEA
119 | *.iws
120 | /out/
121 |
122 | # User-specific configurations
123 | .idea/caches/
124 | .idea/libraries/
125 | .idea/shelf/
126 | .idea/.name
127 | .idea/compiler.xml
128 | .idea/copyright/profiles_settings.xml
129 | .idea/encodings.xml
130 | .idea/misc.xml
131 | .idea/modules.xml
132 | .idea/scopes/scope_settings.xml
133 | .idea/vcs.xml
134 | .idea/jsLibraryMappings.xml
135 | .idea/datasources.xml
136 | .idea/dataSources.ids
137 | .idea/sqlDataSources.xml
138 | .idea/dynamic.xml
139 | .idea/uiDesigner.xml
140 |
141 | # OS-specific files
142 | .DS_Store
143 | .DS_Store?
144 | ._*
145 | .Spotlight-V100
146 | .Trashes
147 | ehthumbs.db
148 | Thumbs.db
149 |
150 | # Legacy Eclipse project files
151 | .classpath
152 | .project
153 | .cproject
154 | .settings/
155 |
156 | # Mobile Tools for Java (J2ME)
157 | .mtj.tmp/
158 |
159 | # Package Files #
160 | *.war
161 | *.ear
162 |
163 | # virtual machine crash logs (Reference: http://www.java.com/en/download/help/error_hotspot.xml)
164 | hs_err_pid*
165 |
166 | ## Plugin-specific files:
167 |
168 | # mpeltonen/sbt-idea plugin
169 | .idea_modules/
170 |
171 | # JIRA plugin
172 | atlassian-ide-plugin.xml
173 |
174 | # Mongo Explorer plugin
175 | .idea/mongoSettings.xml
176 |
177 | # Crashlytics plugin (for Android Studio and IntelliJ)
178 | com_crashlytics_export_strings.xml
179 | crashlytics.properties
180 | crashlytics-build.properties
181 | fabric.properties
182 |
183 | ### AndroidStudio Patch ###
184 |
185 | !/gradle/wrapper/gradle-wrapper.jar
186 |
187 | ### Firebase ###
188 | .idea
189 | **/node_modules/*
190 | **/.firebaserc
191 |
192 | ### Firebase Patch ###
193 | .runtimeconfig.json
194 | .firebase/
195 |
196 | ### Git ###
197 | # Created by git for backups. To disable backups in Git:
198 | # $ git config --global mergetool.keepBackup false
199 | *.orig
200 |
201 | # Created by git when using merge tools for conflicts
202 | *.BACKUP.*
203 | *.BASE.*
204 | *.LOCAL.*
205 | *.REMOTE.*
206 | *_BACKUP_*.txt
207 | *_BASE_*.txt
208 | *_LOCAL_*.txt
209 | *_REMOTE_*.txt
210 |
211 | ### Java ###
212 | # Compiled class file
213 |
214 | # Log file
215 |
216 | # BlueJ files
217 | *.ctxt
218 |
219 | # Mobile Tools for Java (J2ME)
220 |
221 | # Package Files #
222 | *.jar
223 | *.nar
224 | *.zip
225 | *.tar.gz
226 | *.rar
227 |
228 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
229 |
230 | ### Kotlin ###
231 | # Compiled class file
232 |
233 | # Log file
234 |
235 | # BlueJ files
236 |
237 | # Mobile Tools for Java (J2ME)
238 |
239 | # Package Files #
240 |
241 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
242 |
243 | # End of https://www.gitignore.io/api/git,java,kotlin,android,firebase,androidstudio
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/.idea/codeStyles/codeStyleConfig.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
19 |
20 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Explanation
2 | -----------------
3 |
4 | Hi👋:)
5 |
6 | I created clean architecture samples for three purposes.
7 |
8 | 1. Study on clean architecture
9 | 2. Modular separation
10 | 3. Unit test using Mockito
11 |
12 |
13 | Screenshots
14 | -----------------
15 |
16 | 
17 |
18 |
19 | REST API
20 | -----------------
21 | https://github.com/tastejs/hacker-news-pwas
22 |
23 |
24 | Languages, libraries and tools used
25 | -----------------
26 |
27 | * Kotlin
28 | * AAC ViewModel
29 | * LiveData
30 | * AndroidX Support Libraries
31 | * RxKotlin
32 | * Dagger2
33 | * Retrofit
34 | * OkHttp3
35 | * Gson
36 | * Mockito
37 |
38 |
39 | Clean architecture
40 | -----------------
41 | 
42 |
43 |
44 | Architectural approach
45 | -----------------
46 | 
47 |
48 |
49 | Dagger2
50 | -----------------
51 | 
52 |
53 |
54 | Thanks
55 | -----------------
56 | - https://github.com/android10/Android-CleanArchitecture
57 |
58 | - https://github.com/android10/Android-CleanArchitecture-Kotlin
59 |
60 | - https://github.com/googlesamples/android-architecture
61 |
62 | - https://github.com/bufferapp/clean-architecture-components-boilerplate
63 |
--------------------------------------------------------------------------------
/architecture.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkw8263/AndroidCleanArchitectureDemo/132fe99d4f4e23d9537acc8fcabd4b2a30778983/architecture.png
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | ext.kotlin_version = '1.3.21'
3 | repositories {
4 | google()
5 | jcenter()
6 |
7 | }
8 | dependencies {
9 | classpath 'com.android.tools.build:gradle:3.3.1'
10 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
11 | // NOTE: Do not place your application dependencies here; they belong
12 | // in the individual module build.gradle files
13 | }
14 | }
15 |
16 | allprojects {
17 | repositories {
18 | google()
19 | jcenter()
20 |
21 | }
22 | }
23 |
24 | task clean(type: Delete) {
25 | delete rootProject.buildDir
26 | }
27 |
--------------------------------------------------------------------------------
/clean_architecture.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkw8263/AndroidCleanArchitectureDemo/132fe99d4f4e23d9537acc8fcabd4b2a30778983/clean_architecture.png
--------------------------------------------------------------------------------
/dagger2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkw8263/AndroidCleanArchitectureDemo/132fe99d4f4e23d9537acc8fcabd4b2a30778983/dagger2.png
--------------------------------------------------------------------------------
/data/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/data/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android-extensions'
3 | apply plugin: 'kotlin-android'
4 | apply plugin: 'kotlin-kapt'
5 | android {
6 | compileSdkVersion 28
7 |
8 |
9 |
10 | defaultConfig {
11 | minSdkVersion 23
12 | targetSdkVersion 28
13 | versionCode 1
14 | versionName "1.0"
15 |
16 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
17 |
18 | }
19 |
20 | buildTypes {
21 | release {
22 | minifyEnabled false
23 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
24 | }
25 | }
26 |
27 | }
28 |
29 | dependencies {
30 | implementation fileTree(dir: 'libs', include: ['*.jar'])
31 |
32 | implementation 'com.android.support:appcompat-v7:28.0.0'
33 | testImplementation 'junit:junit:4.12'
34 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
35 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
36 | testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.1.0"
37 | // retrofit2
38 | api 'com.squareup.retrofit2:retrofit:2.5.0'
39 | api 'com.squareup.retrofit2:converter-gson:2.5.0'
40 | api 'com.squareup.okhttp3:logging-interceptor:3.13.1'
41 | api 'com.squareup.retrofit2:adapter-rxjava2:2.5.0'
42 |
43 | // dagger2
44 | def dagger2_version = "2.21"
45 | implementation "com.google.dagger:dagger:$dagger2_version"
46 | implementation "com.google.dagger:dagger-android:$dagger2_version"
47 | implementation "com.google.dagger:dagger-android-support:$dagger2_version"
48 | kapt "com.google.dagger:dagger-android-processor:$dagger2_version"
49 | kapt "com.google.dagger:dagger-compiler:$dagger2_version"
50 |
51 | // Reactivex
52 | api 'io.reactivex.rxjava2:rxandroid:2.1.0'
53 | api 'io.reactivex.rxjava2:rxkotlin:2.3.0'
54 |
55 | // gson
56 | api 'com.google.code.gson:gson:2.8.5'
57 | api "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
58 |
59 |
60 | implementation project(':domain')
61 | }
62 | repositories {
63 | mavenCentral()
64 | }
65 |
--------------------------------------------------------------------------------
/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/example/data/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.example.data
2 |
3 | import androidx.test.InstrumentationRegistry
4 | import androidx.test.runner.AndroidJUnit4
5 | import junit.framework.Assert.assertEquals
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | /**
10 | * Instrumented test, which will execute on an Android device.
11 | *
12 | * @see Testing documentation
13 | */
14 | @RunWith(AndroidJUnit4::class)
15 | class ExampleInstrumentedTest {
16 | @Test
17 | fun useAppContext() {
18 | // Context of the app under test.
19 | val appContext = InstrumentationRegistry.getTargetContext()
20 | assertEquals("com.example.data.test", appContext.packageName)
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/data/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/data/src/main/java/com/example/data/api/HackerNewsApi.kt:
--------------------------------------------------------------------------------
1 | package com.example.data.api
2 |
3 | import com.example.data.entities.DataEntity
4 | import io.reactivex.Observable
5 | import io.reactivex.Single
6 | import retrofit2.http.GET
7 | import retrofit2.http.Query
8 |
9 | interface HackerNewsApi {
10 |
11 | @GET("/news")
12 | fun getHackerNews(@Query("page") page: Int): Single>
13 |
14 | @GET("/news")
15 | fun getHackerNewsOB(@Query("page") page: Int): Observable>
16 | }
--------------------------------------------------------------------------------
/data/src/main/java/com/example/data/db/MindevDataBase.kt:
--------------------------------------------------------------------------------
1 | package com.example.data.db
2 |
3 | class MindevDataBase {
4 | }
--------------------------------------------------------------------------------
/data/src/main/java/com/example/data/entities/DataEntity.kt:
--------------------------------------------------------------------------------
1 | package com.example.data.entities
2 |
3 | sealed class DataEntity {
4 | data class HackerNews(
5 | var comments_count: Int? = 0,
6 | var domain: String? = "",
7 | var id: Int? = 0,
8 | var points: Int? = 0,
9 | var time: Int? = 0,
10 | var time_ago: String? = "",
11 | var title: String? = "",
12 | var type: String? = "",
13 | var url: String? = "",
14 | var user: String? = ""
15 | ) : DataEntity()
16 | }
--------------------------------------------------------------------------------
/data/src/main/java/com/example/data/mapper/DataHackerNewsMapper.kt:
--------------------------------------------------------------------------------
1 | package com.example.data.mapper
2 |
3 | import com.example.data.entities.DataEntity
4 | import com.example.domain.entities.DomainEntity
5 | import javax.inject.Inject
6 |
7 | open class DataHackerNewsMapper @Inject constructor() :
8 | DataMapper, List> {
9 | override fun mapFromEntity(type: List): List {
10 | return type.map { data ->
11 | DomainEntity.HackerNews(data.comments_count, data.id, data.time_ago, data.title)
12 | }
13 | }
14 |
15 | override fun mapToEntity(type: List): List {
16 | return type.map { data ->
17 | DataEntity.HackerNews().apply {
18 | comments_count = data.comments_count
19 | time_ago = data.time_ago
20 | title = data.title
21 | id = data.id
22 | }
23 | }
24 | }
25 | }
--------------------------------------------------------------------------------
/data/src/main/java/com/example/data/mapper/DataMapper.kt:
--------------------------------------------------------------------------------
1 | package com.example.data.mapper
2 |
3 | interface DataMapper {
4 | fun mapFromEntity(type: E): D
5 | fun mapToEntity(type: D): E
6 | }
--------------------------------------------------------------------------------
/data/src/main/java/com/example/data/repository/HackerNewsRepositoryImpl.kt:
--------------------------------------------------------------------------------
1 | package com.example.data.repository
2 |
3 | import com.example.data.mapper.DataHackerNewsMapper
4 | import com.example.data.source.news.local.HackerNewsLocalDataSource
5 | import com.example.data.source.news.remote.HackerNewsRemoteDataSource
6 | import com.example.domain.HackerNewsRepository
7 | import com.example.domain.entities.DomainEntity
8 | import io.reactivex.Observable
9 | import io.reactivex.Single
10 |
11 | open class HackerNewsRepositoryImpl(
12 | private val hackerNewsLocalDataSource: HackerNewsLocalDataSource,
13 | private val hackerNewsRemoteDataSource: HackerNewsRemoteDataSource,
14 | private val hackerNewsMapper: DataHackerNewsMapper
15 | ) : HackerNewsRepository {
16 | override fun getHackerNewsList(page: Int?): Single> {
17 | return hackerNewsRemoteDataSource.getHackerNewsList(page ?: 0).map { data ->
18 | hackerNewsMapper.mapFromEntity(data)
19 | }
20 | }
21 |
22 | override fun getHackerNewsListOB(page: Int?): Observable> {
23 | return hackerNewsRemoteDataSource.getHackerNewsListOB(page ?: 0).map { data ->
24 | hackerNewsMapper.mapFromEntity(data)
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/data/src/main/java/com/example/data/source/news/local/HackerNewsLocalDataSource.kt:
--------------------------------------------------------------------------------
1 | package com.example.data.source.news.local
2 |
3 | import com.example.data.entities.DataEntity
4 | import io.reactivex.Observable
5 | import io.reactivex.Single
6 | import javax.inject.Inject
7 |
8 | open class HackerNewsLocalDataSource @Inject constructor() {
9 | fun getHackerNewsList(page: Int): Single> {
10 | return Single.never()
11 | }
12 |
13 | fun getHackerNewsListOB(page: Int): Observable> {
14 | return Observable.empty()
15 | }
16 | }
--------------------------------------------------------------------------------
/data/src/main/java/com/example/data/source/news/remote/HackerNewsRemoteDataSource.kt:
--------------------------------------------------------------------------------
1 | package com.example.data.source.news.remote
2 |
3 | import com.example.data.api.HackerNewsApi
4 | import com.example.data.entities.DataEntity
5 | import io.reactivex.Observable
6 | import io.reactivex.Single
7 |
8 | open class HackerNewsRemoteDataSource(private val hackerNewsApi: HackerNewsApi) {
9 | open fun getHackerNewsList(page: Int): Single> {
10 | return hackerNewsApi.getHackerNews(page)
11 | }
12 |
13 | open fun getHackerNewsListOB(page: Int): Observable> {
14 | return hackerNewsApi.getHackerNewsOB(page)
15 | }
16 | }
--------------------------------------------------------------------------------
/data/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | data
3 |
4 |
--------------------------------------------------------------------------------
/data/src/test/java/com/example/data/HackerNewsRepoTest.kt:
--------------------------------------------------------------------------------
1 | package com.example.data
2 |
3 | import com.example.data.api.HackerNewsApi
4 | import com.example.data.entities.DataEntity
5 | import com.example.data.mapper.DataHackerNewsMapper
6 | import com.example.data.repository.HackerNewsRepositoryImpl
7 | import com.example.data.source.news.remote.HackerNewsRemoteDataSource
8 | import com.example.domain.entities.DomainEntity
9 | import com.nhaarman.mockitokotlin2.given
10 | import com.nhaarman.mockitokotlin2.mock
11 | import com.nhaarman.mockitokotlin2.verify
12 | import io.reactivex.Single
13 | import okhttp3.OkHttpClient
14 | import org.junit.Test
15 | import retrofit2.Retrofit
16 | import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
17 | import retrofit2.converter.gson.GsonConverterFactory
18 |
19 | class HackerNewsRepoTest {
20 | private var hackerNewsApi = providesRetrofit()
21 |
22 | @Test
23 | fun `check, remote data values`() {
24 | val list: MutableList = mutableListOf()
25 | list.apply {
26 | add(DataEntity.HackerNews(0, "1", 0, 0, 0, "1", "1", "1", "1", "1"))
27 | add(DataEntity.HackerNews(0, "1", 0, 0, 0, "1", "1", "1", "1", "1"))
28 | add(DataEntity.HackerNews(0, "1", 0, 0, 0, "1", "1", "1", "1", "1"))
29 | add(DataEntity.HackerNews(0, "1", 0, 0, 0, "1", "1", "1", "1", "1"))
30 | }
31 |
32 | val hackerNewsRemoteDataSource: HackerNewsRemoteDataSource = mock()
33 | given { hackerNewsRemoteDataSource.getHackerNewsList(3) }.willReturn(Single.just(list))
34 |
35 | hackerNewsRemoteDataSource.getHackerNewsList(3)
36 | .test()
37 | .assertNoErrors()
38 | .assertComplete()
39 | .assertValue(list)
40 |
41 | verify(hackerNewsRemoteDataSource).getHackerNewsList(3)
42 | }
43 |
44 | @Test
45 | fun `check, DataEntity change DomainEntity`() {
46 | val list: ArrayList = ArrayList()
47 | list.apply {
48 | add(DataEntity.HackerNews(0, "1", 0, 0, 0, "1", "1", "1", "1", "1"))
49 | add(DataEntity.HackerNews(0, "1", 0, 0, 0, "1", "1", "1", "1", "1"))
50 | add(DataEntity.HackerNews(0, "1", 0, 0, 0, "1", "1", "1", "1", "1"))
51 | add(DataEntity.HackerNews(0, "1", 0, 0, 0, "1", "1", "1", "1", "1"))
52 | }
53 |
54 | val hackerNewsRemoteDataSource: HackerNewsRemoteDataSource = mock()
55 | given { hackerNewsRemoteDataSource.getHackerNewsList(3) }.willReturn(Single.just(list))
56 |
57 | val list2: ArrayList = ArrayList()
58 | list2.apply {
59 | add(DomainEntity.HackerNews(0, 0, "1", "1"))
60 | add(DomainEntity.HackerNews(0, 0, "1", "1"))
61 | add(DomainEntity.HackerNews(0, 0, "1", "1"))
62 | add(DomainEntity.HackerNews(0, 0, "1", "1"))
63 | }
64 |
65 | val hackerNewsMapper = DataHackerNewsMapper()
66 | hackerNewsRemoteDataSource.getHackerNewsList(3)
67 | .map { hackerNewsMapper.mapFromEntity(it) }
68 | .test()
69 | .assertNoErrors()
70 | .assertComplete()
71 | .assertValue(list2)
72 |
73 | verify(hackerNewsRemoteDataSource).getHackerNewsList(3)
74 | }
75 |
76 | @Test
77 | fun `check, repository data`() {
78 | val list: MutableList = mutableListOf()
79 | list.apply {
80 | add(DomainEntity.HackerNews(0, 0, "1"))
81 | add(DomainEntity.HackerNews(0, 0, "1"))
82 | add(DomainEntity.HackerNews(0, 0, "1"))
83 | add(DomainEntity.HackerNews(0, 0, "1"))
84 | }
85 |
86 | val hackerNewsRepositoryImpl: HackerNewsRepositoryImpl = mock()
87 | given { hackerNewsRepositoryImpl.getHackerNewsList(3) }.willReturn(Single.just(list))
88 | hackerNewsRepositoryImpl.getHackerNewsList(3)
89 | .test()
90 | .assertNoErrors()
91 | .assertComplete()
92 | .assertValue(list)
93 |
94 | verify(hackerNewsRepositoryImpl).getHackerNewsList(3)
95 | }
96 |
97 | @Test
98 | fun `network request`() {
99 | val result = hackerNewsApi.getHackerNews(3)
100 | .map { data ->
101 | data.map { "title: ${it.title}, time_ago: ${it.time_ago}, comments_count: ${it.comments_count}, user: ${it.user}\n" }
102 | }.blockingGet()
103 | print(result)
104 | }
105 |
106 | private fun providesRetrofit(): HackerNewsApi {
107 | return Retrofit.Builder()
108 | .baseUrl("http://api.hackerwebapp.com/")
109 | .client(OkHttpClient.Builder().build())
110 | .addConverterFactory(GsonConverterFactory.create())
111 | .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
112 | .build()
113 | .create(HackerNewsApi::class.java)
114 | }
115 | }
--------------------------------------------------------------------------------
/domain/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/domain/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android-extensions'
3 | apply plugin: 'kotlin-android'
4 | apply plugin: 'kotlin-kapt'
5 | android {
6 | compileSdkVersion 28
7 |
8 |
9 |
10 | defaultConfig {
11 | minSdkVersion 23
12 | targetSdkVersion 28
13 | versionCode 1
14 | versionName "1.0"
15 |
16 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
17 |
18 | }
19 |
20 | buildTypes {
21 | release {
22 | minifyEnabled false
23 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
24 | }
25 | }
26 |
27 | }
28 |
29 | dependencies {
30 | implementation fileTree(dir: 'libs', include: ['*.jar'])
31 |
32 | implementation 'com.android.support:appcompat-v7:28.0.0'
33 | testImplementation 'junit:junit:4.12'
34 | testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.1.0"
35 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
36 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
37 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
38 |
39 |
40 | // Reactivex
41 | implementation 'io.reactivex.rxjava2:rxandroid:2.1.0'
42 | implementation 'io.reactivex.rxjava2:rxkotlin:2.3.0'
43 | }
44 | repositories {
45 | mavenCentral()
46 | }
47 |
--------------------------------------------------------------------------------
/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/example/domain/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.example.domain
2 |
3 | import androidx.test.InstrumentationRegistry
4 | import androidx.test.runner.AndroidJUnit4
5 | import junit.framework.Assert.assertEquals
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | /**
10 | * Instrumented test, which will execute on an Android device.
11 | *
12 | * @see Testing documentation
13 | */
14 | @RunWith(AndroidJUnit4::class)
15 | class ExampleInstrumentedTest {
16 | @Test
17 | fun useAppContext() {
18 | // Context of the app under test.
19 | val appContext = InstrumentationRegistry.getTargetContext()
20 | assertEquals("com.example.domain.test", appContext.packageName)
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/domain/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/domain/src/main/java/com/example/domain/HackerNewsRepository.kt:
--------------------------------------------------------------------------------
1 | package com.example.domain
2 |
3 | import com.example.domain.entities.DomainEntity
4 | import io.reactivex.Observable
5 | import io.reactivex.Single
6 |
7 | interface HackerNewsRepository : Repository {
8 |
9 | fun getHackerNewsList(page: Int?): Single>
10 |
11 | fun getHackerNewsListOB(page: Int?): Observable>
12 | }
--------------------------------------------------------------------------------
/domain/src/main/java/com/example/domain/Repository.kt:
--------------------------------------------------------------------------------
1 | package com.example.domain
2 |
3 | interface Repository
--------------------------------------------------------------------------------
/domain/src/main/java/com/example/domain/entities/DomainEntity.kt:
--------------------------------------------------------------------------------
1 | package com.example.domain.entities
2 |
3 | sealed class DomainEntity {
4 | data class HackerNews(
5 | val comments_count: Int? = 0,
6 | val id: Int? = 0,
7 | val time_ago: String? = "",
8 | val title: String? = ""
9 | ) : DomainEntity()
10 | }
--------------------------------------------------------------------------------
/domain/src/main/java/com/example/domain/extension/ReactiveExtension.kt:
--------------------------------------------------------------------------------
1 | package com.example.domain.extension
2 |
3 | import io.reactivex.Single
4 | import io.reactivex.android.schedulers.AndroidSchedulers
5 | import io.reactivex.schedulers.Schedulers
6 |
7 | fun Single.networkCommunityThread(): Single {
8 | return this.subscribeOn(Schedulers.io())
9 | .observeOn(AndroidSchedulers.mainThread())
10 | }
--------------------------------------------------------------------------------
/domain/src/main/java/com/example/domain/usecase/BaseUseCase.kt:
--------------------------------------------------------------------------------
1 | package com.example.domain.usecase
2 |
3 | interface BaseUseCase
--------------------------------------------------------------------------------
/domain/src/main/java/com/example/domain/usecase/ObsedrvableUseCase.kt:
--------------------------------------------------------------------------------
1 | package com.example.domain.usecase
2 |
3 | import io.reactivex.Observable
4 |
5 | interface ObservableUseCase : BaseUseCase {
6 | fun execute(params: Params?): Observable
7 | }
8 |
--------------------------------------------------------------------------------
/domain/src/main/java/com/example/domain/usecase/SingleUseCase.kt:
--------------------------------------------------------------------------------
1 | package com.example.domain.usecase
2 |
3 | import io.reactivex.Single
4 |
5 | interface SingleUseCase : BaseUseCase {
6 | fun execute(params: Params?): Single
7 | }
--------------------------------------------------------------------------------
/domain/src/main/java/com/example/domain/usecase/news/HackerNewsUseCase.kt:
--------------------------------------------------------------------------------
1 | package com.example.domain.usecase.news
2 |
3 | import com.example.domain.HackerNewsRepository
4 | import com.example.domain.entities.DomainEntity
5 | import com.example.domain.extension.networkCommunityThread
6 | import com.example.domain.usecase.SingleUseCase
7 | import io.reactivex.Single
8 |
9 | open class HackerNewsUseCase(private val hackerNewsRepository: HackerNewsRepository) :
10 | SingleUseCase> {
11 |
12 | override fun execute(params: Param?): Single> {
13 | return hackerNewsRepository.getHackerNewsList(params?.page)
14 | .networkCommunityThread()
15 | }
16 | data class Param(val page: Int)
17 | }
18 |
19 | //class HackerNewsUseCase2(private val hackerNewsRepository: HackerNewsRepository) :
20 | // ObservableUseCase> {
21 | //
22 | // override fun execute(params: Param?): Observable> {
23 | // return hackerNewsRepository.getHackerNewsListOB(params?.page)
24 | // .subscribeOn(Schedulers.io())
25 | // .observeOn(AndroidSchedulers.mainThread())
26 | // }
27 | // data class Param(val page: Int)
28 | //}
--------------------------------------------------------------------------------
/domain/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | domain
3 |
4 |
--------------------------------------------------------------------------------
/domain/src/test/java/com/example/domain/HackerNewsUseCaseTest.kt:
--------------------------------------------------------------------------------
1 | package com.example.domain
2 |
3 | import com.example.domain.entities.DomainEntity
4 | import com.example.domain.usecase.news.HackerNewsUseCase
5 | import com.nhaarman.mockitokotlin2.mock
6 | import com.nhaarman.mockitokotlin2.verify
7 | import io.reactivex.Single
8 | import org.junit.Test
9 | import org.mockito.Mockito.`when`
10 |
11 | class HackerNewsUseCaseTest {
12 | @Test
13 | fun `hacker news, useCase execute`() {
14 | val mock = mock()
15 | val list = ArrayList()
16 | list.apply {
17 | add(DomainEntity.HackerNews(0, 0, "1", "1"))
18 | add(DomainEntity.HackerNews(0, 0, "1", "1"))
19 | add(DomainEntity.HackerNews(0, 0, "1", "1"))
20 | add(DomainEntity.HackerNews(0, 0, "1", "1"))
21 | }
22 | `when`(mock.execute(HackerNewsUseCase.Param(3))).thenReturn(Single.just(list))
23 |
24 | mock.execute(HackerNewsUseCase.Param(3))
25 | .test()
26 | .assertNoErrors()
27 | .assertComplete()
28 | .assertValue(list)
29 |
30 | verify(mock).execute(HackerNewsUseCase.Param(3))
31 | }
32 | }
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkw8263/AndroidCleanArchitectureDemo/132fe99d4f4e23d9537acc8fcabd4b2a30778983/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Feb 13 16:40:18 KST 2019
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
7 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/presentation/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/presentation/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | apply plugin: 'kotlin-android'
4 |
5 | apply plugin: 'kotlin-android-extensions'
6 |
7 | apply plugin: 'kotlin-kapt'
8 | android {
9 | compileSdkVersion 28
10 | defaultConfig {
11 | applicationId "com.example.mindevandroidcleanarchitecturedemo"
12 | minSdkVersion 23
13 | targetSdkVersion 28
14 | versionCode 1
15 | versionName "1.0"
16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
17 | }
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 |
25 | compileOptions {
26 | sourceCompatibility JavaVersion.VERSION_1_8
27 | targetCompatibility JavaVersion.VERSION_1_8
28 | }
29 |
30 | }
31 |
32 | dependencies {
33 | implementation fileTree(dir: 'libs', include: ['*.jar'])
34 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
35 | implementation 'androidx.appcompat:appcompat:1.1.0-alpha02'
36 | implementation 'androidx.core:core-ktx:1.1.0-alpha04'
37 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
38 | implementation "androidx.recyclerview:recyclerview:1.0.0"
39 | testImplementation 'junit:junit:4.12'
40 | testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.1.0"
41 | testImplementation 'androidx.arch.core:core-testing:2.0.0'
42 | androidTestImplementation 'androidx.test:runner:1.1.2-alpha01'
43 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.2-alpha01'
44 |
45 | // dagger2
46 | def dagger2_version = "2.21"
47 | implementation "com.google.dagger:dagger:$dagger2_version"
48 | implementation "com.google.dagger:dagger-android:$dagger2_version"
49 | implementation "com.google.dagger:dagger-android-support:$dagger2_version"
50 | kapt "com.google.dagger:dagger-android-processor:$dagger2_version"
51 | kapt "com.google.dagger:dagger-compiler:$dagger2_version"
52 |
53 | // retrofit2
54 | implementation 'com.squareup.retrofit2:retrofit:2.5.0'
55 | implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
56 | implementation 'com.squareup.okhttp3:logging-interceptor:3.13.1'
57 | implementation 'com.squareup.retrofit2:adapter-rxjava2:2.5.0'
58 |
59 | // gson
60 | implementation 'com.google.code.gson:gson:2.8.5'
61 |
62 | // ViewModelProvides
63 | implementation "androidx.lifecycle:lifecycle-extensions:2.0.0"
64 |
65 | implementation project(':data')
66 | implementation project(':domain')
67 | }
68 |
--------------------------------------------------------------------------------
/presentation/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 |
--------------------------------------------------------------------------------
/presentation/src/androidTest/java/com/example/mindevandroidcleanarchitecturedemo/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.example.mindevandroidcleanarchitecturedemo
2 |
3 | import androidx.test.InstrumentationRegistry
4 | import androidx.test.runner.AndroidJUnit4
5 | import junit.framework.Assert
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | /**
10 | * Instrumented test, which will execute on an Android device.
11 | *
12 | * See [testing documentation](http://d.android.com/tools/testing).
13 | */
14 | @RunWith(AndroidJUnit4::class)
15 | class ExampleInstrumentedTest {
16 | @Test
17 | fun useAppContext() {
18 | // Context of the app under test.
19 | val appContext = InstrumentationRegistry.getTargetContext()
20 | Assert.assertEquals("com.example.presenter.test", appContext.packageName)
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/presentation/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/presentation/src/main/java/com/example/mindevandroidcleanarchitecturedemo/MindevApplication.kt:
--------------------------------------------------------------------------------
1 | package com.example.mindevandroidcleanarchitecturedemo
2 |
3 | import android.app.Activity
4 | import android.app.Application
5 | import com.example.mindevandroidcleanarchitecturedemo.di.DaggerMindevComponent
6 | import dagger.android.AndroidInjector
7 | import dagger.android.DispatchingAndroidInjector
8 | import dagger.android.HasActivityInjector
9 | import javax.inject.Inject
10 |
11 | class MindevApplication : Application(), HasActivityInjector {
12 | @Inject
13 | lateinit var dispatchingAndroidInjector: DispatchingAndroidInjector
14 |
15 | override fun activityInjector(): AndroidInjector = dispatchingAndroidInjector
16 |
17 | override fun onCreate() {
18 | super.onCreate()
19 | DaggerMindevComponent.builder()
20 | .application(this)
21 | .build()
22 | .inject(this)
23 |
24 | }
25 | }
--------------------------------------------------------------------------------
/presentation/src/main/java/com/example/mindevandroidcleanarchitecturedemo/base/MindevActivity.kt:
--------------------------------------------------------------------------------
1 | package com.example.mindevandroidcleanarchitecturedemo.base
2 |
3 | import android.os.Bundle
4 | import androidx.lifecycle.ViewModel
5 | import dagger.android.support.DaggerAppCompatActivity
6 |
7 | abstract class MindevActivity : DaggerAppCompatActivity() {
8 | abstract val layoutResource: Int
9 | abstract val viewModel: T
10 |
11 | override fun onCreate(savedInstanceState: Bundle?) {
12 | super.onCreate(savedInstanceState)
13 | setContentView(layoutResource)
14 | }
15 | }
--------------------------------------------------------------------------------
/presentation/src/main/java/com/example/mindevandroidcleanarchitecturedemo/base/MindevViewModel.kt:
--------------------------------------------------------------------------------
1 | package com.example.mindevandroidcleanarchitecturedemo.base
2 |
3 | import androidx.lifecycle.ViewModel
4 | import io.reactivex.disposables.CompositeDisposable
5 |
6 | open class MindevViewModel : ViewModel() {
7 | protected val compositeDisposable = CompositeDisposable()
8 |
9 | override fun onCleared() {
10 | super.onCleared()
11 | compositeDisposable.clear()
12 | }
13 | }
--------------------------------------------------------------------------------
/presentation/src/main/java/com/example/mindevandroidcleanarchitecturedemo/di/MindevComponent.kt:
--------------------------------------------------------------------------------
1 | package com.example.mindevandroidcleanarchitecturedemo.di
2 |
3 | import com.example.mindevandroidcleanarchitecturedemo.MindevApplication
4 | import com.example.mindevandroidcleanarchitecturedemo.di.module.ActivityBindingModule
5 | import com.example.mindevandroidcleanarchitecturedemo.di.module.AppModule
6 | import dagger.BindsInstance
7 | import dagger.Component
8 | import dagger.android.support.AndroidSupportInjectionModule
9 | import javax.inject.Singleton
10 |
11 | @Singleton
12 | @Component(
13 | modules = [
14 | AndroidSupportInjectionModule::class,
15 | AppModule::class,
16 | ActivityBindingModule::class]
17 | )
18 | interface MindevComponent {
19 | @Component.Builder
20 | interface Builder {
21 | @BindsInstance
22 | fun application(app: MindevApplication): Builder
23 |
24 | fun build(): MindevComponent
25 | }
26 |
27 | fun inject(app: MindevApplication)
28 | }
29 |
--------------------------------------------------------------------------------
/presentation/src/main/java/com/example/mindevandroidcleanarchitecturedemo/di/module/ActivityBindingModule.kt:
--------------------------------------------------------------------------------
1 | package com.example.mindevandroidcleanarchitecturedemo.di.module
2 |
3 | import com.example.mindevandroidcleanarchitecturedemo.di.module.main.MainModule
4 | import com.example.mindevandroidcleanarchitecturedemo.di.qualifier.PerActivity
5 | import com.example.mindevandroidcleanarchitecturedemo.ui.MainActivity
6 | import dagger.Module
7 | import dagger.android.ContributesAndroidInjector
8 |
9 | @Module
10 | abstract class ActivityBindingModule {
11 | @PerActivity
12 | @ContributesAndroidInjector(modules = [MainModule::class])
13 | abstract fun bindingMainActivity(): MainActivity
14 | }
--------------------------------------------------------------------------------
/presentation/src/main/java/com/example/mindevandroidcleanarchitecturedemo/di/module/AppModule.kt:
--------------------------------------------------------------------------------
1 | package com.example.mindevandroidcleanarchitecturedemo.di.module
2 |
3 | import android.content.Context
4 | import com.example.mindevandroidcleanarchitecturedemo.MindevApplication
5 | import com.example.mindevandroidcleanarchitecturedemo.di.qualifier.ApplicationContext
6 | import dagger.Binds
7 | import dagger.Module
8 |
9 | @Module(includes = [NetWorkModule::class])
10 | abstract class AppModule {
11 |
12 | @ApplicationContext
13 | @Binds
14 | abstract fun provideApplicationContext(mindevApplication: MindevApplication): Context
15 | }
--------------------------------------------------------------------------------
/presentation/src/main/java/com/example/mindevandroidcleanarchitecturedemo/di/module/MainViewModelFactory.kt:
--------------------------------------------------------------------------------
1 | package com.example.mindevandroidcleanarchitecturedemo.di.module
2 |
3 | import androidx.lifecycle.ViewModel
4 | import androidx.lifecycle.ViewModelProvider
5 | import com.example.domain.usecase.news.HackerNewsUseCase
6 | import com.example.mindevandroidcleanarchitecturedemo.mapper.PresentationHackerNewsMapper
7 | import com.example.mindevandroidcleanarchitecturedemo.vm.MainViewModel
8 |
9 | @Suppress("UNCHECKED_CAST")
10 | open class MainViewModelFactory(
11 | private val hackerNewsUseCase: HackerNewsUseCase,
12 | private val presentationHackerNewsMapper: PresentationHackerNewsMapper
13 | ) : ViewModelProvider.Factory {
14 | override fun create(modelClass: Class): T {
15 | return MainViewModel(hackerNewsUseCase, presentationHackerNewsMapper) as T
16 | }
17 | }
--------------------------------------------------------------------------------
/presentation/src/main/java/com/example/mindevandroidcleanarchitecturedemo/di/module/NetWorkModule.kt:
--------------------------------------------------------------------------------
1 | package com.example.mindevandroidcleanarchitecturedemo.di.module
2 |
3 | import com.example.data.api.HackerNewsApi
4 | import com.example.mindevandroidcleanarchitecturedemo.BuildConfig
5 | import com.google.gson.Gson
6 | import com.google.gson.GsonBuilder
7 | import dagger.Module
8 | import dagger.Provides
9 | import okhttp3.OkHttpClient
10 | import okhttp3.logging.HttpLoggingInterceptor
11 | import retrofit2.Retrofit
12 | import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
13 | import retrofit2.converter.gson.GsonConverterFactory
14 | import java.util.concurrent.TimeUnit
15 |
16 | @Module
17 | class NetWorkModule {
18 |
19 | @Provides
20 | fun providesOkHttpClient(): OkHttpClient {
21 | return OkHttpClient.Builder().apply {
22 | addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.HEADERS))
23 | if (BuildConfig.DEBUG) addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
24 | connectTimeout(10, TimeUnit.SECONDS)
25 | readTimeout(10, TimeUnit.SECONDS)
26 | }.build()
27 | }
28 |
29 | @Provides
30 | fun provideGson(): Gson {
31 | return GsonBuilder()
32 | .setLenient()
33 | .create()
34 | }
35 |
36 | @Provides
37 | fun providesRetrofit(okHttpClient: OkHttpClient, gson: Gson): Retrofit {
38 | return Retrofit.Builder()
39 | .baseUrl("http://api.hackerwebapp.com/")
40 | .client(okHttpClient)
41 | .addConverterFactory(GsonConverterFactory.create(gson))
42 | .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
43 | .build()
44 |
45 | }
46 |
47 | @Provides
48 | fun providesHackerNewsApi(retrofit: Retrofit): HackerNewsApi {
49 | return retrofit.create(HackerNewsApi::class.java)
50 | }
51 | }
--------------------------------------------------------------------------------
/presentation/src/main/java/com/example/mindevandroidcleanarchitecturedemo/di/module/main/MainModule.kt:
--------------------------------------------------------------------------------
1 | package com.example.mindevandroidcleanarchitecturedemo.di.module.main
2 |
3 | import com.example.data.api.HackerNewsApi
4 | import com.example.data.mapper.DataHackerNewsMapper
5 | import com.example.data.repository.HackerNewsRepositoryImpl
6 | import com.example.data.source.news.local.HackerNewsLocalDataSource
7 | import com.example.data.source.news.remote.HackerNewsRemoteDataSource
8 | import com.example.domain.HackerNewsRepository
9 | import com.example.domain.usecase.news.HackerNewsUseCase
10 | import com.example.mindevandroidcleanarchitecturedemo.di.module.MainViewModelFactory
11 | import com.example.mindevandroidcleanarchitecturedemo.di.qualifier.PerActivity
12 | import com.example.mindevandroidcleanarchitecturedemo.mapper.PresentationHackerNewsMapper
13 | import dagger.Module
14 | import dagger.Provides
15 | import javax.inject.Named
16 |
17 | @Module
18 | class MainModule {
19 |
20 | @Provides
21 | @PerActivity
22 | @Named("HackerNewsRepositoryImpl")
23 | fun provideRepository(
24 | hackerNewsLocalDataSource: HackerNewsLocalDataSource,
25 | hackerNewsRemoteDataSource: HackerNewsRemoteDataSource,
26 | dataHackerNewsMapper: DataHackerNewsMapper
27 | ): HackerNewsRepository {
28 | return HackerNewsRepositoryImpl(hackerNewsLocalDataSource, hackerNewsRemoteDataSource, dataHackerNewsMapper)
29 | }
30 |
31 | @Provides
32 | @PerActivity
33 | fun provideHackerNewsRemoteDataSource(hackerNewsApi: HackerNewsApi): HackerNewsRemoteDataSource {
34 | return HackerNewsRemoteDataSource(hackerNewsApi)
35 | }
36 |
37 | @Provides
38 | @PerActivity
39 | fun provideHackerNewsUseCase(@Named("HackerNewsRepositoryImpl") hackerNewsRepository: HackerNewsRepository): HackerNewsUseCase {
40 | return HackerNewsUseCase(hackerNewsRepository)
41 | }
42 |
43 | @Provides
44 | @PerActivity
45 | fun provideMainViewModelFactory(
46 | hackerNewsUseCase: HackerNewsUseCase,
47 | presentationHackerNewsMapper: PresentationHackerNewsMapper
48 | ): MainViewModelFactory {
49 | return MainViewModelFactory(hackerNewsUseCase, presentationHackerNewsMapper)
50 | }
51 | }
--------------------------------------------------------------------------------
/presentation/src/main/java/com/example/mindevandroidcleanarchitecturedemo/di/qualifier/ApplicationContext.kt:
--------------------------------------------------------------------------------
1 | package com.example.mindevandroidcleanarchitecturedemo.di.qualifier
2 |
3 | import javax.inject.Qualifier
4 |
5 | @Qualifier
6 | @Retention(AnnotationRetention.RUNTIME)
7 | annotation class ApplicationContext
--------------------------------------------------------------------------------
/presentation/src/main/java/com/example/mindevandroidcleanarchitecturedemo/di/qualifier/PerActivity.kt:
--------------------------------------------------------------------------------
1 | package com.example.mindevandroidcleanarchitecturedemo.di.qualifier
2 |
3 | import javax.inject.Scope
4 |
5 | @Scope
6 | @Retention(AnnotationRetention.RUNTIME)
7 | annotation class PerActivity
--------------------------------------------------------------------------------
/presentation/src/main/java/com/example/mindevandroidcleanarchitecturedemo/di/qualifier/ViewModelKey.kt:
--------------------------------------------------------------------------------
1 | package com.example.mindevandroidcleanarchitecturedemo.di.qualifier
2 |
3 | import androidx.lifecycle.ViewModel
4 | import dagger.MapKey
5 | import kotlin.reflect.KClass
6 |
7 | @Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER)
8 | @Retention(AnnotationRetention.RUNTIME)
9 | @MapKey
10 | annotation class ViewModelKey(val value: KClass)
--------------------------------------------------------------------------------
/presentation/src/main/java/com/example/mindevandroidcleanarchitecturedemo/entities/PresentationEntity.kt:
--------------------------------------------------------------------------------
1 | package com.example.mindevandroidcleanarchitecturedemo.entities
2 |
3 | sealed class PresentationEntity {
4 | data class HackerNews(
5 | val comments_count: Int? = 0,
6 | val id: Int? = 0,
7 | val time_ago: String? = "",
8 | val title: String? = ""
9 | ) : PresentationEntity()
10 | }
--------------------------------------------------------------------------------
/presentation/src/main/java/com/example/mindevandroidcleanarchitecturedemo/extension/ArchitectureComponentsExtension.kt:
--------------------------------------------------------------------------------
1 | package com.example.mindevandroidcleanarchitecturedemo.extension
2 |
3 | import androidx.lifecycle.LifecycleOwner
4 | import androidx.lifecycle.LiveData
5 | import androidx.lifecycle.Observer
6 |
7 | fun LifecycleOwner.observe(liveData: LiveData, action: (t: T) -> Unit) {
8 | liveData.observe(this, Observer { it?.let { t -> action(t) } })
9 | }
10 |
--------------------------------------------------------------------------------
/presentation/src/main/java/com/example/mindevandroidcleanarchitecturedemo/extension/ContextExtension.kt:
--------------------------------------------------------------------------------
1 | package com.example.mindevandroidcleanarchitecturedemo.extension
2 |
3 | import android.content.Context
4 | import android.widget.Toast
5 |
6 | fun Context.showToast(message: String) {
7 | Toast.makeText(this, message, Toast.LENGTH_SHORT).show()
8 | }
--------------------------------------------------------------------------------
/presentation/src/main/java/com/example/mindevandroidcleanarchitecturedemo/mapper/PresentationHackerNewsMapper.kt:
--------------------------------------------------------------------------------
1 | package com.example.mindevandroidcleanarchitecturedemo.mapper
2 |
3 | import com.example.domain.entities.DomainEntity
4 | import com.example.mindevandroidcleanarchitecturedemo.entities.PresentationEntity
5 | import javax.inject.Inject
6 |
7 | class PresentationHackerNewsMapper @Inject constructor() :
8 | PresenterMapper {
9 | override fun mapToView(type: DomainEntity.HackerNews): PresentationEntity.HackerNews {
10 | return PresentationEntity.HackerNews(type.comments_count, type.id, type.time_ago, type.title)
11 | }
12 | }
--------------------------------------------------------------------------------
/presentation/src/main/java/com/example/mindevandroidcleanarchitecturedemo/mapper/PresenterMapper.kt:
--------------------------------------------------------------------------------
1 | package com.example.mindevandroidcleanarchitecturedemo.mapper
2 |
3 | interface PresenterMapper {
4 | fun mapToView(type: V): D
5 | }
--------------------------------------------------------------------------------
/presentation/src/main/java/com/example/mindevandroidcleanarchitecturedemo/ui/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.example.mindevandroidcleanarchitecturedemo.ui
2 |
3 | import android.os.Bundle
4 | import android.view.View
5 | import androidx.lifecycle.ViewModelProviders
6 | import androidx.recyclerview.widget.LinearLayoutManager
7 | import com.example.mindevandroidcleanarchitecturedemo.R
8 | import com.example.mindevandroidcleanarchitecturedemo.base.MindevActivity
9 | import com.example.mindevandroidcleanarchitecturedemo.di.module.MainViewModelFactory
10 | import com.example.mindevandroidcleanarchitecturedemo.entities.PresentationEntity
11 | import com.example.mindevandroidcleanarchitecturedemo.extension.observe
12 | import com.example.mindevandroidcleanarchitecturedemo.extension.showToast
13 | import com.example.mindevandroidcleanarchitecturedemo.vm.MainViewModel
14 | import kotlinx.android.synthetic.main.activity_main.*
15 | import javax.inject.Inject
16 |
17 | class MainActivity : MindevActivity() {
18 |
19 | @Inject
20 | lateinit var factory: MainViewModelFactory
21 | override val viewModel: MainViewModel
22 | get() = ViewModelProviders.of(this, factory)[MainViewModel::class.java]
23 |
24 | override val layoutResource: Int
25 | get() = R.layout.activity_main
26 |
27 | override fun onCreate(savedInstanceState: Bundle?) {
28 | super.onCreate(savedInstanceState)
29 | setObserver()
30 | viewModel.getList()
31 | }
32 |
33 | private fun setObserver() {
34 | observe(viewModel.liveResult, ::liveDataResult)
35 | }
36 |
37 | private fun liveDataResult(result: MainViewModel.Result) {
38 | when (result) {
39 | is MainViewModel.Result.NewsData -> setUpRecycler(result.data)
40 | is MainViewModel.Result.ShowError -> showToast(result.throwable.message.orEmpty())
41 | is MainViewModel.Result.ProgressBarVisibility -> progressBarVisibility(result.isLoading)
42 | }
43 | }
44 |
45 | private fun progressBarVisibility(isLoading: Boolean) {
46 | progress.visibility = if (isLoading) View.VISIBLE else View.GONE
47 | }
48 |
49 | private fun setUpRecycler(items: List) {
50 | recyclerList.apply {
51 | layoutManager = LinearLayoutManager(this@MainActivity)
52 | adapter = MainAdapter(items)
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/presentation/src/main/java/com/example/mindevandroidcleanarchitecturedemo/ui/MainAdapter.kt:
--------------------------------------------------------------------------------
1 | package com.example.mindevandroidcleanarchitecturedemo.ui
2 |
3 | import android.view.ViewGroup
4 | import androidx.recyclerview.widget.RecyclerView
5 | import com.example.mindevandroidcleanarchitecturedemo.entities.PresentationEntity
6 |
7 | class MainAdapter(private var items: List) : RecyclerView.Adapter() {
8 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MainViewHolder = MainViewHolder(parent)
9 | override fun getItemCount(): Int = items.size
10 | override fun onBindViewHolder(holder: MainViewHolder, position: Int) = holder.bind(items[position])
11 | }
--------------------------------------------------------------------------------
/presentation/src/main/java/com/example/mindevandroidcleanarchitecturedemo/ui/MainViewHolder.kt:
--------------------------------------------------------------------------------
1 | package com.example.mindevandroidcleanarchitecturedemo.ui
2 |
3 | import android.annotation.SuppressLint
4 | import android.view.LayoutInflater
5 | import android.view.ViewGroup
6 | import androidx.recyclerview.widget.RecyclerView
7 | import com.example.mindevandroidcleanarchitecturedemo.R
8 | import com.example.mindevandroidcleanarchitecturedemo.entities.PresentationEntity
9 | import kotlinx.android.synthetic.main.item_main.view.*
10 |
11 | class MainViewHolder(parent: ViewGroup) :
12 | RecyclerView.ViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_main, parent, false)) {
13 | @SuppressLint("SetTextI18n")
14 | fun bind(item: PresentationEntity.HackerNews) {
15 | with(itemView) {
16 | tvNumber.text = "# $layoutPosition"
17 | tvTimeAgo.text = item.time_ago
18 | tvContent.text = item.title
19 | tvCommentCount.text = "comment ${item.comments_count.toString()} 개"
20 | }
21 | }
22 | }
--------------------------------------------------------------------------------
/presentation/src/main/java/com/example/mindevandroidcleanarchitecturedemo/vm/MainViewModel.kt:
--------------------------------------------------------------------------------
1 | package com.example.mindevandroidcleanarchitecturedemo.vm
2 |
3 | import androidx.lifecycle.LiveData
4 | import androidx.lifecycle.MutableLiveData
5 | import com.example.domain.usecase.news.HackerNewsUseCase
6 | import com.example.mindevandroidcleanarchitecturedemo.base.MindevViewModel
7 | import com.example.mindevandroidcleanarchitecturedemo.entities.PresentationEntity
8 | import com.example.mindevandroidcleanarchitecturedemo.mapper.PresentationHackerNewsMapper
9 | import io.reactivex.rxkotlin.addTo
10 |
11 | class MainViewModel(
12 | private val hackerNewsUseCase: HackerNewsUseCase,
13 | private val presentationHackerNewsMapper: PresentationHackerNewsMapper
14 | ) : MindevViewModel() {
15 |
16 | sealed class Result {
17 | data class NewsData(val data: List) : Result()
18 | data class ShowError(val throwable: Throwable) : Result()
19 | data class ProgressBarVisibility(val isLoading: Boolean) : Result()
20 | }
21 |
22 | val mutableLiveResult = MutableLiveData()
23 | val liveResult: LiveData = mutableLiveResult
24 |
25 | fun getList() {
26 | mutableLiveResult.value = Result.ProgressBarVisibility(true)
27 | hackerNewsUseCase.execute(HackerNewsUseCase.Param(30))
28 | .subscribe { response, error ->
29 | mutableLiveResult.value = Result.ProgressBarVisibility(false)
30 | if (error != null) mutableLiveResult.value = Result.ShowError(error)
31 | else mutableLiveResult.value =
32 | Result.NewsData(response.map { presentationHackerNewsMapper.mapToView(it) })
33 | }.addTo(compositeDisposable)
34 | }
35 | }
--------------------------------------------------------------------------------
/presentation/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/presentation/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
10 |
12 |
14 |
16 |
18 |
20 |
22 |
24 |
26 |
28 |
30 |
32 |
34 |
36 |
38 |
40 |
42 |
44 |
46 |
48 |
50 |
52 |
54 |
56 |
58 |
60 |
62 |
64 |
66 |
68 |
70 |
72 |
74 |
75 |
--------------------------------------------------------------------------------
/presentation/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
15 |
19 |
20 |
--------------------------------------------------------------------------------
/presentation/src/main/res/layout/item_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
13 |
19 |
25 |
32 |
37 |
38 |
--------------------------------------------------------------------------------
/presentation/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/presentation/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/presentation/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkw8263/AndroidCleanArchitectureDemo/132fe99d4f4e23d9537acc8fcabd4b2a30778983/presentation/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/presentation/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkw8263/AndroidCleanArchitectureDemo/132fe99d4f4e23d9537acc8fcabd4b2a30778983/presentation/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/presentation/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkw8263/AndroidCleanArchitectureDemo/132fe99d4f4e23d9537acc8fcabd4b2a30778983/presentation/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/presentation/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkw8263/AndroidCleanArchitectureDemo/132fe99d4f4e23d9537acc8fcabd4b2a30778983/presentation/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/presentation/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkw8263/AndroidCleanArchitectureDemo/132fe99d4f4e23d9537acc8fcabd4b2a30778983/presentation/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/presentation/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkw8263/AndroidCleanArchitectureDemo/132fe99d4f4e23d9537acc8fcabd4b2a30778983/presentation/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/presentation/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkw8263/AndroidCleanArchitectureDemo/132fe99d4f4e23d9537acc8fcabd4b2a30778983/presentation/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/presentation/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkw8263/AndroidCleanArchitectureDemo/132fe99d4f4e23d9537acc8fcabd4b2a30778983/presentation/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/presentation/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkw8263/AndroidCleanArchitectureDemo/132fe99d4f4e23d9537acc8fcabd4b2a30778983/presentation/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/presentation/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkw8263/AndroidCleanArchitectureDemo/132fe99d4f4e23d9537acc8fcabd4b2a30778983/presentation/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/presentation/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #008577
4 | #00574B
5 | #D81B60
6 |
7 |
--------------------------------------------------------------------------------
/presentation/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | MIndevAndroidCleanArchitectureDemo
3 |
4 |
--------------------------------------------------------------------------------
/presentation/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/presentation/src/test/java/com/example/mindevandroidcleanarchitecturedemo/HackerNewsVMTest.kt:
--------------------------------------------------------------------------------
1 | package com.example.mindevandroidcleanarchitecturedemo
2 |
3 | import androidx.arch.core.executor.testing.InstantTaskExecutorRule
4 | import com.example.domain.entities.DomainEntity
5 | import com.example.domain.usecase.news.HackerNewsUseCase
6 | import com.example.mindevandroidcleanarchitecturedemo.entities.PresentationEntity
7 | import com.example.mindevandroidcleanarchitecturedemo.mapper.PresentationHackerNewsMapper
8 | import com.example.mindevandroidcleanarchitecturedemo.vm.MainViewModel
9 | import junit.framework.Assert.assertEquals
10 | import org.junit.Before
11 | import org.junit.Rule
12 | import org.junit.Test
13 | import org.mockito.Mock
14 | import org.mockito.MockitoAnnotations
15 |
16 | class HackerNewsVMTest {
17 | @get:Rule
18 | val rule = InstantTaskExecutorRule()
19 |
20 | private lateinit var mainViewModel: MainViewModel
21 | private lateinit var presentationHackerNewsMapper: PresentationHackerNewsMapper
22 |
23 | @Mock
24 | lateinit var hackerNewsUseCase: HackerNewsUseCase
25 |
26 | @Before
27 | fun setUp() {
28 | MockitoAnnotations.initMocks(this)
29 | presentationHackerNewsMapper = PresentationHackerNewsMapper()
30 | mainViewModel = MainViewModel(hackerNewsUseCase, presentationHackerNewsMapper)
31 | }
32 |
33 | @Test
34 | fun `live data, hacker news success`() {
35 | val value = listOf(PresentationEntity.HackerNews(0, 0, "1", "1"))
36 | mainViewModel.mutableLiveResult.postValue(MainViewModel.Result.NewsData(value))
37 | assertEquals(value, (mainViewModel.liveResult.value as MainViewModel.Result.NewsData).data)
38 | }
39 |
40 | @Test
41 | fun `live data, hacker news error`() {
42 | val value = Throwable(" error ")
43 | mainViewModel.mutableLiveResult.postValue(MainViewModel.Result.ShowError(value))
44 | assertEquals(value, (mainViewModel.liveResult.value as MainViewModel.Result.ShowError).throwable)
45 | }
46 |
47 | @Test
48 | fun `live data, hacker news loading`() {
49 | mainViewModel.mutableLiveResult.postValue(MainViewModel.Result.ProgressBarVisibility(true))
50 | mainViewModel.mutableLiveResult.postValue(MainViewModel.Result.ProgressBarVisibility(false))
51 | assertEquals(false, (mainViewModel.liveResult.value as MainViewModel.Result.ProgressBarVisibility).isLoading)
52 | }
53 |
54 | @Test
55 | fun `ui entity, DomainEntity change Presentation Entity`() {
56 | val presentationHackerNewsMapper = PresentationHackerNewsMapper()
57 | val domainEntity = DomainEntity.HackerNews(0, 0, "1", "1")
58 | println("domainEntity comments_count${domainEntity.comments_count}")
59 | println("domainEntity id${domainEntity.id}")
60 | println("domainEntity time_ago${domainEntity.time_ago}")
61 | println("domainEntity title${domainEntity.title}")
62 |
63 | val entity: PresentationEntity.HackerNews = presentationHackerNewsMapper.mapToView(domainEntity)
64 | println("changed ")
65 | println("PresentationEntity comments_count${entity.comments_count}")
66 | println("PresentationEntity id${entity.id}")
67 | println("PresentationEntity time_ago${entity.time_ago}")
68 | println("PresentationEntity title${entity.title}")
69 | }
70 | }
--------------------------------------------------------------------------------
/preview.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkw8263/AndroidCleanArchitectureDemo/132fe99d4f4e23d9537acc8fcabd4b2a30778983/preview.png
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':domain', ':data', ':presentation'
--------------------------------------------------------------------------------