kotlin

Unit test the new Kotlin coroutine StateFlow

懵懂的女人 提交于 2020-12-05 06:55:49
问题 Recently was introduced the class StateFlow as part of Kotlin coroutine. I'm currently trying it and encounter an issue while trying to unit test my ViewModel. What I want to achieve: testing that my StateFlow is receiving all the state values in the correct order in my ViewModel. My code is as follow: ViewModel: class WalletViewModel(private val getUserWallets: GetUersWallets) : ViewModel() { val userWallet: StateFlow<State<UserWallets>> get() = _userWallets private val _userWallets:

Unit test the new Kotlin coroutine StateFlow

删除回忆录丶 提交于 2020-12-05 06:55:26
问题 Recently was introduced the class StateFlow as part of Kotlin coroutine. I'm currently trying it and encounter an issue while trying to unit test my ViewModel. What I want to achieve: testing that my StateFlow is receiving all the state values in the correct order in my ViewModel. My code is as follow: ViewModel: class WalletViewModel(private val getUserWallets: GetUersWallets) : ViewModel() { val userWallet: StateFlow<State<UserWallets>> get() = _userWallets private val _userWallets:

Kotlin, Android, how to debug coroutines correctly?

老子叫甜甜 提交于 2020-12-05 03:53:59
问题 I trying to debug my coroutines, and breakpoints placed into suspend function does't work. Pls help me to understand why. Working with Android Studio. Ok, i launch a coroutine from viewModelScope: viewModelScope.launch(IO) { when(val result = interactor.getAllWords()){...} } In getAllWords() i wrote: override suspend fun getAllWords(): WordResult { val words = mutableListOf<Word>() when (val wordsResult = getAllWordsWithoutFiltersApplying()) {} ... return getWordsWithSelectedPattern() I have

Kotlin, Android, how to debug coroutines correctly?

◇◆丶佛笑我妖孽 提交于 2020-12-05 03:47:42
问题 I trying to debug my coroutines, and breakpoints placed into suspend function does't work. Pls help me to understand why. Working with Android Studio. Ok, i launch a coroutine from viewModelScope: viewModelScope.launch(IO) { when(val result = interactor.getAllWords()){...} } In getAllWords() i wrote: override suspend fun getAllWords(): WordResult { val words = mutableListOf<Word>() when (val wordsResult = getAllWordsWithoutFiltersApplying()) {} ... return getWordsWithSelectedPattern() I have

Sorting list based on another list's order [duplicate]

为君一笑 提交于 2020-12-05 02:52:26
问题 This question already has answers here : Guava way of sorting List according to another list? (5 answers) Closed 3 years ago . I need to sort a list of Person objects( List<Person> , where each Person object has few attributes like id (unique), name , age … etc). The sorting order is based on another list. That list contains a set of Person id 's (A List<String> which is already sorted). What is the best way to order the List<Person> in the same order as the list of id 's using Kotlin or Java

【Android】ViewModel 用法及源码解析

。_饼干妹妹 提交于 2020-12-05 01:40:36
本文讲解 ViewModel 用法,以及 ViewModel 源码解析。 官方文档: https://developer.android.google.cn/topic/libraries/architecture/viewmodel 一句话介绍 ViewModel :以注重生命周期的方式存储和管理界面相关的数据,让数据可在发生屏幕旋转等配置更改后继续留存。 注:本文使用 Kotlin 编写。 导入 Lifecycle 库:implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0" 一、用法 1. 自定义布局,一个 TextView ,两个 Button <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"

Public fields for Java compatibility

老子叫甜甜 提交于 2020-12-04 16:00:32
问题 I found recent interest in Kotlin as a language, because the platform we develop for is Java 6 based and hence lacks any syntactic sugar the recent years brought to Java. There's but one thing that makes it impossible to use Kotlin over Java in development, that is, the platform we develop for uses some reflection internally and requires members to be public. It won't work otherwise. So, the bytecode generated from the Kotlin file in fact produces public getters and setters, the fields

Public fields for Java compatibility

≡放荡痞女 提交于 2020-12-04 16:00:10
问题 I found recent interest in Kotlin as a language, because the platform we develop for is Java 6 based and hence lacks any syntactic sugar the recent years brought to Java. There's but one thing that makes it impossible to use Kotlin over Java in development, that is, the platform we develop for uses some reflection internally and requires members to be public. It won't work otherwise. So, the bytecode generated from the Kotlin file in fact produces public getters and setters, the fields

How to set '-Xuse-experimental=kotlin.experimental' in IntelliJ

﹥>﹥吖頭↗ 提交于 2020-12-04 15:58:48
问题 while trying to build a Kotlin/Ktor application in IntelliJ, multiple warnings of the form Warning:(276, 6) Kotlin: This class can only be used with the compiler argument '-Xuse-experimental=kotlin.Experimental' are output. The warnings refer to @UseExperimental(KtorExperimentalLocationsAPI::class) so I expected to satisfy the warning by setting Settings -> Build -> Compiler -> Kotlin Compiler -> Additional command line parameters to -version -Xuse-experimental=kotlin.Experimental . (

How to set '-Xuse-experimental=kotlin.experimental' in IntelliJ

半腔热情 提交于 2020-12-04 15:58:39
问题 while trying to build a Kotlin/Ktor application in IntelliJ, multiple warnings of the form Warning:(276, 6) Kotlin: This class can only be used with the compiler argument '-Xuse-experimental=kotlin.Experimental' are output. The warnings refer to @UseExperimental(KtorExperimentalLocationsAPI::class) so I expected to satisfy the warning by setting Settings -> Build -> Compiler -> Kotlin Compiler -> Additional command line parameters to -version -Xuse-experimental=kotlin.Experimental . (