Skip to content

Commit

Permalink
ktlint 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
hoc081098 committed Sep 30, 2023
1 parent 52a27f5 commit cb8a65f
Show file tree
Hide file tree
Showing 84 changed files with 2,575 additions and 2,190 deletions.
27 changes: 16 additions & 11 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
root = true

root=true
[*]
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

indent_size=2
end_of_line=lf
charset=utf-8
trim_trailing_whitespace=true
insert_final_newline=true
[*.{kt,kts}]
ij_kotlin_imports_layout = *

ij_kotlin_imports_layout=*
ij_continuation_indent_size=4
ktlint_standard_filename=disabled
ktlint_standard_package-name=disabled
ktlint_standard_property-naming=disabled
ktlint_standard_function-naming=disabled
ktlint_standard_no-empty-file=disabled
filename=disabled
ktlint_experimental=enabled
[*.xml]
indent_size = 4
indent_size=4
4 changes: 1 addition & 3 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
[![Qodana](https://github.com/Kotlin-Android-Open-Source/MVI-Coroutines-Flow/actions/workflows/qodana.yml/badge.svg)](https://github.com/Kotlin-Android-Open-Source/MVI-Coroutines-Flow/actions/workflows/qodana.yml)
[![Validate Gradle Wrapper](https://github.com/Kotlin-Android-Open-Source/MVI-Coroutines-Flow/actions/workflows/gradle-wrapper-validation.yml/badge.svg)](https://github.com/Kotlin-Android-Open-Source/MVI-Coroutines-Flow/actions/workflows/gradle-wrapper-validation.yml)
[![API](https://img.shields.io/badge/API-21%2B-brightgreen.svg?style=flat)](https://android-arsenal.com/api?level=21)
[![Kotlin](https://img.shields.io/badge/kotlin-1.8.10-blue.svg?logo=kotlin)](http://kotlinlang.org)
[![Kotlin](https://img.shields.io/badge/kotlin-1.9.0-blue.svg?logo=kotlin)](http://kotlinlang.org)
[![Hits](https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2FKotlin-Android-Open-Source%2FMVI-Coroutines-Flow&count_bg=%2379C83D&title_bg=%23555555&icon=&icon_color=%23E7E7E7&title=hits&edge_flat=false)](https://hits.seeyoufarm.com)
[![License: MIT](https://img.shields.io/badge/License-MIT-purple.svg)](https://opensource.org/licenses/MIT)
[![Gitter](https://badges.gitter.im/Kotlin-Android-Open-Source/community.svg)](https://gitter.im/Kotlin-Android-Open-Source/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
Expand Down
18 changes: 12 additions & 6 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ android {
isShrinkResources = true
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
"proguard-rules.pro",
)
}

Expand Down Expand Up @@ -56,9 +56,9 @@ dependencies {
fileTree(
mapOf(
"dir" to "libs",
"include" to listOf("*.jar")
)
)
"include" to listOf("*.jar"),
),
),
)

implementation(domain)
Expand All @@ -81,7 +81,13 @@ dependencies {
testImplementation(deps.test.junit)
androidTestImplementation(deps.test.androidx.junit)
androidTestImplementation(deps.test.androidx.core)
androidTestImplementation(deps.test.androidx.espresso.core)
androidTestImplementation(
deps
.test
.androidx
.espresso
.core,
)

addUnitTest()
testImplementation(testUtils)
Expand All @@ -106,7 +112,7 @@ koverReport {
excludes {
classes(
"*.databinding.*",
"*.BuildConfig"
"*.BuildConfig",
)
}
}
Expand Down
17 changes: 9 additions & 8 deletions app/src/main/java/com/hoc/flowmvi/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ import org.koin.core.logger.Level
@ExperimentalStdlibApi
@ExperimentalTime
@JvmField
val allModules = listOf(
coreModule,
dataModule,
domainModule,
mainModule,
addModule,
searchModule,
)
val allModules =
listOf(
coreModule,
dataModule,
domainModule,
mainModule,
addModule,
searchModule,
)

@Suppress("unused")
@ExperimentalStdlibApi
Expand Down
9 changes: 5 additions & 4 deletions app/src/main/java/com/hoc/flowmvi/core/CoreModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import org.koin.core.module.dsl.singleOf
import org.koin.dsl.module

@JvmField
val coreModule = module {
singleOf(::DefaultAppCoroutineDispatchers) { bind<AppCoroutineDispatchers>() }
val coreModule =
module {
singleOf(::DefaultAppCoroutineDispatchers) { bind<AppCoroutineDispatchers>() }

singleOf(::NavigatorImpl) { bind<Navigator>() }
}
singleOf(::NavigatorImpl) { bind<Navigator>() }
}
3 changes: 1 addition & 2 deletions app/src/main/java/com/hoc/flowmvi/core/NavigatorImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ class NavigatorImpl(
private val add: IntentProviders.Add,
private val search: IntentProviders.Search,
) : Navigator {
override fun Context.navigateToAdd() =
startActivity(add.makeIntent(this))
override fun Context.navigateToAdd() = startActivity(add.makeIntent(this))

override fun Context.navigateToSearch() {
startActivity(search.makeIntent(this))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@ class ViewBindingInitializer : Initializer<Unit> {
Timber.d("ViewBindingInitializer...")
}

override fun dependencies(): List<Class<out Initializer<*>>> =
listOf(TimberInitializer::class.java)
override fun dependencies(): List<Class<out Initializer<*>>> = listOf(TimberInitializer::class.java)
}
17 changes: 9 additions & 8 deletions app/src/test/java/com/hoc/flowmvi/CheckModulesTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,18 @@ import org.koin.test.mock.MockProviderRule
@ExperimentalTime
class CheckModulesTest : AutoCloseKoinTest() {
@get:Rule
val mockProvider = MockProviderRule.create { clazz ->
when (clazz) {
SavedStateHandle::class -> {
mockk<SavedStateHandle> {
every { get<Any?>(any()) } returns null
every { setSavedStateProvider(any(), any()) } just runs
val mockProvider =
MockProviderRule.create { clazz ->
when (clazz) {
SavedStateHandle::class -> {
mockk<SavedStateHandle> {
every { get<Any?>(any()) } returns null
every { setSavedStateProvider(any(), any()) } just runs
}
}
else -> error("Unknown class: $clazz")
}
else -> error("Unknown class: $clazz")
}
}

@get:Rule
val coroutineRule = TestCoroutineDispatcherRule()
Expand Down
84 changes: 38 additions & 46 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask
import java.util.EnumSet
import java.util.Locale
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
Expand All @@ -9,6 +8,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
id("org.jetbrains.kotlinx.kover") version "0.7.3" apply false
id("com.diffplug.spotless") version "6.22.0" apply false
}

buildscript {
Expand All @@ -28,12 +28,12 @@ buildscript {
}

subprojects {
apply(plugin = "com.diffplug.spotless")
apply(plugin = "com.github.ben-manes.versions")

fun isNonStable(version: String): Boolean {
val stableKeyword = listOf("RELEASE", "FINAL", "GA")
.any { version.uppercase().contains(it) }
val stableKeyword =
listOf("RELEASE", "FINAL", "GA")
.any { version.uppercase().contains(it) }
val regex = "^[0-9,.v-]+(-r)?$".toRegex()
val isStable = stableKeyword || regex.matches(version)
return !isStable
Expand All @@ -51,6 +51,40 @@ subprojects {
}
}

afterEvaluate {
tasks.withType<Test> {
maxParallelForks =
(Runtime.getRuntime().availableProcessors() / 2).coerceAtLeast(1).also {
println("Setting maxParallelForks to $it")
}
testLogging {
showExceptions = true
showCauses = true
showStackTraces = true
showStandardStreams = true
events =
EnumSet.of(
TestLogEvent.PASSED,
TestLogEvent.FAILED,
TestLogEvent.SKIPPED,
TestLogEvent.STANDARD_OUT,
TestLogEvent.STANDARD_ERROR,
)
exceptionFormat = TestExceptionFormat.FULL
}
}
}
}

allprojects {
tasks.withType<KotlinCompile> {
kotlinOptions {
val version = JavaVersion.VERSION_11.toString()
jvmTarget = version
}
}

apply<com.diffplug.gradle.spotless.SpotlessPlugin>()
configure<com.diffplug.gradle.spotless.SpotlessExtension> {
kotlin {
target("**/*.kt")
Expand Down Expand Up @@ -80,46 +114,4 @@ subprojects {
endWithNewline()
}
}

afterEvaluate {
tasks.withType<Test> {
maxParallelForks = (Runtime.getRuntime().availableProcessors() / 2).coerceAtLeast(1).also {
println("Setting maxParallelForks to $it")
}
testLogging {
showExceptions = true
showCauses = true
showStackTraces = true
showStandardStreams = true
events = EnumSet.of(
TestLogEvent.PASSED,
TestLogEvent.FAILED,
TestLogEvent.SKIPPED,
TestLogEvent.STANDARD_OUT,
TestLogEvent.STANDARD_ERROR
)
exceptionFormat = TestExceptionFormat.FULL
}
}
}
}

allprojects {
tasks.withType<KotlinCompile> {
kotlinOptions {
val version = JavaVersion.VERSION_11.toString()
jvmTarget = version
}
}

repositories {
google()
mavenCentral()
maven(url = "https://jitpack.io")
maven(url = "https://s01.oss.sonatype.org/content/repositories/snapshots/")
}
}

tasks.register("clean", Delete::class) {
delete(rootProject.buildDir)
}
8 changes: 4 additions & 4 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
repositories {
mavenCentral()
mavenCentral()
}

plugins {
`kotlin-dsl`
`kotlin-dsl-precompiled-script-plugins`
}
`kotlin-dsl`
`kotlin-dsl-precompiled-script-plugins`
}
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/deps.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import org.gradle.kotlin.dsl.project
import org.gradle.plugin.use.PluginDependenciesSpec
import org.gradle.plugin.use.PluginDependencySpec

const val ktlintVersion = "0.46.1"
const val ktlintVersion = "1.0.0"
const val kotlinVersion = "1.9.10"

object appConfig {
Expand Down
2 changes: 1 addition & 1 deletion core-ui/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ android {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
"proguard-rules.pro",
)
}
}
Expand Down
22 changes: 12 additions & 10 deletions core-ui/src/main/java/com/hoc/flowmvi/core_ui/CollectIn.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ inline fun <T> Flow<T>.collectIn(
owner: LifecycleOwner,
minActiveState: Lifecycle.State = Lifecycle.State.STARTED,
crossinline action: suspend (value: T) -> Unit,
): Job = owner.lifecycleScope.launch {
owner.repeatOnLifecycle(state = minActiveState) {
Timber.d("Start collecting $owner $minActiveState...")
collect { action(it) }
): Job =
owner.lifecycleScope.launch {
owner.repeatOnLifecycle(state = minActiveState) {
Timber.d("Start collecting $owner $minActiveState...")
collect { action(it) }
}
}
}

/**
* Launches a new coroutine and repeats `block` every time the Fragment's viewLifecycleOwner
Expand All @@ -31,8 +32,9 @@ inline fun <T> Flow<T>.collectInViewLifecycle(
fragment: Fragment,
minActiveState: Lifecycle.State = Lifecycle.State.STARTED,
crossinline action: suspend (value: T) -> Unit,
): Job = collectIn(
owner = fragment.viewLifecycleOwner,
minActiveState = minActiveState,
action = action,
)
): Job =
collectIn(
owner = fragment.viewLifecycleOwner,
minActiveState = minActiveState,
action = action,
)
Loading

0 comments on commit cb8a65f

Please sign in to comment.