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

    Slackbot

    07/30/2022, 11:36 AM
    This message was deleted.
    c
    b
    • 3
    • 5
  • k

    Kashismails

    07/30/2022, 1:43 PM
    do you have any example of realm migration ? i have added a new entity and that requires realm to be migrated but i am unable to migrate my db. Secondly, if i use "delete realm if migration is needed" then on retrieving data the new entity is getting default values.
    open class RealmServiceImpl(private val realm: Realm) {
        fun insertSupplier(supplier: SupplierDomainModel) {
    
            CoroutineScope(Dispatchers.Default).async {
                write(supplier)
            }
    
        }
    
        fun insertPackedOrder(order: OrderDomainModel) {
            CoroutineScope(Dispatchers.Default).async {
                writeOrderPacked(order)
            }
        }
    
        private suspend fun writeOrderPacked(order: OrderDomainModel) =
            realm.write {
                copyToRealm(
                    order.asOrderEntity()
                )
            }
    
        private suspend fun write(supplier: SupplierDomainModel) =
            realm.write {
               copyToRealm(
                    supplier.asEntity()
                )
            }
    
        private fun delete() {
            realm.writeBlocking {
                val writeTransactionTasks = realm.query<SupplierEntity>().find()
                delete(writeTransactionTasks)
            }
        }
    
        fun removePackedOrder(order: OrderDomainModel) {
            CoroutineScope(Dispatchers.Default).launch {
                removeOrder(order)
            }
        }
    
        private suspend fun removeOrder(order: OrderDomainModel) {
            realm.write {
                val deletable = this.query<OrderEntity>("orderId == ${order.orderItemId}").find().first()
                delete(deletable)
            }
        }
    
        fun getPackedOrders() = realm.query<OrderEntity>().find()
    
        fun getSupplier() = realm.query<SupplierEntity>().find().last()
    
    }
    this is my realm class supplier's data is getting retrieved successfully
    suspend fun getShippingBookedOrders(): DataState<List<OrdersDTO>> {
        return withContext(Dispatchers.Default + SupervisorJob()) {
            val ktor = async {
                ktorService.getShippingBookedOrders(supplierId = supplier!!.sid)
            }
    
            val ktorServiceList = ktor.await()
            val ordersList =realmServiceImpl.getPackedOrders()
    
            ktorServiceList.data?.asDomainModel()?.map { item ->
                item.isPacked = ordersList.any {
                    item.orderItemId == it.orderId
                }
            }
    
            ktorServiceList
        }
    }
    open class OrderEntity: RealmObject {
       open var orderId: Int = -130
    }
  • k

    Kashismails

    07/30/2022, 1:43 PM
    i am using kmm version of realm
  • a

    andylamax

    07/30/2022, 7:53 PM
    Welcome to the kotlin slack @Yesayaathuman Questions like these (General android questions) are most suited for stack overflow or the android slack. Not the kotlin slack. That being said IIRC, starting from version 2.6.0, retrofit did start supporting coroutines and suspend functions. Meaning
    @POST("login")
    suspend fun login(
        email: String,
        password: String
    ) : Call<AccessToken>
    can just be written as
    suspend fun login(
        email: String,
        password: String
    ) : AccessToken          // Notice that there is no need to Wrap this inside a Call object
    Keep in mind that before embracing coroutines, your code could have looked like this (without the suspend keyword)
    @POST("login")
    fun login(                // Notice that there is no suspend modifier here
        email: String,
        password: String
    ) : Call<AccessToken>
    After you change your return type, you can just wrap your service in a try catch block like this
    try {
        val token = service.login("<mailto:yesaya@athumani.com|yesaya@athumani.com>","secure-password")
    } catch(exception: Throwble){
       // handle exceptions here
    }
    Your code becomes simple and almost similar to a concurrent one. ADVICE: Because you have chosen to embrace coroutines, why not look into ktor-client instead of retrofit?? These annotation magic tends to hide some implementations that lead to scenarios like these. You can ask ktor specific questions in the #ktor channel. But if you still want to keep dancing with retrofit, try reading this article, It may give you more guidance.
  • k

    Khanzada Kashif

    08/01/2022, 6:10 AM
    Hey guyz, I am using Realm in my kmm project and performing CRUD operations in shared module, create operation is working fine whenever I add an object it is being added in the file, I have checked it with realm editor but when i try to read all data in the List of objects all the objects get overwritten with the default value of variables, meanwhile the data in the file stays the same. Does anyone know what could be the issue?
    fun getPackedOrders() : List<OrderEntity> = realm.query<OrderEntity>().find()
    this is how I am reading data, I have tried .asFlow() as well.
  • i

    IsaacMart

    08/01/2022, 12:52 PM
    https://kotlinlang.slack.com/archives/CJLTWPH7S/p1659358191988159
    k
    • 2
    • 3
  • c

    coroutinedispatcher

    08/01/2022, 8:57 PM
    https://coroutinedispatcher.com/posts/gradle-convention-plugin/
    l
    • 2
    • 2
  • s

    sundernegi

    08/02/2022, 11:37 AM
    Hello Anyone can help me how to save MP3 file in android/data/package name/files directory
  • a

    ALAN R S

    08/02/2022, 3:11 PM
    👋 Hello, team!
  • k

    kevindmoore

    08/02/2022, 3:59 PM
    Just out of curiosity, are there talks, blogs etc talking about improvements to the whole android build speed. I just got an M1 Mac, 64GB memory and the build process is still slow. Takes over 5 minutes to build for 1 test
    a
    c
    w
    • 4
    • 10
  • r

    raghunandan

    08/03/2022, 11:46 AM
    Is it good to change baseurl just because your server us hosted in a different region. Would love some inputs on whether we can get around by having a single base url for all regions without compromising on latency
  • g

    Gaurav

    08/03/2022, 2:02 PM
    Please Suggest a efficient way of getting last and second last key of a linked hash map other than iterating the map??...Thanx in advance:thank-you:
  • k

    KotlinLeaner

    08/03/2022, 3:15 PM
    Hello, I have string
    val string = "Welcome<br>how are you?"
    when I am trying to regex
    string?.replace("\\<.*?\\>", " ");
    it's not working. It returning same string. Anyone know how to fix this problem?
    c
    r
    • 3
    • 4
  • v

    Vinicius Matheus

    08/03/2022, 4:52 PM
    👋 Hello, team!
    a
    • 2
    • 1
  • r

    Romão

    08/03/2022, 9:15 PM
    I'm learning Android development, trying to do code a simple app in Kotlin. Want to load a JSON file on the assets folder into a string in ViewModel (livedata). Trying to use Moshi,
    val moshi = Moshi.Builder().add(KotlinJsonAdapterFactory()).build()
            val jsonAdapter: JsonAdapter<User> = moshi.adapter(User::class.java)
            val data = AssetManager.open("users.json").bufferedReader().use { it.readText() }
            jsonAdapter.fromJson(data)
    how to read the User.json in the assets folder into a string? then input the string into jsonAdapter.fromJson(string)?
    g
    d
    • 3
    • 3
  • p

    Paul

    08/04/2022, 9:15 PM
    Hey all. Recently I've migrated my open-source app called Gamedge to be a pure Jetpack Compose app. It utilizes all the latest libraries & tools in the Android development world. A couple of thoughts: 🧵 https://github.com/mars885/gamedge
    m
    • 2
    • 7
  • c

    Colton Idle

    08/05/2022, 3:16 AM
    I'm still very much learning about coroutines (and the difference between dispatchers vs threads) but I always found the fact of why viewModelScope.launch uses the main thread by default as an interesting choice. I suppose the answer in this SO question make sense, but does anyone have a more canonical answer as to why main dispatcher is used? https://stackoverflow.com/questions/62166878/why-does-viewmodelscope-launch-run-on-the-main-thread-by-default
    r
    e
    • 3
    • 8
  • l

    Lukasz Kalnik

    08/05/2022, 1:27 PM
    I have a Compose
    ModalBottomSheetLayout
    where the contents is the main screen with a list of items, and the
    sheetContent
    are item details (with different settings). As the item details are quite complex, and don't influence the main screen, I would like to have them in a separate ViewModel. How can I pass the
    itemId
    from the
    MainScreenViewModel
    to the
    ItemDetailsViewModel
    . I don't really fancy creating a shared ViewModel just to pass one value (which is anyway only temporary, as the
    ItemDetailsViewModel
    will store
    itemId
    as well to get the item data).
    i
    • 2
    • 2
  • n

    Nat Strangerweather

    08/06/2022, 9:39 AM
    I have a Kotlin/Compose app which runs well in Android 30 and 31 but crashes with an indexOutOfBoundsException on first install in Android 32 and 33 (on emulators). We've established in the #compose channel that the code is fine (thanks Lukasz). Is this something I should report in the bug tracker? Or is there a known reason why this might be happening?
    s
    • 2
    • 9
  • k

    kk57

    08/06/2022, 10:23 PM
    Hello everyone I created a small video about writing kotlin DSL for Android,

    https://youtu.be/WxBbW6MnqS4▾

  • r

    Regan Russell

    08/07/2022, 1:14 AM
    Hello. Could someone please help me? I am in hell. I have been looking at this kotlin/Java/RxJava/Dagger2/… code for over a week and I am going around in circles.
  • r

    Regan Russell

    08/07/2022, 1:17 AM
    I see ….
    @Inject @Named( something ) Observable<String> someChanges;
    When I try to inject that into a new adapter it is always null. I don’t see any other reference to the variable except
    compositeDisposable.add((Disposable) someChanges ....
    the rest of the code is a mess and its unreadable, unintelligible…
  • r

    Regan Russell

    08/07/2022, 1:25 AM
    My main questions are architectural… I don’t get any of this.
  • r

    Regan Russell

    08/07/2022, 4:35 AM
    I guess my main problem is with Redux
    t
    • 2
    • 1
  • t

    Thomas Urbanitsch

    08/08/2022, 10:32 AM
    First of all: Identify the library that was causing the issue to understand where this is coming from. (e.g. using
    gradle app:dependencies
    ) We had similar troubles with a third party SDK that fixed such a violation in a new version and Google still not approving our new release with that update. Writing an objection to the violation including • the identified root cause • the changes that were made and • proof of the fix (we included apk analyzer reports from before and after the change, showing the namespace being entirely removed) helped in our case.
    a
    • 2
    • 1
  • r

    reactormonk

    08/09/2022, 8:00 AM
    How can I tell android-studio which SDK to use when I tick the "search non-project items"?
  • l

    LopsPower

    08/09/2022, 8:47 AM
    Hi everyone 👋 I just published a new project on GitHub, PokeCardCompose :compose:. It's a demo App 100% write in Compose, Flow and Koin based on MVI Clean Architecture. And because I love Pokémon cards I chose this theme for the demo app 🐱⚡️ Feel free to give me feedback if you see anything to improve 🙏 https://github.com/lopspower/PokeCardCompose
    m
    r
    • 3
    • 2
  • j

    juliocbcotta

    08/10/2022, 3:21 PM
    I am trying to enable
    nonTransitiveRClass
    in my project, but to avoid a bunch of import alias I thought I could encapsulate the R classes from library modules and avoid the class name conflict... How to encapsulate the
    R
    or
    R.string
    class in my class ? I tried this
    object MyR {
        val string: R.string = R.string
    }
    but I get this
    e
    t
    • 3
    • 10
  • i

    Iheme Tobechukwu

    08/10/2022, 7:57 PM
    Hello guys.OK so my moduleA adds ModuleB as a dependency. But this data class is in moduleA. And I'm trying to use it in ModuleB. Doesn't seem to work
    t
    • 2
    • 1
  • r

    Rafiul Islam

    08/10/2022, 9:41 PM
    I want to send some data from the server to users using Firebase Cloud Message and show that data in MainActivity. But my situation is I want to show the data directly in MainActivity without any notification when MainActivity is in the foreground. For all the other cases like when the app is in the background or the app is in the foreground but other activities (Not MainActivity) open, it will show a notification and if I click the notification it will go to MainActivity(this part can be handled by pendingIntent or click_action). But combining both logic seems tricky. Is using BroadcastReceiver a solution? How can I handle this? Any suggestion or link?
Powered by Linen
Title
r

Rafiul Islam

08/10/2022, 9:41 PM
I want to send some data from the server to users using Firebase Cloud Message and show that data in MainActivity. But my situation is I want to show the data directly in MainActivity without any notification when MainActivity is in the foreground. For all the other cases like when the app is in the background or the app is in the foreground but other activities (Not MainActivity) open, it will show a notification and if I click the notification it will go to MainActivity(this part can be handled by pendingIntent or click_action). But combining both logic seems tricky. Is using BroadcastReceiver a solution? How can I handle this? Any suggestion or link?
View count: 11