https://kotlinlang.org logo
Docs
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
  • o

    oday

    09/30/2022, 11:38 AM
    is there a defacto/known way to park network requests when network is not available and make the requests again when network is back? seems like a typical requirement
    k
    g
    • 3
    • 3
  • a

    althaf

    10/01/2022, 10:38 AM
    Hi, Here the WishesByCategory is a domain model with following definition
    data class WishesByCategory(val id: Int, val name: String, val wishes: List<Wish>)
    Code below is the from a repository mapper, that maps WishesResponse to the domain model, I'm stuck with the code at 'When' statement, since all the domains models are immutable in my case, i have to make it mutable list explicitly as shown below, however, the follow code doesn't work as each time the loop run it creates fresh list. Final result is that each domain model end up with empty list. Is there a better way to write this code ?
    private fun List<WishesRpse>.toWishesByCategory(): List<WishesByCategory> {
        val result: ArrayList<WishesByCategory> = ArrayList()
        val expWbyC =
            WishesByCategory(1, context.getString(R.string.jp_wish_cat_experience), listOf())
        val eventWbyC =
            WishesByCategory(2, context.getString(R.string.jp_wish_cat_events), listOf())
        val serviceWbyC =
            WishesByCategory(3, context.getString(R.string.jp_wish_cat_services), listOf())
        val moblityWbyC =
            WishesByCategory(4, context.getString(R.string.jp_wish_cat_mobility), listOf())
        val othersWbyC =
            WishesByCategory(5, context.getString(R.string.jp_wish_cat_others), listOf())
        forEach {
            when (it.id) {
                in experience ->
                    expWbyC.wishes.toMutableList()
                in events ->
                    eventWbyC.wishes.toMutableList()
                in service ->
                    serviceWbyC.wishes.toMutableList()
                in mobility ->
                    moblityWbyC.wishes.toMutableList()
                else -> othersWbyC.wishes.toMutableList()
            }.add(Wish(it.id, it.name))
        }
        listOf<WishesByCategory>(
            expWbyC,
            eventWbyC,
            serviceWbyC,
            moblityWbyC,
            othersWbyC
        ).forEach {
            if (it.wishes.isNotEmpty()) result.add(it)
        }
        return result
    }
    m
    • 2
    • 2
  • m

    Mohamed Ibrahim

    10/02/2022, 11:03 AM
    Any ideas of how to handle product flavors cleanly and neatly?
  • e

    Eric Womer

    10/02/2022, 12:56 PM
    What do I need to import inorder to use fun someFun(variable:Dp [<<= this thing here, the Dp])
    m
    m
    • 3
    • 9
  • e

    Eugene Maksymenko

    10/02/2022, 8:43 PM
    👋 Hello, team! Let me introduce WorldWind Kotlin - the first multi-platform planetary 3D globe library for JS, Android and JVM
    g
    • 2
    • 1
  • s

    Sam

    10/03/2022, 3:24 AM
    Hi everyone, Do you know any tools or plugin to convert synthetics to view binding? Thanks
  • o

    Og'abek Tirkashov

    10/03/2022, 4:06 AM
    👋 Hello, team!
  • k

    Katarzyna

    10/03/2022, 12:02 PM
    This time Ngenge Senior shows you how to do Firebase authentication using SMS. ✉️ Find the whole article here: 👇 https://blog.kotlin-academy.com/firebase-phone-authentication-in-jetpack-compose-using-mvvm-architecture-258775059aa7
  • s

    Sky

    10/03/2022, 6:26 PM
    Hi guys, i have a post request that returns: { “id”:“unique-id-of-the-new-favourite” } … so im wondering in order to get the return value do i need to create a new Kotlin data class?.. or can i just speicfy a return type…
    s
    • 2
    • 7
  • i

    Ihoby Christian

    10/04/2022, 6:56 AM
    👋 Hello, team!
  • a

    Ahmed Sellami

    10/04/2022, 8:50 AM
    How can I mix these two classes in an observable that handles both normal and one time observation without rewriting the logic? In other words, how can I create a class that somehow extends these two?
    open class OneTimeObservable {
        private var isInitialised = false
        var state = false
            set(value) {
                field = value
                isInitialised = true
                if (oneTimeObservers.isNotEmpty()) {
                    notifyOneTimeObservers(value)
                }
            }
    
        private val oneTimeObservers = mutableMapOf<String, (Boolean) -> Unit>()
    
        fun whenReady(tag: String, listener: (Boolean) -> Unit): Boolean {
            return if (!isInitialised) {
                oneTimeObservers[tag] = listener
                false
            } else {
                listener(state)
                true
            }
        }
    
        private fun notifyOneTimeObservers(boolean: Boolean) {
            oneTimeObservers.forEach {
                it.value(boolean)
            }
            oneTimeObservers.clear()
        }
    }
    
    open class Observable {
        var state = false
            set(value) {
                field = value
                notifyObservers(value)
            }
    
        private val observers = mutableMapOf<String, (Boolean) -> Unit>()
    
        fun addObserver(tag: String, observer: (Boolean) -> Unit) {
            observers[tag] = observer
        }
    
        private fun notifyObservers(boolean: Boolean) {
            observers.forEach {
                it.value(boolean)
            }
        }
    }
    i
    • 2
    • 2
  • p

    pablisco

    10/04/2022, 5:54 PM
    Hey fellow Android Kotliners. I’m working on kopyk.at and I just managed to use it on an Android app. We are looking to have a final RC in a month or so (no warranties, as I may find a job before that). Would look to get some feedback on it if people want to give it a try 🙂 🙏
  • n

    Naveen

    10/06/2022, 5:09 AM
    Hello Devs, can anyone help me with this. So I’ve a very famous problem with Navigation Component of fragment recreating when back is pressed, it happens in this case : There are 2 fragments A and B where A is having list of items: 1. Scroll down to bottom of list on A 2. Navigate from A to B 3. Press back button 4. Fragment A state is changed and it’s not at the bottom of the list How can I prevent Fragment A state from getting destroyed and recreated ?
    d
    • 2
    • 5
  • j

    Jan

    10/06/2022, 12:32 PM
    Hi, I have a question regarding a ColorStateListResource: 1. In my res/color folder I have created a color list selector resource, see https://developer.android.com/guide/topics/resources/color-list-resource 2. Its working fine e.g. on Android 11 3. It crashes e.g. on Android 6.0.1 with: XmlPullParserException: <item> tag requires a 'drawable' attribute ... If I create a drawable list selector under res/drawable its working as well, but thats not what I want. Is that a known issue in some of the jetpack libraries I am using or something else? Thanks ...
    k
    a
    • 3
    • 6
  • a

    Ahmed Sellami

    10/06/2022, 1:25 PM
    How can I retrieve an item from a list and add it if it does not exist and get its reference again? I guess I can do better than this.
    var playedPodcast = playedPodcasts.find {
        it.id == itemToPlay?.id
    }
    if (playedPodcast == null) {
        playedPodcasts.add(PlayedPodcast(itemToPlay?.id, mutableListOf()))
    }
    playedPodcast = playedPodcasts.find {
        it.id == itemToPlay?.id
    }!!
    c
    d
    • 3
    • 8
  • i

    ilushakr

    10/06/2022, 1:53 PM
    HI guys mb someone knows is there any way to create two shared modules with KMM project (for example shared and feature) and use it both in ios app via cocoapods(as i undersand via regular frameworks its restricted bc only one searching path)? also if yes can i make one of theese modules dependent from anouther (module feature implements shared)?
    c
    • 2
    • 3
  • n

    Niclas Hjalmarsson

    10/07/2022, 9:49 AM
    Hi guys I have a question on windowInsets and how it works when the app is no longer in the foreground. For starters I have a full compose app, with just one activity calling
    WindowCompat.setDecorFitsSystemWindows(window, false)
    to let me draw behind the systembars. So all my compose views (that need it ofc) calls
    Modifier.systemBarPadding()
    for statusbar and navbar padding, and it works as expected. But I’ve found that calling for example an Intent chooser to pick an app to open like an installed email app, makes the
    systemBarPadding()
    return 0 and my layout jumps to underneath the status bar. And it’s all very visible since the dialog from the Intent chooser is not covering the entire screen. Any tips on how I can make
    systemBarPadding()
    keeping it’s value even after the app is not in the foreground anymore? Thanks for any help.
    i
    • 2
    • 2
  • n

    Naresh

    10/07/2022, 10:38 AM
    could anyone help me to learn about Retrofit API calls in Android from the scratch?
    e
    • 2
    • 2
  • k

    KotlinLeaner

    10/07/2022, 11:58 AM
    Hi guys, I have two UUID which is
    0x1810
    ,
    0x2A35
    . So I am adding value in my btyeArrayof but it giving me error on my side. Please also guide me how can I pass data to scan filters with multiple id.
    • 1
    • 2
  • a

    Abdulaziz Mohammed

    10/07/2022, 5:29 PM
    what is different between flatmapconcat and flatmaplatest?
    g
    • 2
    • 2
  • s

    Santiago

    10/07/2022, 10:48 PM
    Hi there. I created a Xamarin Bindings library for a native library I wrote in Kotlin Multiplatform Mobile that depends on ktor. When I launch the Android app that uses this bindings library wrapping the ktor library, I see the following error
    Java.Lang.NoClassDefFoundError: Failed resolution of: Lio/ktor/client/engine/okhttp/OkHttp; ---> Java.Lang.ClassNotFoundException: Didn't find class "io.ktor.client.engine.okhttp.OkHttp" on path
    I understand I'm missing a dependency on my bindings library / xamarin forms app, but I'm not sure how to proceed. Did anyone try already to use a KMM library with ktor dependency from Xamarin Forms that experienced this error before? Thanks.
  • i

    Isaac Akakpo

    10/08/2022, 6:06 PM
    Hello guys.. I created a portfolio site using Jetpack Compose.. check ot out here.. https://develnerd.github.io/
  • e

    Eric Womer

    10/09/2022, 2:13 PM
    How do I call a @Composable function from within LiveData's observe method?
    a
    • 2
    • 11
  • e

    Eric Womer

    10/09/2022, 2:15 PM
    And why can't you overload a method and add @Composable to it?
    a
    • 2
    • 2
  • e

    Eric Womer

    10/10/2022, 12:31 AM
    Anyone got any suggestions recomendations on video/ or other series on learning coroutines and compose with MVVM in mind?
    a
    j
    • 3
    • 2
  • s

    Sharansalian Dev

    10/10/2022, 5:04 AM
    Any Android Expert that can help me with this?
    https://stackoverflow.com/questions/74010297/create-a-needle-gaugeview-from-ios-swift-to-androidkotlin
  • a

    Azhar

    10/10/2022, 5:57 AM
    How can I animated real invoice receipt gif for each item clicking kotlin code
  • a

    althaf

    10/11/2022, 5:07 AM
    Hi, there this block is still asking for a return statement, though i'm only able to return from the 'fold' block, any way out of it ?
    override suspend fun load(params: LoadParams<Int>): LoadResult<Int, Hotel> {
        val currentPage = params.key ?: pageSetting.page
        hotelSearchRepository.search(
            hotelInquiry,
            page = currentPage,
            itemsPerPage = pageSetting.records
        ).collect { result ->
    >>>>>     return@collect  result.fold(onSuccess = { hotelInquiryDetails ->
                Page(
                    data = hotelInquiryDetails.hotels,
                    prevKey = if (currentPage == STARTING_PAGE_INDEX) null else (currentPage - 1),
                    nextKey = if (hotelInquiryDetails.hotels.isEmpty()) null else (currentPage + pageSetting.records)
                )
            }, onFailure = {
                Error<Int, Hotel>(Exception(it))
            })
        }
    } <<<<< - Error not return statement
    g
    • 2
    • 7
  • s

    Sergio C.

    10/11/2022, 8:36 AM
    Hi, Why is Kotlin version 1.7.20 not available in Android Studio to update? Gradle lint suggests the new version but it's not available in the stable channel.
    y
    m
    m
    • 4
    • 7
  • c

    CS_047_HARI OM DWIVEDI

    10/11/2022, 7:08 PM
    👋 Hello, team!
Powered by Linen
Title
c

CS_047_HARI OM DWIVEDI

10/11/2022, 7:08 PM
👋 Hello, team!
View count: 2