Skip to content

Kotlin 1.5.0 #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .idea/gradle.xml

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

2 changes: 1 addition & 1 deletion .idea/misc.xml

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

10 changes: 10 additions & 0 deletions .idea/runConfigurations.xml

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

3 changes: 2 additions & 1 deletion app/src/main/java/com/hoc/flowmvi/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ class App : Application() {
startKoin {
androidContext(this@App)

androidLogger(level = Level.DEBUG)
// TODO: Koin
androidLogger(level = Level.NONE)

modules(
coreModule,
Expand Down
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ buildscript {
gradlePluginPortal()
}
dependencies {
classpath("com.android.tools.build:gradle:4.0.2")
classpath("com.android.tools.build:gradle:4.2.0")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
classpath("com.diffplug.spotless:spotless-plugin-gradle:5.10.0")
classpath("com.diffplug.spotless:spotless-plugin-gradle:5.12.4")
}
}

Expand Down
18 changes: 9 additions & 9 deletions buildSrc/src/main/kotlin/deps.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import org.gradle.plugin.use.PluginDependenciesSpec
import org.gradle.plugin.use.PluginDependencySpec

const val ktlintVersion = "0.41.0"
const val kotlinVersion = "1.5.0-M1"
const val kotlinVersion = "1.5.0"

object appConfig {
const val applicationId = "com.hoc.flowmvi"

const val compileSdkVersion = 30
const val buildToolsVersion = "30.0.2"
const val buildToolsVersion = "30.0.3"

const val minSdkVersion = 21
const val targetSdkVersion = 30
Expand All @@ -23,11 +23,11 @@ object appConfig {
object deps {
object androidx {
const val appCompat = "androidx.appcompat:appcompat:1.3.0-rc01"
const val coreKtx = "androidx.core:core-ktx:1.6.0-alpha01"
const val constraintLayout = "androidx.constraintlayout:constraintlayout:2.1.0-beta01"
const val recyclerView = "androidx.recyclerview:recyclerview:1.2.0-rc01"
const val coreKtx = "androidx.core:core-ktx:1.6.0-alpha03"
const val constraintLayout = "androidx.constraintlayout:constraintlayout:2.1.0-beta02"
const val recyclerView = "androidx.recyclerview:recyclerview:1.2.0"
const val swipeRefreshLayout = "androidx.swiperefreshlayout:swiperefreshlayout:1.2.0-alpha01"
const val material = "com.google.android.material:material:1.4.0-alpha01"
const val material = "com.google.android.material:material:1.4.0-beta01"
}

object lifecycle {
Expand All @@ -46,20 +46,20 @@ object deps {
}

object coroutines {
private const val version = "1.4.3"
private const val version = "1.5.0-RC"

const val core = "org.jetbrains.kotlinx:kotlinx-coroutines-core:$version"
const val android = "org.jetbrains.kotlinx:kotlinx-coroutines-android:$version"
}

object koin {
private const val version = "3.0.1-beta-2"
private const val version = "3.0.1"

const val core = "io.insert-koin:koin-core:$version"
const val android = "io.insert-koin:koin-android:$version"
}

const val coil = "io.coil-kt:coil:1.1.1"
const val coil = "io.coil-kt:coil:1.2.1"

object test {
const val junit = "junit:junit:4.13"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.cancel
import kotlinx.coroutines.channels.SendChannel
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.delay
Expand All @@ -38,14 +37,10 @@ import java.util.concurrent.atomic.AtomicBoolean
import java.util.concurrent.atomic.AtomicReference
import kotlin.coroutines.EmptyCoroutineContext

fun <T> SendChannel<T>.safeOffer(element: T): Boolean {
return runCatching { offer(element) }.getOrDefault(false)
}

@ExperimentalCoroutinesApi
fun EditText.firstChange(): Flow<Unit> {
return callbackFlow {
val listener = doOnTextChanged { _, _, _, _ -> safeOffer(Unit) }
val listener = doOnTextChanged { _, _, _, _ -> trySend(Unit) }
awaitClose {
Dispatchers.Main.dispatch(EmptyCoroutineContext) {
removeTextChangedListener(listener)
Expand All @@ -59,7 +54,7 @@ fun EditText.firstChange(): Flow<Unit> {
@CheckResult
fun SwipeRefreshLayout.refreshes(): Flow<Unit> {
return callbackFlow {
setOnRefreshListener { safeOffer(Unit) }
setOnRefreshListener { trySend(Unit) }
awaitClose { setOnRefreshListener(null) }
}
}
Expand All @@ -68,7 +63,7 @@ fun SwipeRefreshLayout.refreshes(): Flow<Unit> {
@CheckResult
fun View.clicks(): Flow<View> {
return callbackFlow {
setOnClickListener { safeOffer(it) }
setOnClickListener { trySend(it) }
awaitClose { setOnClickListener(null) }
}
}
Expand All @@ -77,7 +72,7 @@ fun View.clicks(): Flow<View> {
@CheckResult
fun EditText.textChanges(): Flow<CharSequence?> {
return callbackFlow<CharSequence?> {
val listener = doOnTextChanged { text, _, _, _ -> safeOffer(text) }
val listener = doOnTextChanged { text, _, _, _ -> trySend(text) }
addTextChangedListener(listener)
awaitClose { removeTextChangedListener(listener) }
}.onStart { emit(text) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.scan
import kotlinx.coroutines.withContext
import kotlin.time.Duration
import kotlin.time.ExperimentalTime
import kotlin.time.milliseconds

Expand All @@ -44,7 +45,7 @@ internal class UserRepositoryImpl constructor(
return withContext(dispatchers.io) {
retrySuspend(
times = 3,
initialDelay = 500.milliseconds,
initialDelay = Duration.milliseconds(500),
factor = 2.0,
) {
Log.d("###", "[USER_REPO] Retry times=$it")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import com.hoc.flowmvi.core.clicks
import com.hoc.flowmvi.core.collectIn
import com.hoc.flowmvi.core.navigator.Navigator
import com.hoc.flowmvi.core.refreshes
import com.hoc.flowmvi.core.safeOffer
import com.hoc.flowmvi.core.toast
import com.hoc.flowmvi.ui.main.databinding.ActivityMainBinding
import kotlinx.coroutines.ExperimentalCoroutinesApi
Expand Down Expand Up @@ -76,7 +75,7 @@ class MainActivity : AppCompatActivity() {
ItemTouchHelper(
SwipeLeftToDeleteCallback(context) cb@{ position ->
val userItem = mainVM.viewState.value.userItems[position]
removeChannel.safeOffer(userItem)
removeChannel.trySend(userItem)
}
).attachToRecyclerView(this)
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip