Skip to content

Commit cacbc80

Browse files
committed
refactor: data and domain use caller co-routine scope (#262)
* chore: remove android.work:work-test module * refactor: simplify data source and factory
1 parent e2987b8 commit cacbc80

File tree

29 files changed

+129
-290
lines changed

29 files changed

+129
-290
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -219,3 +219,5 @@ fabric.properties
219219

220220
# Exclude client credentail files
221221
secrets.properties
222+
223+
.kotlin/sessions/

buildSrc/src/main/java/co/anitrend/arch/buildSrc/plugin/CorePlugin.kt

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ package co.anitrend.arch.buildSrc.plugin
33
import co.anitrend.arch.buildSrc.plugin.components.configureAndroid
44
import co.anitrend.arch.buildSrc.plugin.components.configureSpotless
55
import co.anitrend.arch.buildSrc.plugin.components.configureDependencies
6-
import co.anitrend.arch.buildSrc.plugin.components.configureOptions
76
import co.anitrend.arch.buildSrc.plugin.components.configurePlugins
7+
import co.anitrend.arch.buildSrc.plugin.components.configureSources
8+
import co.anitrend.arch.buildSrc.plugin.components.configureDokka
9+
import co.anitrend.arch.buildSrc.plugin.extensions.containsBasePlugin
810
import co.anitrend.arch.buildSrc.plugin.extensions.isKotlinLibraryGroup
911
import org.gradle.api.Plugin
1012
import org.gradle.api.Project
@@ -30,7 +32,8 @@ open class CorePlugin : Plugin<Project> {
3032
if (!project.isKotlinLibraryGroup()) {
3133
project.configureAndroid()
3234
}
33-
project.configureOptions()
35+
project.configureDokka()
36+
project.configureSources()
3437
project.configureDependencies()
3538
project.configureSpotless()
3639
project.availableExtensions()

buildSrc/src/main/java/co/anitrend/arch/buildSrc/plugin/components/AndroidConfiguration.kt

-16
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
package co.anitrend.arch.buildSrc.plugin.components
22

3-
import co.anitrend.arch.buildSrc.plugin.extensions.spotlessExtension
43
import co.anitrend.arch.buildSrc.plugin.extensions.baseExtension
54
import co.anitrend.arch.buildSrc.plugin.extensions.libraryExtension
65
import co.anitrend.arch.buildSrc.plugin.extensions.isDomainModule
76
import co.anitrend.arch.buildSrc.plugin.extensions.isThemeModule
87
import co.anitrend.arch.buildSrc.plugin.extensions.kotlinAndroidProjectExtension
98
import co.anitrend.arch.buildSrc.plugin.extensions.props
10-
import co.anitrend.arch.buildSrc.plugin.extensions.libs
119
import org.gradle.api.JavaVersion
1210
import org.gradle.api.Project
1311
import org.gradle.api.tasks.testing.Test
@@ -22,20 +20,6 @@ private fun Project.configureLint() = libraryExtension().run {
2220
}
2321
}
2422

25-
internal fun Project.configureSpotless(): Unit = spotlessExtension().run {
26-
kotlin {
27-
target("**/*.kt")
28-
targetExclude(
29-
"${layout.buildDirectory.get()}/**/*.kt",
30-
"**/androidTest/**/*.kt",
31-
"**/test/**/*.kt",
32-
"bin/**/*.kt"
33-
)
34-
ktlint(libs.pintrest.ktlint.get().version)
35-
licenseHeaderFile(rootProject.file("spotless/copyright.kt"))
36-
}
37-
}
38-
3923
internal fun Project.configureAndroid(): Unit = baseExtension().run {
4024
compileSdkVersion(34)
4125
defaultConfig {

buildSrc/src/main/java/co/anitrend/arch/buildSrc/plugin/components/AndroidOptions.kt buildSrc/src/main/java/co/anitrend/arch/buildSrc/plugin/components/ProjectDokka.kt

+2-76
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
package co.anitrend.arch.buildSrc.plugin.components
22

33
import org.gradle.api.Project
4-
import org.gradle.api.tasks.bundling.Jar
5-
import org.gradle.kotlin.dsl.get
64
import org.jetbrains.dokka.gradle.DokkaTask
75
import co.anitrend.arch.buildSrc.module.Modules
86
import co.anitrend.arch.buildSrc.plugin.extensions.*
9-
import org.gradle.api.publish.maven.MavenPublication
10-
import org.gradle.kotlin.dsl.getValue
117
import org.gradle.kotlin.dsl.invoke
128
import org.gradle.kotlin.dsl.named
13-
import org.jetbrains.kotlin.gradle.dsl.kotlinExtension
149
import java.net.URL
1510

1611
private fun Project.dependenciesOfProject(): List<Modules.Module> {
@@ -59,49 +54,11 @@ private fun Project.dependenciesOfProject(): List<Modules.Module> {
5954
}
6055
}
6156

62-
private fun Project.createMavenPublicationUsing(sources: Jar) {
63-
publishingExtension().publications {
64-
val component = components.findByName("android")
65-
66-
val projectName = this@createMavenPublicationUsing.name
67-
68-
logger.lifecycle("Configuring maven publication options for ${path}:maven with component -> ${component?.name}")
69-
create("maven", MavenPublication::class.java) {
70-
groupId = "co.anitrend.arch"
71-
artifactId = projectName
72-
version = props[PropertyTypes.VERSION]
73-
74-
artifact(sources)
75-
artifact("${layout.buildDirectory.get()}/outputs/aar/${projectName}-release.aar")
76-
from(component)
77-
78-
pom {
79-
name.set("support-arch")
80-
description.set("A multi-module template library that attempts to make clean arch apps easier to build")
81-
url.set("https://github.com/anitrend/support-arch")
82-
licenses {
83-
license {
84-
name.set("Apache License, Version 2.0")
85-
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
86-
}
87-
}
88-
developers {
89-
developer {
90-
id.set("wax911")
91-
name.set("Maxwell Mapako")
92-
organizationUrl.set("https://github.com/anitrend")
93-
}
94-
}
95-
}
96-
}
97-
}
98-
}
99-
100-
private fun Project.createDokkaTaskProvider() = tasks.named<DokkaTask>("dokkaHtml") {
57+
internal fun Project.configureDokka() = tasks.named<DokkaTask>("dokkaHtml") {
10158
outputDirectory.set(layout.buildDirectory.dir("docs/dokka"))
10259

10360
// Set module name displayed in the final output
104-
moduleName.set(this@createDokkaTaskProvider.name)
61+
moduleName.set(project.name)
10562

10663
// Use default or set to custom path to cache directory
10764
// to enable package-list caching
@@ -207,35 +164,4 @@ private fun Project.createDokkaTaskProvider() = tasks.named<DokkaTask>("dokkaHtm
207164
}
208165
}
209166
}
210-
}
211-
212-
internal fun Project.configureOptions() {
213-
if (containsBasePlugin()) {
214-
logger.lifecycle("Applying extension options for ${project.path}")
215-
216-
val mainSourceSets = when {
217-
!isKotlinLibraryGroup() -> baseExtension().sourceSets["main"].java.srcDirs
218-
else -> kotlinJvmProjectExtension().sourceSets["main"].kotlin.srcDirs()
219-
}
220-
221-
logger.lifecycle("Applying additional tasks options for dokka and javadoc on ${project.path}")
222-
223-
createDokkaTaskProvider()
224-
225-
val sourcesJar by tasks.register("sourcesJar", Jar::class.java) {
226-
archiveClassifier.set("sources")
227-
from(mainSourceSets)
228-
}
229-
230-
val classesJar by tasks.register("classesJar", Jar::class.java) {
231-
from("${project.layout.buildDirectory.get()}/intermediates/classes/release")
232-
}
233-
234-
artifacts {
235-
add("archives", classesJar)
236-
add("archives", sourcesJar)
237-
}
238-
239-
createMavenPublicationUsing(sourcesJar)
240-
}
241167
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package co.anitrend.arch.buildSrc.plugin.components
2+
3+
import co.anitrend.arch.buildSrc.plugin.extensions.props
4+
import co.anitrend.arch.buildSrc.plugin.extensions.publishingExtension
5+
import org.gradle.api.Project
6+
import org.gradle.api.publish.maven.MavenPublication
7+
8+
9+
internal fun Project.configureMaven() {
10+
publishingExtension().publications {
11+
val component = components.findByName("java")
12+
13+
logger.lifecycle("Configuring maven publication options for ${path}:maven with component -> ${component?.name}")
14+
create("maven", MavenPublication::class.java) {
15+
groupId = "co.anitrend.arch"
16+
artifactId = project.name
17+
version = props[PropertyTypes.VERSION]
18+
19+
from(component)
20+
21+
pom {
22+
name.set("support-arch")
23+
description.set("A multi-module template library that attempts to make clean arch apps easier to build")
24+
url.set("https://github.com/anitrend/support-arch")
25+
licenses {
26+
license {
27+
name.set("Apache License, Version 2.0")
28+
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
29+
}
30+
}
31+
developers {
32+
developer {
33+
id.set("wax911")
34+
name.set("Maxwell Mapako")
35+
organizationUrl.set("https://github.com/anitrend")
36+
}
37+
}
38+
}
39+
}
40+
}
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package co.anitrend.arch.buildSrc.plugin.components
2+
3+
import co.anitrend.arch.buildSrc.plugin.extensions.baseExtension
4+
import co.anitrend.arch.buildSrc.plugin.extensions.isKotlinLibraryGroup
5+
import co.anitrend.arch.buildSrc.plugin.extensions.kotlinJvmProjectExtension
6+
import org.gradle.api.Project
7+
import org.gradle.api.tasks.bundling.Jar
8+
import org.gradle.kotlin.dsl.get
9+
import org.gradle.kotlin.dsl.getValue
10+
import org.gradle.kotlin.dsl.provideDelegate
11+
12+
internal fun Project.configureSources() {
13+
val mainSourceSets = when {
14+
!isKotlinLibraryGroup() -> baseExtension().sourceSets["main"].java.srcDirs
15+
else -> kotlinJvmProjectExtension().sourceSets["main"].kotlin.srcDirs()
16+
}
17+
18+
val sourcesJar by tasks.register("sourcesJar", Jar::class.java) {
19+
archiveClassifier.set("sources")
20+
from(mainSourceSets)
21+
}
22+
23+
val classesJar by tasks.register("classesJar", Jar::class.java) {
24+
from("${project.layout.buildDirectory.get()}/intermediates/classes/release")
25+
}
26+
27+
artifacts {
28+
add("archives", classesJar)
29+
add("archives", sourcesJar)
30+
}
31+
32+
afterEvaluate {
33+
configureMaven()
34+
}
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package co.anitrend.arch.buildSrc.plugin.components
2+
3+
import co.anitrend.arch.buildSrc.plugin.extensions.libs
4+
import co.anitrend.arch.buildSrc.plugin.extensions.spotlessExtension
5+
import org.gradle.api.Project
6+
7+
8+
internal fun Project.configureSpotless(): Unit = spotlessExtension().run {
9+
kotlin {
10+
target("**/*.kt")
11+
targetExclude(
12+
"${layout.buildDirectory.get()}/**/*.kt",
13+
"**/androidTest/**/*.kt",
14+
"**/test/**/*.kt",
15+
"bin/**/*.kt"
16+
)
17+
ktlint(libs.pintrest.ktlint.get().version)
18+
licenseHeaderFile(rootProject.file("spotless/copyright.kt"))
19+
}
20+
}

core/src/main/kotlin/co/anitrend/arch/core/model/ISupportViewModelState.kt

-11
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import co.anitrend.arch.domain.entities.LoadState
2424
*
2525
* @property model observable model from a use case output
2626
* @property loadState observable network state from underlying sources
27-
* @property refreshState observable network refresh state from underlying sources
2827
*
2928
* @param R type of your [model]
3029
*
@@ -33,7 +32,6 @@ import co.anitrend.arch.domain.entities.LoadState
3332
interface ISupportViewModelState<R> {
3433
val model: LiveData<R>
3534
val loadState: LiveData<LoadState>
36-
val refreshState: LiveData<LoadState>
3735

3836
/**
3937
* Triggers use case to perform a retry operation
@@ -44,13 +42,4 @@ interface ISupportViewModelState<R> {
4442
* Triggers use case to perform refresh operation
4543
*/
4644
suspend fun refresh()
47-
48-
/**
49-
* Called upon [androidx.lifecycle.ViewModel.onCleared] and should optionally
50-
* call cancellation of any ongoing jobs.
51-
*
52-
* If your use case source is of type [co.anitrend.arch.domain.common.IUseCase]
53-
* then you could optionally call [co.anitrend.arch.domain.common.IUseCase.onCleared] here
54-
*/
55-
fun onCleared()
5645
}

data/src/main/kotlin/co/anitrend/arch/data/common/ISupportResponse.kt

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@ import co.anitrend.arch.request.callback.RequestCallback
2323
*
2424
* @since v1.1.0
2525
*/
26-
interface ISupportResponse<in RESOURCE, out RESPONSE> {
26+
interface ISupportResponse<in I, out O> {
2727
/**
28-
* Response handler for coroutine contexts which need to observe [NetworkState]
28+
* Response handler for coroutine contexts which need to observe [LoadState]
2929
*
3030
* @param resource awaiting execution
3131
* @param requestCallback for the deferred result
3232
*
3333
* @return resource fetched if present
3434
*/
3535
suspend operator fun invoke(
36-
resource: RESOURCE,
36+
resource: I,
3737
requestCallback: RequestCallback,
38-
): RESPONSE?
38+
): O?
3939
}

data/src/main/kotlin/co/anitrend/arch/data/repository/SupportRepository.kt

-39
This file was deleted.

data/src/main/kotlin/co/anitrend/arch/data/repository/contract/ISupportRepository.kt

-30
This file was deleted.

0 commit comments

Comments
 (0)