https://kotlinlang.org logo
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
android
  • n

    Napa Ram

    10/19/2021, 12:15 PM
    Hi Team, is ktlint support Compose
    g
    • 2
    • 1
  • u

    慧斌

    10/20/2021, 6:40 AM
    Hi, guys What’s the difference?😆
    typealias HttpCall<T> = suspend () -> Response<HttpResult<T>>
    
    suspend fun <T> HttpCall<T>.doTransform(): Try<T> {
        return try {
            invoke().run {
                if (isSuccessful && body()?.statusCode == 200) {
                    Right(body()!!.result)
                } else {
                    Left(Exception(body()?.message))
                }
            }
        } catch (e: Exception) {
            Left(e)
        }
    }
    //getToken is a REST API by retrofit
    val httpCall: HttpCall<AuthenticationToken> = { service.getToken(params) }
    httpCall.doTransform() // OK
    { service.getToken(params) }.doTransform() // failure
    a
    • 2
    • 2
  • s

    Sergio C.

    10/20/2021, 11:06 AM
    hello all Any ideas why android studio debuger is not showing local variables in suspend functions?
    e
    • 2
    • 2
  • s

    Sergio C.

    10/20/2021, 5:07 PM
    A 'return' expression required in a function with a block body ('{...}'). If you got this error after the compiler update, then it's most likely due to a fix of a bug introduced in 1.3.0 (see KT-28061 for details) this error makes no sense because there are return expressions at all points.. wth This happens when using runCatching inside a suspend function. How can I solve this?
    🧵 2
    • 1
    • 1
  • s

    Sergio C.

    10/20/2021, 5:51 PM
    Kotlin is not happy today... Is this a bug?
    u
    e
    • 3
    • 7
  • c

    Charles Jo

    10/20/2021, 8:58 PM
    Hi. I'm going to use ktor to build an android application that serves https server. The problem is that how can I generate(or get) bks keystore that has trustful certificate. When I use self-signed certificate, the browser notifies that certificate is not trustful. But If I'm going to trustful certificate from a bks keystore, then sslConnector crashes app because of null alias.
    u
    • 2
    • 37
  • x

    xxfast

    10/21/2021, 12:12 AM
    For anyone working with
    WorkManager
    ’s `CoroutineWorker`s, is there a way to run clean up work during
    onStopped()
    ? looks like this is marked as
    final
    in the implementation for some reason
    e
    i
    c
    • 4
    • 5
  • f

    Fernando de Paula

    10/21/2021, 2:18 AM
    i have difficult to understand this val intent = Intent(this, MoviesList::class.java) what "::" means?
    e
    • 2
    • 2
  • i

    Ink

    10/21/2021, 10:18 AM
    enum class ScreenState(val error: ErrorAlertType? = null) {
        LOADING, ERROR, OK
    }
    
    enum class ErrorAlertType {
        CONNECTION, UNKNOWN
    }
    and then
    val state = ScreenState.ERROR(ErrorAlertType.UNKNOWN)
    How I can define my 
    ScreenState
    to get optional parameter for 
    ERROR
    state?
    d
    g
    • 3
    • 2
  • s

    Sergio C.

    10/21/2021, 4:54 PM
    Is it a good idea to call a function in the ViewModel and pass a function as the callback instead of using LiveData or other flow? Is there any memory leak doing this?
    g
    • 2
    • 9
  • s

    Susheel

    10/21/2021, 10:46 PM
    I have an enum class that I'm trying to mock using mockito. All I'm doing is
    val category = mock(Category::class.java)
    where Category is the enum. And when I run the test I'm seeing a
    NoClassDefFoundError
    I already added the mock-maker-inline file but any thoughts on what I'm doing wrong here?
    d
    t
    • 3
    • 4
  • k

    Kwangjo Lee

    10/22/2021, 11:20 AM
    Hi, I am newbie :). I have just one query about jetpack composer. Does anyone know about remoteview example making with compose for home widget? Our team want to percent based layout but it is so complex with current remote view 😞
    c
    m
    • 3
    • 4
  • r

    raghunandan

    10/22/2021, 5:13 PM
    I have to support deep link in my app. I have a deep link activity ( transparent activity) where I have all the re routing logic. The app uses navigation architecture component. But building back stack seems to be a problem. Since we have activities and some fragments. If I deep link to a activity hosting one fragment when app is not opened on clicking back the app exits. There is no other activity in the stack. I do understand that if you have all fragments and you deep link to fragment navigating up will take you to the start destination in nav graph. Is there a way to keep the existing code base and still have a proper back stack.
    :not-kotlin: 1
    i
    • 2
    • 13
  • m

    Marko Novakovic

    10/23/2021, 2:14 PM
    am writing tests for my
    ViewModel
    that exposes state with
    StateFlow
    . I want to test that it emits
    Loading
    state and than starting data fetching process from
    init
    block. when I provide fake API I can’t catch
    Loading
    state because data is fetched immediately and
    Success
    state is emitted. how to test that
    Loading
    comes first followed by
    Success
    ?
    a
    s
    +2
    • 5
    • 8
  • j

    Josefsidhd

    10/24/2021, 9:26 AM
    Please has anyone here worked on an android recovery system before?
    :thread-please: 1
    :not-kotlin: 7
    l
    • 2
    • 2
  • s

    Sergio C.

    10/24/2021, 3:29 PM
    Do we need to import kotlinx-coroutines-android dependencies to use coroutines with kotlin? Kotlin has it’s own coroutines implementations right? What’s the diference between the two?
    b
    s
    a
    • 4
    • 6
  • f

    Francisco

    10/25/2021, 4:09 AM
    Hello everyone! I'm trying to use a ListAdapter, with a list in which items are not unique. Items are kinda like this:
    data class Item(val a: String, val b: String)
    My problems comes trying to create a DiffCallback: If I use oldItem == newItem on
    itemsAreTheSame
    , this is going to return true on items that are not the same, for instance, the first two on the following list: Item("a", "a") Item("a", "a") Item("b", "b") As long as an operation doesn't involve items with the same content, everything works fine: animations, add, edit, move, delete. But this gets buggy when items are equal. If I delete the second item, the first one will also be deleted. If I add or move something, the animation is wrong, kind of reversed. What I wanted to know is if there's any other way to handle something like this, without adding an identifier, nor using a custom differ without ListAdapter.
    u
    • 2
    • 2
  • k

    kierans777

    10/25/2021, 4:32 AM
    I'm wanting to use an ExpansionPanel (https://material.io/archive/guidelines/components/expansion-panels.html) in Compose. However I can't seem to find the right function. Can anyone help me please?
    c
    • 2
    • 2
  • m

    maxmello

    10/25/2021, 7:28 AM
    viewModelScope
    and
    lifecycleScope
    both run on the Main Dispatcher. All the official and unofficial examples of these scopes together with a
    StateFlow
    or
    SharedFlow
    show this:
    .stateIn(viewModelScope, ...) or .sharedIn(viewModelScope, ...)
    . But this means that all the calculations (for example when using
    combine
    ) then run on the main thread. Wouldn’t the better default be to always run
    SharedFlow
    and
    StateFlow
    in
    viewModelScope + Dispatchers.Default
    ? When collecting the flow, it will run in another coroutine anyway, and UI operations can be done on the Main dispatcher.
    f
    a
    • 3
    • 2
  • s

    Shreyas Patil

    10/25/2021, 3:15 PM
    Hi, facing this issue, did anyone faced this and tackled it? https://stackoverflow.com/questions/69678819/exception-in-android-app-failed-resolution-of-lorg-jacoco-agent-rt-internal-8f
    a
    • 2
    • 5
  • a

    Ashu

    10/26/2021, 7:58 AM
    Is there a way to pass the right hand side of
    {SomeObject} is {SomeClass}
    as a parameter? I am trying to perform type checking inside a function where the type to check for meeds to be passed as an argument. Any way to achieve this?
    i
    e
    • 3
    • 9
  • f

    Farid Mrz

    10/26/2021, 2:21 PM
    hello, With the new navHost how do you pass data to an activity destination? With composable you can use the NamedNavArguments. But these seem not to be available for activities? Is there a way to pass parcelable data that you could put in the intent of the activity you are starting?
    :not-kotlin: 2
    c
    • 2
    • 3
  • n

    Noel Stieglitz

    10/26/2021, 2:54 PM
    Hello! Are there any plans for Databinding to use KSP instead of Kapt?
    g
    m
    +2
    • 5
    • 8
  • z

    zain

    10/27/2021, 2:24 PM
    Simpler way to add a common filter to reduce the same variable call
    players.filter {
        it.pStatus != "E" && it.pStatus != "I" && it.pStatus != "S" && it.pStatus != "D" && it.pStatus != "R" && it.pStatus != "NIS"
    }
    l
    • 2
    • 2
  • w

    William Reed

    10/27/2021, 5:05 PM
    if i have a
    value class
    , can I send it through a bundle as the type of it’s backing field? or do i need the class to be
    Parcelable
    ?
    • 1
    • 1
  • t

    tateisu

    10/27/2021, 10:23 PM
    https://gist.github.com/tateisu/cbda451135d2b5c9b69f7ac4599f9833 small test code for this problem
    :thread-please: 1
    e
    • 2
    • 4
  • m

    Md. Nazmun Sadat Khan

    10/28/2021, 5:01 AM
    Hey, I want to share a project on Github from Android Studio (Artic Fox) to get some feedback, but no matter how hard I try the initial commit operation always fails with the error "GIT_ASKPASS_TOKEN environment variable is not defined!" For some context, I integrated Android Studio to GitHub via personal tokens, with the right permissions and set to expire next month. I tried making new tokens too, but that didn't help. Googling the issue didn't bring up any good solutions to this either. I'm stuck. What should I do?
    :not-kotlin: 6
    i
    • 2
    • 2
  • z

    zain

    10/28/2021, 5:41 AM
    I have 400 players with 4 skills I want to group them by skill but take only 20 from each skill
    players.groupBy {
        it.skill
    }
    • 1
    • 2
  • g

    Graeme Laws

    10/28/2021, 10:04 AM
    Hi guys. Hopefully this is the best place to ask. I'm currently evaluating building our app in Kotlin Multiplatform. There is a separate iOS project being developed, but the idea is to keep the door open to implement the iOS version in the KMM project later down the line. I've been researching app architectures, and there doesn't seem to be a main consensus on the best one to use (even a link to a page on the kotlin homepage discussing this is no longer available). One of the requirements is we'll be using Jetpack Compose and SwiftUI, and it seems only the MVI pattern allows us to be truly multiplatform without separate presentation logic and testing. The issue is that most of these articles i've been reading are a few years old now, and I wanted to know what the latest recommendations are? I found the todoapp example project which seems to satisfy our requirements. Would this be the recommended way to go? https://github.com/JetBrains/compose-jb/tree/master/examples/todoapp
    d
    c
    e
    • 4
    • 4
  • u

    undermark5

    10/28/2021, 8:41 PM
    I’ve got this code
    fun onFinishedProcessingEvent(event: FinishedProcessing) {
        when (event) {
            is FinishedProcessingSuccessfully -> {
                onAuthenticationSuccess()
            }
            is FinishedProcessingUnsuccessfully -> {
                onAuthenticationFailure(event)
            }
        }
    }
    where
    FinishedProcessing
    is defined as follows
    sealed class FinishedProcessing(val status: String)
    class FinishedProcessingSuccessfully(status: String = "success"): FinishedProcessing(status)
    class FinishedProcessingUnsuccessfully(error: String) : FinishedProcessing(error)
    Intellisense in Android Studio (Android Studio Arctic Fox | 2020.3.1 Patch 3) is suggesting that I make the when exhaustive by adding an
    else
    branch because I’m using a sealed class. However, as far as I can tell, this should be exhaustive without the else, or is there something I’m missing?
    • 1
    • 1
Powered by Linen
Title
u

undermark5

10/28/2021, 8:41 PM
I’ve got this code
fun onFinishedProcessingEvent(event: FinishedProcessing) {
    when (event) {
        is FinishedProcessingSuccessfully -> {
            onAuthenticationSuccess()
        }
        is FinishedProcessingUnsuccessfully -> {
            onAuthenticationFailure(event)
        }
    }
}
where
FinishedProcessing
is defined as follows
sealed class FinishedProcessing(val status: String)
class FinishedProcessingSuccessfully(status: String = "success"): FinishedProcessing(status)
class FinishedProcessingUnsuccessfully(error: String) : FinishedProcessing(error)
Intellisense in Android Studio (Android Studio Arctic Fox | 2020.3.1 Patch 3) is suggesting that I make the when exhaustive by adding an
else
branch because I’m using a sealed class. However, as far as I can tell, this should be exhaustive without the else, or is there something I’m missing?
Ah, I found the issue, though it could potentially be a bug in intellisesne, my issue was the file the
FinishedProcessing
was in had the incorrect package directive.
View count: 6