Fisayo
05/14/2022, 8:06 AMSlackbot
05/14/2022, 10:47 AMBreaker ACT
05/14/2022, 3:26 PMval numberChannel = Channel<Int>(capacity = Channel.BUFFERED)
GlobalScope.launch {
numberChannel.send(0)
numberChannel.send(1)
numberChannel.send(2)
numberChannel.send(3)
numberChannel.send(4)
numberChannel.send(5)
numberChannel.send(6)
numberChannel.send(7)
}
GlobalScope.launch {
delay(1000)
numberChannel.receiveAsFlow()
.filter { it % 2 == 0 }
.collectLatest {
Timber.d("------Collect1: $it") //expect print: 0,2,4,6
}
}
GlobalScope.launch {
delay(2000)
numberChannel.receiveAsFlow()
.collectLatest {
Timber.d("------Collect2: $it") //expect print: 1,3,5,7
}
}
Slackbot
05/15/2022, 6:34 PMYoshio Schermer
05/16/2022, 2:25 PMChukwuka Eze
05/17/2022, 8:57 AMVivek Modi
05/17/2022, 9:18 AMval completeEvent = events?.lastOrNull { events -> events.status == "complete" }
val activeEvent = events?.find { events -> events.status == "active" }
val futureEvent = events?.firstOrNull { events -> events.status == "future" }
ApiResponse
"Events": [{
"title": "Test 1",
"status": "complete"
}, {
"title": "Test 2",
"status": "complete"
}, {
"title": "Test 3",
"status": "complete",
}, {
"title": "Test 4",
"status": "complete"
}, {
"title": "Test 5",
"status": "complete"
}, {
"title": "Test 6",
"status": "active"
}, {
"title": "Test 7",
"status": "future"
}, {
"title": "Test 8",
"status": "future"
}]
haris mehmood
05/18/2022, 9:52 AMVivek Modi
05/18/2022, 9:41 PMAaron Waller
05/19/2022, 6:28 PMError: java.lang.IllegalArgumentException: Uri lacks 'file' scheme: <content://media/external/images/media/54545>
Kaushalya
05/20/2022, 2:39 AMSatyam G
05/20/2022, 9:52 AMobject Extensions{
fun TextUtils.checkEmpty(str: String?): String? {
if (!TextUtils.isEmpty(str)) {
return str
} else {
return null
}
}
}
I have written this but not able to access this method. What is getting wrong here ??Chetak Bhimani
05/20/2022, 9:57 AMfun String.checkEmpty(str: String?): String? {
if (!TextUtils.isEmpty(str)) {
return str
} else {
return null
}
}
Iqbal Ahmed
05/20/2022, 10:49 AMmanju reddy
05/20/2022, 4:55 PMlam bui
05/22/2022, 4:37 AMNicolai
05/24/2022, 3:53 PM[{id: 1, isSomething: false},{id: 2, isSomething: false}]
and list B
[{id: 1, isSomething: true}]
Is there an easy nice clean way in kotlin to merge the two lists so it ends up favoring list B ending up giving me
{id: 1, isSomething: true},{id: 2, isSomething: false}]
Bhumil
05/24/2022, 11:21 PMMichaeljon Hayden
05/25/2022, 4:11 PMRaed Ghazal
05/26/2022, 3:38 PMSusheel
05/26/2022, 5:46 PMTask :*****App:compileGoogleReleaseKotlin FAILED
Unresolved reference: viewModelsThis is the
by viewModels()
code. The debug build compiles successfully, so I'm perplexed by the release build issue. Any ideas?TarunY
05/27/2022, 9:48 AMLucas Mo
05/27/2022, 1:48 PMazabost
05/27/2022, 6:55 PM./gradlew :app:installDebug
though, so I thought that it might be related with Gradle’s file system watching not working correctly (I’m on 7.4.2), therefore I disabled it in gradle.properties
but it didn’t help at all.
Any clues?
EDIT:
How is this “not Kotlin”?
Perhaps it’s a problem with the Kotlin compiler/plugin not recompiling the sources after they are changed?Lilly
05/28/2022, 10:16 PM@IntRange
annotation for kotlin which I can use in kotlin only module? @IntRange works at compilation time right?fulstaph
05/29/2022, 5:29 PMRene Win
05/31/2022, 9:15 AMval test = chunked(2)
.map { it.toInt(16).toUByte() }
val test2: UByteArray = test.toUByteArray()
when i debug those values, the test is an arrayList of UByte (correct), but the test2 value shows in the debugger thats an byte[] instead of ubyte[].
is that just an bug in the debugger because its experimental? i cannot find an answer somewhereLilly
05/31/2022, 11:22 AMwhenNotNull
function:
inline fun <T : Any, R> whenNotNull(input: T?, callback: (T) -> R): R? = input?.let(callback)
usage:
override fun onReceive(context: Context?, intent: Intent?) {
whenNotNull(intent) {
it.someAction()
}
}
I have often problems with shadowed variable names, e.g. I cannot write:
override fun onReceive(context: Context?, intent: Intent?) {
whenNotNull(intent) { intent -> // shadowed
intent.someAction()
}
}
Is there some construct to recognize that intent
is not null within the callback
block, so I can write:
override fun onReceive(context: Context?, intent: Intent?) {
whenNotNull(intent) {
intent.someAction()
}
}
I have enabled some static analyzer tools which complain about the "it". I know I can just write whenNotNull(intent) { _intent -> }
but I'm curious if there is some Kotlin construct which targets this case.Louis Gautier
05/31/2022, 7:01 PMfun <A, B>LiveData<A>.combine(
vararg other: LiveData<*>,
combiner: (/*Don't know*/) -> B
) {
val result = MediatorLiveData<B>()
other.forEach { liveData ->
result.addSource(liveData) {
if (other.toList().all { it.value != null }) {
result.postValue(combiner(other))
}
}
}
}
usage :
fun a() {
MutableLiveData<Int>().combine2(MutableLiveData<Boolean>()) { entry1, entry2, etc ->
}
}
Do you have any ideas ?Philipp Smorygo [JB]
05/31/2022, 10:07 PMplugins {
kotlin("multiplatform")
id("com.android.application")
}
group = "me.user"
version = "1.0-SNAPSHOT"
kotlin {
android()
sourceSets {
val androidMain by getting {
dependencies {
val compose_version = "1.2.0-beta02"
implementation(project(":shared"))
implementation("androidx.core:core-ktx:1.7.0")
implementation("androidx.compose.ui:ui:$compose_version")
implementation("androidx.compose.runtime:runtime:$compose_version")
implementation("androidx.compose.ui:ui-tooling:$compose_version")
implementation("androidx.compose.foundation:foundation:$compose_version")
implementation("androidx.compose.ui:ui-tooling-preview:$compose_version")
implementation("androidx.compose.material:material:$compose_version")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.4.1")
implementation("androidx.activity:activity-compose:1.4.0")
implementation("com.google.android.material:material:1.5.0")
implementation("androidx.appcompat:appcompat:1.4.1")
implementation("androidx.constraintlayout:constraintlayout:2.1.3")
}
}
}
}
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions {
jvmTarget = "1.8"
}
}
android {
compileSdkVersion(32)
defaultConfig {
applicationId = "me.user.androidApp"
minSdkVersion(24)
targetSdkVersion(32)
versionCode = 1
versionName = "1.0"
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
buildTypes {
getByName("release") {
isMinifyEnabled = false
}
}
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.2.0-beta02"
}
}
But the problem is that application fails to build with
Caused by: java.lang.IllegalStateException: couldn't find inline method Landroidx/compose/runtime/ComposablesKt;.remember(Lkotlin/jvm/functions/Function0;)Ljava/lang/Object;
at org.jetbrains.kotlin.codegen.inline.SourceCompilerForInlineKt.getMethodNode(SourceCompilerForInline.kt:118)
at org.jetbrains.kotlin.codegen.inline.SourceCompilerForInlineKt.loadCompiledInlineFunction(SourceCompilerForInline.kt:96)
at org.jetbrains.kotlin.backend.jvm.codegen.IrSourceCompilerForInline.compileInlineFunction(IrSourceCompilerForInline.kt:90)
at org.jetbrains.kotlin.codegen.inline.InlineCodegen.performInline(InlineCodegen.kt:47)
... 67 more
Kotlin is 1.6.21
AGP version 7.2.1
I have
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.2.0-beta02"
}
In my shared
module as well (edited)Philipp Smorygo [JB]
05/31/2022, 10:07 PMplugins {
kotlin("multiplatform")
id("com.android.application")
}
group = "me.user"
version = "1.0-SNAPSHOT"
kotlin {
android()
sourceSets {
val androidMain by getting {
dependencies {
val compose_version = "1.2.0-beta02"
implementation(project(":shared"))
implementation("androidx.core:core-ktx:1.7.0")
implementation("androidx.compose.ui:ui:$compose_version")
implementation("androidx.compose.runtime:runtime:$compose_version")
implementation("androidx.compose.ui:ui-tooling:$compose_version")
implementation("androidx.compose.foundation:foundation:$compose_version")
implementation("androidx.compose.ui:ui-tooling-preview:$compose_version")
implementation("androidx.compose.material:material:$compose_version")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.4.1")
implementation("androidx.activity:activity-compose:1.4.0")
implementation("com.google.android.material:material:1.5.0")
implementation("androidx.appcompat:appcompat:1.4.1")
implementation("androidx.constraintlayout:constraintlayout:2.1.3")
}
}
}
}
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions {
jvmTarget = "1.8"
}
}
android {
compileSdkVersion(32)
defaultConfig {
applicationId = "me.user.androidApp"
minSdkVersion(24)
targetSdkVersion(32)
versionCode = 1
versionName = "1.0"
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
buildTypes {
getByName("release") {
isMinifyEnabled = false
}
}
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.2.0-beta02"
}
}
But the problem is that application fails to build with
Caused by: java.lang.IllegalStateException: couldn't find inline method Landroidx/compose/runtime/ComposablesKt;.remember(Lkotlin/jvm/functions/Function0;)Ljava/lang/Object;
at org.jetbrains.kotlin.codegen.inline.SourceCompilerForInlineKt.getMethodNode(SourceCompilerForInline.kt:118)
at org.jetbrains.kotlin.codegen.inline.SourceCompilerForInlineKt.loadCompiledInlineFunction(SourceCompilerForInline.kt:96)
at org.jetbrains.kotlin.backend.jvm.codegen.IrSourceCompilerForInline.compileInlineFunction(IrSourceCompilerForInline.kt:90)
at org.jetbrains.kotlin.codegen.inline.InlineCodegen.performInline(InlineCodegen.kt:47)
... 67 more
Kotlin is 1.6.21
AGP version 7.2.1
I have
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.2.0-beta02"
}
In my shared
module as well (edited)ephemient
06/01/2022, 1:06 AMPhilipp Smorygo [JB]
06/01/2022, 9:30 AM