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
  • a

    Ali

    03/31/2022, 3:32 PM
    Hello, Does anyone knows how to get drawable image path as a string inside my repository without using any context?
    :not-kotlin: 4
    a
    i
    • 3
    • 18
  • l

    lam bui

    04/01/2022, 7:48 AM
    private fun getListMedia(): List<EverfitMedia> {
        return mediaAttachmentListNew.filterIsInstance<EverfitMedia>()
    }
    Hello everyone, I’m using filterIsInstance, it’s not working, pls help me, many thanks.
    v
    • 2
    • 5
  • g

    Galou Minisini

    04/01/2022, 12:55 PM
    Hi everyone! I have some experience with coroutine but none with Flow and I'm trying to use them in one of my view. I have my ViewModel `HelpViewmodel`and my view
    HelpView
    . The view is a custom view that extends
    FrameLayout
    and
    LifecycleOwner
    . The view is sometimes being hidden, sometimes being shown. So it goes through the states
    onAttachedToWindow
    and
    onDetachedFromWindow
    where I set my life cycle state:
    override fun onAttachedToWindow() {
        super.onAttachedToWindow()
        lifecycleRegistry.currentState = Lifecycle.State.RESUMED
      }
    
      override fun onDetachedFromWindow() {
        super.onDetachedFromWindow()
        lifecycleRegistry.currentState = Lifecycle.State.DESTROYED
      }
    From my
    init
    in the view I am collection the
    uiState
    , a StateFlow emited by my ViewModel.
    viewModel.uiState.collectIn(this) { uiState ->
      loaderManager.dismiss()
      errorNetwork.isVisible = uiState is HelpViewModel.UiState.Error
      when (uiState) {
        is HelpViewModel.UiState.Loaded -> showContent(<http://uiState.help|uiState.help>)
        HelpViewModel.UiState.Loading -> loaderManager.show(R.string.help_loading)
        else -> return@collectIn
      }
    }
    The
    collectIn
    function is an extension function:
    inline fun <T> Flow<T>.collectIn(
      owner: LifecycleOwner,
      crossinline onCollect: suspend (T) -> Unit
    ) = owner.lifecycleScope.launch { owner.repeatOnLifecycle(Lifecycle.State.STARTED) { collect { onCollect(it) } } }
    My view is receiving correctly the new states at first but once it's hidden it stops collection the new uiState. My viewModel still emits some new state but the view seems to have stop subscribing to it or is not receiving it for some reason. Any idea why?
    a
    r
    • 3
    • 12
  • t

    Tolga ÇAĞLAYAN

    04/02/2022, 10:13 AM
    I've published the country code picker package for Jetpack compose. You may need it. https://github.com/togisoft/jetpack_compose_country_code_picker #jetpack-compose :kotlin-intensifies::android-wave::jetpack-compose:
    m
    • 2
    • 1
  • a

    Asad Mukhtar

    04/02/2022, 8:24 PM
    Hi folks, I have a navigationGraph inside with Bottom Navigation and inside one of fragment that attachto bottom navigaiton, i have 4 other fragments with viewpager + tabs and in every fragment i have one recyclerview, everytime i switch the tab and again back to viewpager, as fragment recreated so adapter reset again and scrolling position move to top, how i maintain the state? i done rnd on few things but nothing help kindly is there anyone who can help me to achieve this? Thanks
    :not-kotlin: 2
    👀 1
    u
    i
    • 3
    • 5
  • s

    Scott Peterson

    04/04/2022, 1:56 AM
    What is everyone using as a date picker in Compose land?
    a
    • 2
    • 1
  • k

    Kevin

    04/04/2022, 8:43 AM
    Hi, recently i was learning on how to make custom views and i'm found out of the resources which using the method to inflate other views(from other xml activity). after trying it out to referencing the custom views in
    activity_main.xml
    in form of
    <com.test_project.library.buttons.TestButton/>
    , it did works perfectly, but i found out that i cannot override the text value because the
    android:text
    doesn't appear from suggestion. is this because the effect from inflating the views? or there is something that missing from the custom views class that i didn't declare it first so i cannot put text value in
    activity_main.xml
    ?
    :not-kotlin: 1
    c
    • 2
    • 3
  • i

    ildar.i [Android]

    04/04/2022, 12:16 PM
    If I’m using Paging 3 for my search list, I want to have a different Pager.flow each time I type something in SearchBox, right? Currently I’m doing this (collect from Paging flow into my SharedFlow):
    private var currentSearch: Job? = null
    private val debounceDelayMs = 500L
    
    private val _searchPagingFlow = MutableSharedFlow<PagingData<TaskModel>>()
    override val searchPagingFlow: Flow<PagingData<TaskModel>> = _searchPagingFlow
    
    override fun searchByText(text: String) {
        currentSearch?.cancel()
        currentSearch = ioThenMain({
            delay(debounceDelayMs)
            repository.searchTasks(text)
        }) { pagingFlow ->
            pagingFlow.collect {
                _searchPagingFlow.emit(it)
            }
        }
    }
    but this approach won’t save current search items, because I’m using SharedFlow. What can I do here to make it work properly?
    j
    • 2
    • 7
  • l

    lam bui

    04/05/2022, 4:53 AM
    How to add and run script to generate image for mutils screen or app icon? I don’t have experience for this part, can you make me a reference document or link? Many thanks.
    :not-kotlin: 1
    u
    • 2
    • 2
  • l

    lawlorslaw

    04/05/2022, 6:00 AM
    i am migrating from rxjava to coroutines and just stumped on something now. is there an equivalent to
    local.onErrorResumeNext { remote }
    with coroutines?
    g
    • 2
    • 24
  • t

    Tower Guidev2

    04/05/2022, 2:29 PM
    Hi i am trying out kotlin 1.7 features in my current Android application and have managed success with contextReceivers however I have one question... why is my "with" shown as redundant?
    l
    r
    • 3
    • 3
  • r

    Rak

    04/05/2022, 8:50 PM
    Hi, I am working on a lib to embedded in our customers apps. It contains a few screens and I am trying to build in some configurability. I have managed to pass in colors that can be used to override some of the elements in the screen but replacing fonts I am stuck on. If the host app has a font that needs to be used by the lib, how would I do that? Is it even possible?
    :not-kotlin: 3
    l
    • 2
    • 5
  • r

    Rahul Ray

    04/06/2022, 12:41 PM
    i have declared some build config fields in the app module. I am not able to access it in other modules. Do i need to include those fields in every module's gradle file? Or is there some different approach to handle this?
    :not-kotlin: 3
    i
    • 2
    • 10
  • a

    althaf

    04/07/2022, 6:03 AM
    Hi it possible to simplify this code in Kotlin
    private fun getAmountLength(currency: CharSequence?, amount: CharSequence?): Int {
        return when {
            !currency.isNullOrEmpty() && !amount.isNullOrEmpty() -> currency.length + amount.length + 1
            !amount.isNullOrEmpty() && currency.isNullOrEmpty() -> amount.length
            amount.isNullOrEmpty() && !currency.isNullOrEmpty() -> currency.length
            else -> 0
        }
    }
    a
    • 2
    • 1
  • a

    althaf

    04/07/2022, 7:21 AM
    hi , any idea why this code snippet doesn't work for buildString , only currency is evaluated , amount and ratepercent are skipped
    spannableAmount = SpannableString(buildString {
        currency?.takeIf { it.isNotEmpty() }?.let { currency ->
            currencyLength1 = currency.length
            append("$currency")
        }
        amount?.takeIf { it.isNotEmpty() }?.let { amount ->
            amountLength1 = currencyLength1 + amount.length
            append(" $amount")
        }
        ratePercent?.takeIf { it.isNotEmpty() }?.let { rate ->
            rateLength1 = amountLength1 + rate.length
            append(" $ratePercent")
        }
    })
    i
    a
    • 3
    • 5
  • m

    Mohammad Jahidul Islam

    04/07/2022, 1:47 PM
    ❓ Hi, I am very beginning in android dev. I want to learn kotlin. Should I need to buy books? I am just learning hear and there from random tutorials. First I take it as a fun. Now I want to take it serious as a career. Thanks in advance
    u
    v
    p
    • 4
    • 4
  • s

    Sam Stone

    04/08/2022, 3:58 AM
    Has anyone ever gotten a
    ClassCastException: LinkedHashMap can't be cast to X
    When using
    by lazy{X}
    ? I think this is the second time, though haven't had it in a while. Code:
    class MyFragment : Fragment() {
    private val foo by lazy { MyDialogFragment(params) }
    fun myFun() {
    foo.show()
    }
    }
    👀 2
    t
    l
    • 3
    • 3
  • c

    Chethan

    04/08/2022, 11:28 AM
    How can merge multiple list to form alternative elements ? We have kotlin zip function to combine two list and to form alternative element list , zip is limited for two list, I have to do for multiple list . what is best approach to do
    c
    t
    • 3
    • 3
  • p

    paul vickers

    04/09/2022, 12:34 PM
    I need to pre populate a database with large amounts of data.
    :not-kotlin: 4
    u
    • 2
    • 2
  • t

    tseisel

    04/10/2022, 9:06 AM
    How do you represent dates in Android with Kotlin? 1️⃣ java.util.Date 2️⃣ kotlinx-datetime 3️⃣ A value class wrapping a Long number of milliseconds 4️⃣ Desugared Java 8 time APIs 5️⃣ Other, please tell us more in thread!
    1️⃣ 1
    4️⃣ 19
    2️⃣ 5
    p
    e
    a
    • 4
    • 5
  • j

    Jean Patricio

    04/11/2022, 1:52 PM
    Hello! A beginner question: Does koin 3 annotations impact build time?
    a
    j
    +2
    • 5
    • 7
  • b

    Barry Fawthrop

    04/11/2022, 2:36 PM
    Hi all, Looking into LiveData ViewModel and Data DAOs and Repositories. I understand you would link a ViewModel with an Activity and thus the data is linked to Views in the Activities View. But how do you link a ViewModel to the Application. Like a User Data, which is needed by multiple Activities. Thus holding one copy of the LiveData for the entire Application. Thanks
    :not-kotlin: 2
    j
    • 2
    • 1
  • g

    Galou Minisini

    04/11/2022, 11:40 PM
    Hi! I sometimes get bug reports with the following stack trace:
    java.lang.IllegalArgumentException · parameter must be a descendant of this view
    ViewGroup.java:7024 android.view.ViewGroup.offsetRectBetweenParentAndChild	
    ViewGroup.java:6946 android.view.ViewGroup.offsetDescendantRectToMyCoords	
    NestedScrollView.java:1445 androidx.core.widget.NestedScrollView.isWithinDeltaOfScreen	
    NestedScrollView.java:1999 androidx.core.widget.NestedScrollView.onSizeChanged	
    View.java:23959 android.view.View.sizeChange	
    View.java:23892 android.view.View.setFrame	
    View.java:23751 android.view.View.layout	
    ViewGroup.java:7277 android.view.ViewGroup.layout	
    LinearLayout.java:1829 android.widget.LinearLayout.setChildFrame	
    LinearLayout.java:1673 android.widget.LinearLayout.layoutVertical	
    LinearLayout.java:1582 android.widget.LinearLayout.onLayout	
    View.java:23754 android.view.View.layout	
    ViewGroup.java:7277 android.view.ViewGroup.layout
    I have never been able to reproduce it so I have no idea where it is coming from. It always happen from the same screen. The screen is mostly composed of several fields that the user has to fill up. Most of those fields are
    EditText
    but the users don't fill them directly. When they press on an EditText, a new activity is opened with a list os several items they can choose from once the select an item that new activity is closed, the user is sent back the form activity and the EditText is automatically filled in with the name of the item selected. The error seems to often happen after selecting a couple of items this way. that's what I can see from the logs but I haven't find a way to reproduce it. It is only happening to some users and not all the time. Mostly happening on Samsung devices but I recently say some reports from pixel devices. Any idea what could go wrong or how I could get more info to try to reproduce it?
    :not-kotlin: 4
    a
    • 2
    • 3
  • a

    Adriano Celentano

    04/12/2022, 9:39 AM
    In my current project we had to remove a function, which we copied from this Google Blog post, because the code has no licence. It seems very strange to me as the Android Dev team write this code for us to use it. Someone can help me how to solve this and give a good argument why we are allowed to use this code ? https://medium.com/androiddevelopers/a-safer-way-to-collect-flows-from-android-uis-23080b1f8bda
    j
    • 2
    • 5
  • a

    Ahmet Hasim Delibas

    04/12/2022, 6:33 PM
    Hey guys. It would be very helpful if you have any idea on this: I have a text file with a long list of strings (12 thousand strings). Would it make sense for me to define a fixed list to use this in my project? Is it better to search through text or use a fixed data structure?
    :not-kotlin: 2
    r
    g
    • 3
    • 5
  • g

    Galou Minisini

    04/12/2022, 8:12 PM
    Is this channel only for android questions purely related to Kotlin? I see that @kenkyee is reacting to every single questions with :not-kotlin:
    i
    k
    +2
    • 5
    • 13
  • a

    Android75

    04/13/2022, 4:32 AM
    I Need to connect 2-3-4 devices in lan, locally and without internet. Is it possible to use Ktor as server in a device? An device become device server and other device can use API to send data.
    😔 1
    :not-kotlin: 2
    l
    • 2
    • 1
  • l

    Lukasz Kalnik

    04/13/2022, 12:51 PM
    I'm using
    viewModelScope
    to collect an endless Flow in my
    viewModel
    . In my unit test I want to "destroy" the ViewModel in order for
    viewModelScope
    to cancel the Flow collection. I'm calling
    viewModel.onCleared()
    but it doesn't cancel the `viewModelScope`'s children jobs. How can I make sure all coroutines started inside
    viewModelScope
    are canceled before my test ends, so
    runTest
    doesn't hang waiting for the coroutines to finish?
    j
    u
    i
    • 4
    • 21
  • k

    Kyaw Linn Thant

    04/13/2022, 2:29 PM
    Hi this is a weird message. I am from Myanmar(Burma) where you heard about military coup from south east asia. I am annative android developer since where I got B.E degree from my university since 2017. I am pretty sure about my native android development. Now let me talk about my desired wish. I am trying to learn iOS development. But I am surely happy to be an Android developer. I heard KMM from my hear and start googling it. Please someone if enough time to help somebody to guide. Please choose me as a teacher or guider. I learn KMM by self. Its rare of resources and I am not enough to learn so detail things. Please can someone help me? I swear I will not distrub you with this. I just want to ask the most difficult thing that I faced not all the way in learning. I will learn by self. Please.
    l
    • 2
    • 9
  • l

    Lokesh Mudgal

    04/14/2022, 10:00 AM
    Hey can anyone help with video caching in exoplayer. Video is playing from URL from the server, and size can be around 10-100 MB What i required is after playing video first time video should play instantly afterwards from cache
    :not-kotlin: 5
    g
    • 2
    • 2
Powered by Linen
Title
l

Lokesh Mudgal

04/14/2022, 10:00 AM
Hey can anyone help with video caching in exoplayer. Video is playing from URL from the server, and size can be around 10-100 MB What i required is after playing video first time video should play instantly afterwards from cache
:not-kotlin: 5
g

gildor

04/14/2022, 10:03 AM
Your question is not Kotlin related, please check this channel description and Kotlin Slack guidelines: https://kotlinlang.org/community/slackccugl.html#common-channels
🆗 1
Be free to delete your message
View count: 15