kotlin

AndroidThreeTen not working in unit test without robolectric?

邮差的信 提交于 2020-07-20 21:00:07
问题 I'm having trouble creating a unit test without needing robolectric. I am using AndroidThreeTen.init(this) in my code and when I run my test if I disable robolectric I get an error: org.threeten.bp.zone.ZoneRulesException: No time-zone data files registered and if I leave it enabled I get this: [Robolectric] com.mycomp.,yapp.utilities.log.LogTest.on Calling function w it returns an Int: sdk=28; resources=BINARY I have tried using testImplementation ‘com.jakewharton.threetenabp:threetenabp:1.1

how to pass suspend function as explicit parameter to coroutine builder?

核能气质少年 提交于 2020-07-20 14:43:28
问题 I'm looking into launch coroutine builder which takes coroutine code as block: suspend CoroutineScope.() -> Unit . We usually pass the code as lambda. However, I was wondering how to pass this function as explicit parameter to launch function. coroutineScope { launch(block = ::myFunction) } suspend fun CoroutineScope.myFunction(): Unit { // coroutine code } It gives following error Type mismatch. Required: suspend CoroutineScope.() → Unit Found: KSuspendFunction0<Unit> What is it that i'm

how to pass suspend function as explicit parameter to coroutine builder?

强颜欢笑 提交于 2020-07-20 14:42:20
问题 I'm looking into launch coroutine builder which takes coroutine code as block: suspend CoroutineScope.() -> Unit . We usually pass the code as lambda. However, I was wondering how to pass this function as explicit parameter to launch function. coroutineScope { launch(block = ::myFunction) } suspend fun CoroutineScope.myFunction(): Unit { // coroutine code } It gives following error Type mismatch. Required: suspend CoroutineScope.() → Unit Found: KSuspendFunction0<Unit> What is it that i'm

Mockito's argThat returning null when in Kotlin

ぃ、小莉子 提交于 2020-07-20 08:23:30
问题 Given the following class (written in kotlin): class Target { fun <R> target(filter: String, mapper: (String) -> R): R = mapper(filter) } I'm able to test in java, the test code: @Test public void testInJava() { Target mockTarget = Mockito.mock(Target.class); Mockito.when(mockTarget.target( argThat(it -> true), Mockito.argThat(it -> true) )).thenReturn(100); assert mockTarget.target("Hello World", it -> 1) == 100; } The java test pass as expected, but the same test is written in kotlin: @Test

Kotlin multiplatform 'Go to declaration' goes to decompiled code

坚强是说给别人听的谎言 提交于 2020-07-20 07:56:39
问题 When using using Android Studio's 'Go to declaration' feature (cmd + click), a decompiled source is shown, when though the source is in my project. The kotlin MP source is in another module. I can connect the source using the 'choose sources...' option, however I have to do this for each file. Is there a global fix for connecting to the correct source files? 来源: https://stackoverflow.com/questions/61230781/kotlin-multiplatform-go-to-declaration-goes-to-decompiled-code

Flutter plugin constructor in class cannot be applied to given types

有些话、适合烂在心里 提交于 2020-07-19 06:03:12
问题 I'm trying to build a simple speech to text application which should continuously listen. Therefore I searched pub.dev for a fitting plugin but unfortunately, there aren't any like that. So the next step would be to integrate it by myself natively. There is one plugin for android called "Droid Speech 2.0"(kotlin). I successfully integrated into a normal android kotlin project. Now I'm trying to build a flutter plugin for me and thought about using platform channels. But because I don't have

How can I debounce a setOnClickListener for 1 second using Kotlin Coroutines?

青春壹個敷衍的年華 提交于 2020-07-19 04:47:45
问题 When user taps fast on the button the showDialog() method displays multiple times on top of each other, so when you dismiss it there is another one behind it. I am looking for a way to ignore the second tap for 1 second without using a handler or check the previous tap's time. //Button that opens a dialog button.setOnClickListener { showDialog() } I am looking for a solution using Kotlin coroutines or Kotlin flows for future implementations. 回答1: It's better to use a simple Flag for that

How can I debounce a setOnClickListener for 1 second using Kotlin Coroutines?

不羁岁月 提交于 2020-07-19 04:47:18
问题 When user taps fast on the button the showDialog() method displays multiple times on top of each other, so when you dismiss it there is another one behind it. I am looking for a way to ignore the second tap for 1 second without using a handler or check the previous tap's time. //Button that opens a dialog button.setOnClickListener { showDialog() } I am looking for a solution using Kotlin coroutines or Kotlin flows for future implementations. 回答1: It's better to use a simple Flag for that

How can I debounce a setOnClickListener for 1 second using Kotlin Coroutines?

蹲街弑〆低调 提交于 2020-07-19 04:47:12
问题 When user taps fast on the button the showDialog() method displays multiple times on top of each other, so when you dismiss it there is another one behind it. I am looking for a way to ignore the second tap for 1 second without using a handler or check the previous tap's time. //Button that opens a dialog button.setOnClickListener { showDialog() } I am looking for a solution using Kotlin coroutines or Kotlin flows for future implementations. 回答1: It's better to use a simple Flag for that

How can I generalize the arity of rxjava2 Zip function (from Single/Observable) to n Nullable arguments without lose its types?

混江龙づ霸主 提交于 2020-07-19 04:40:10
问题 The bounty expires tomorrow . Answers to this question are eligible for a +500 reputation bounty. Damián Rafael Lattenero is looking for a canonical answer : Maybe it could be a generalisation of arity in methods requiring multiple typed arguments. Two Main Problems to solve: 1) Type check is lost Using the array argument Single.zip() version I lose the strongly typed arguments. 2) Source argument Cannot be Nullable I cannot send nullable source values as argument of Single.zip() function 3)