Skip to content

Commit 088697e

Browse files
authored
refactor all (#174)
* refactor(base) * refactor(base) * refactor(main): MainVM * refactor(main): MainVM * refactor(base) * refactor(base): sealed interface * refactor(add): viewmodel * refactor(add): fix viewmodel * refactor(add): vm * refactor(add): fix tests * refactor(main): MainVM * refactor(main): MainVM * refactor(add): vm * refactor(search): vm * refactor(search): fix tests * done * done * rename * validated nes * fix tests * fix tests * fix tests * rename
1 parent 4212b1e commit 088697e

File tree

44 files changed

+919
-511
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+919
-511
lines changed

app/src/test/java/com/hoc/flowmvi/CheckModulesTest.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ package com.hoc.flowmvi
33
import androidx.lifecycle.SavedStateHandle
44
import com.hoc.flowmvi.test_utils.TestCoroutineDispatcherRule
55
import io.mockk.every
6+
import io.mockk.just
67
import io.mockk.mockk
8+
import io.mockk.runs
79
import kotlin.test.Test
810
import kotlin.time.ExperimentalTime
911
import kotlinx.coroutines.ExperimentalCoroutinesApi
@@ -26,6 +28,7 @@ class CheckModulesTest : AutoCloseKoinTest() {
2628
SavedStateHandle::class -> {
2729
mockk<SavedStateHandle> {
2830
every { get<Any?>(any()) } returns null
31+
every { setSavedStateProvider(any(), any()) } just runs
2932
}
3033
}
3134
else -> error("Unknown class: $clazz")

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ allprojects {
157157
kotlinOptions {
158158
val version = JavaVersion.VERSION_11.toString()
159159
jvmTarget = version
160+
languageVersion = "1.8"
160161
}
161162
}
162163

buildSrc/gradle.properties

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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=-Xmx2048m
10+
11+
# When configured, Gradle will run in incubating parallel mode.
12+
# This option should only be used with decoupled projects. More details, visit
13+
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
14+
org.gradle.parallel=true
15+
16+
# Enable the Build Cache
17+
org.gradle.caching=true
18+
19+
# AndroidX package structure to make it clearer which packages are bundled with the
20+
# Android operating system, and which are packaged with your app's APK
21+
# https://developer.android.com/topic/libraries/support-library/androidx-rn
22+
android.useAndroidX=true
23+
24+
# Automatically convert third-party libraries to use AndroidX
25+
android.enableJetifier=false
26+
27+
# Kotlin code style for this project: "official" or "obsolete":
28+
kotlin.code.style=official
29+
30+
# Enable Kotlin incremental compilation
31+
kotlin.incremental=true
60.1 KB
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-all.zip
4+
networkTimeout=10000
5+
zipStoreBase=GRADLE_USER_HOME
6+
zipStorePath=wrapper/dists

buildSrc/src/main/kotlin/deps.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ inline val PDsS.kotlinAndroid: PDS get() = id("kotlin-android")
105105
inline val PDsS.kotlin: PDS get() = id("kotlin")
106106
inline val PDsS.kotlinKapt: PDS get() = id("kotlin-kapt")
107107
inline val PDsS.kotlinParcelize: PDS get() = id("kotlin-parcelize")
108+
inline val PDsS.nocopyPlugin: PDS get() = id("dev.ahmedmourad.nocopy.nocopy-gradle-plugin")
108109

109110
inline val DependencyHandler.domain get() = project(":domain")
110111
inline val DependencyHandler.core get() = project(":core")
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.hoc.flowmvi.core_ui
2+
3+
import kotlin.coroutines.ContinuationInterceptor
4+
import kotlinx.coroutines.Dispatchers
5+
import kotlinx.coroutines.currentCoroutineContext
6+
import timber.log.Timber
7+
8+
suspend fun debugCheckImmediateMainDispatcher() {
9+
if (BuildConfig.DEBUG) {
10+
val interceptor = currentCoroutineContext()[ContinuationInterceptor]
11+
Timber.d("debugCheckImmediateMainDispatcher: interceptor=$interceptor")
12+
13+
check(interceptor === Dispatchers.Main.immediate) {
14+
"Expected ContinuationInterceptor to be Dispatchers.Main.immediate but was $interceptor"
15+
}
16+
}
17+
}

core/build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ java {
88
}
99

1010
dependencies {
11-
implementation(deps.coroutines.core)
11+
api(deps.coroutines.core)
12+
api(deps.arrow.core)
1213
addUnitTest()
1314
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package com.hoc.flowmvi.core
2+
3+
/**
4+
* `NonEmptySet` is a data type used to model sets that guarantee to have at least one value.
5+
*/
6+
class NonEmptySet<out T>
7+
@Throws(IllegalArgumentException::class)
8+
private constructor(val set: Set<T>) : AbstractSet<T>() {
9+
init {
10+
require(set.isNotEmpty()) { "Set must not be empty" }
11+
require(set !is NonEmptySet<T>) { "Set must not be NonEmptySet" }
12+
}
13+
14+
override val size: Int get() = set.size
15+
override fun iterator(): Iterator<T> = set.iterator()
16+
override fun isEmpty(): Boolean = false
17+
18+
operator fun plus(l: NonEmptySet<@UnsafeVariance T>): NonEmptySet<T> =
19+
NonEmptySet(set + l.set)
20+
21+
@Suppress("RedundantOverride")
22+
override fun equals(other: Any?): Boolean = super.equals(other)
23+
24+
@Suppress("RedundantOverride")
25+
override fun hashCode(): Int = super.hashCode()
26+
27+
override fun toString(): String =
28+
"NonEmptySet(${set.joinToString()})"
29+
30+
companion object {
31+
/**
32+
* Creates a [NonEmptySet] from the given [Collection].
33+
* @return null if [this] is empty.
34+
*/
35+
@JvmStatic
36+
fun <T> Collection<T>.toNonEmptySetOrNull(): NonEmptySet<T>? =
37+
if (isEmpty()) null else NonEmptySet(toSet())
38+
39+
/**
40+
* Creates a [NonEmptySet] from the given [Set].
41+
* @return null if [this] is empty.
42+
*/
43+
@JvmStatic
44+
fun <T> Set<T>.toNonEmptySetOrNull(): NonEmptySet<T>? = (this as? NonEmptySet<T>)
45+
?: if (isEmpty()) null else NonEmptySet(this)
46+
47+
/**
48+
* Creates a [NonEmptySet] from the given values.
49+
*/
50+
@JvmStatic
51+
fun <T> of(element: T, vararg elements: T): NonEmptySet<T> = NonEmptySet(
52+
buildSet(capacity = 1 + elements.size) {
53+
add(element)
54+
addAll(elements)
55+
}
56+
)
57+
58+
/**
59+
* Creates a [NonEmptySet] that contains only the specified [element].
60+
*/
61+
@JvmStatic
62+
fun <T> of(element: T): NonEmptySet<T> = NonEmptySet(setOf(element))
63+
}
64+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.hoc.flowmvi.core
2+
3+
import arrow.core.Validated
4+
import arrow.typeclasses.Semigroup
5+
6+
typealias ValidatedNes<E, A> = Validated<NonEmptySet<E>, A>
7+
8+
@Suppress("NOTHING_TO_INLINE")
9+
inline fun <A> A.validNes(): ValidatedNes<Nothing, A> =
10+
Validated.Valid(this)
11+
12+
@Suppress("NOTHING_TO_INLINE")
13+
inline fun <E> E.invalidNes(): ValidatedNes<E, Nothing> =
14+
Validated.Invalid(NonEmptySet.of(this))
15+
16+
object NonEmptySetSemigroup : Semigroup<NonEmptySet<Any?>> {
17+
override fun NonEmptySet<Any?>.combine(b: NonEmptySet<Any?>): NonEmptySet<Any?> = this + b
18+
}
19+
20+
@Suppress("UNCHECKED_CAST")
21+
fun <T> Semigroup.Companion.nonEmptySet(): Semigroup<NonEmptySet<T>> =
22+
NonEmptySetSemigroup as Semigroup<NonEmptySet<T>>

0 commit comments

Comments
 (0)