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-architecture
  • y

    yshrsmz

    05/28/2019, 9:35 AM
    If foo list screen has complete foo data, I'd cache them in memory as a
    Map<ID, Foo>
    , or in SQLite
    1 reply · 1 participant
  • u

    ursus

    05/28/2019, 3:40 PM
    @oday but from the remite foo list screen I already fetched the data, requesting from network again feels wasteful, so yea maybe as to emulate database, keep it in a hashmap as @yshrsmz said but then, when to invalidate this hashmap? and also process death, youd loose the object, so youd need to rerequest the network..
    y
    2 replies · 2 participants
  • a

    amatkivskiy

    05/30/2019, 4:11 AM
    Hi, I am trying to migrate my app architecture (which is basically Clean Architecture based on RxJava) to Clean Architecture based on kotlin coroutines. There is one thing that I am still struggling is coroutines dispatchers. Previously with RxJava it was common to place main thread and background Schedulers in UseCase and then use them when creating Observable. Right now I see that in some cases developers put coroutine dispatchers in UseCase and then triggering coroutine with specific dispatchers. In other cases I saw that UseCase was made basically just a suspend function and all work related to dispatching was moved to the caller of the UseCase. Any ideas what is more correct way to do this?
    s
    o
    +1
    13 replies · 4 participants
  • u

    ursus

    06/01/2019, 5:49 PM
    is there some sane solution other than codegen?
    j
    22 replies · 2 participants
  • u

    ursus

    06/05/2019, 5:58 AM
    How do you guys manage keyboard resizing your screen in a single activity architecture during screen transitions? Basically when one screen has a keyboard opened, then moving to next or previous, that given screen's layout will be resized for a brief second due to the keyboard Very annoying, and looks cheap
    r
    3 replies · 2 participants
  • e

    escodro

    06/07/2019, 12:04 AM
    Now it easier to track AndroidX versions and release notes. 😊 https://developer.android.com/jetpack/androidx/versions
    ❤️ 3
    k
    1 reply · 2 participants
  • z

    zokipirlo

    06/13/2019, 6:15 AM
    Do you guys think that Jetpack Compose will change current architecture patterns or introduce some new?
    g
    e
    10 replies · 3 participants
  • j

    Jan

    06/13/2019, 11:58 AM
    anyone using koin? how do you handle cleaning up? e.g. closing open realm instances on closing app?
    d
    e
    +2
    9 replies · 5 participants
  • m

    Mohamed Ibrahim

    06/19/2019, 9:58 AM
    I have a case where I'm using
    BehaviorRelays
    with viewModel, the problem is in case of the device rotation,
    ViewModel
    subscribe again which cause duplicate subscription with each rotation. I know I could save a subscription with
    Disposable
    and dispose it if it exists, then subscribe .. but is there any other cleaner solution.
    s
    u
    6 replies · 3 participants
  • j

    jonasb

    06/27/2019, 12:17 PM
    Hey! I have some problems wrapping my head around why
    by viewModels()
    (part of Android KTX) requires a viewmodel factory provider as opposed to a viewmodel factory. I.e. I would prefer to be able to write
    val vm by viewModels { MyViewModel(arg1, arg2) }
    . Is there anything I’m missing where making the viewmodel factory as explicit as it is now is of great benefit?
    p
    1 reply · 2 participants
  • j

    Joan Colmenero

    07/04/2019, 9:36 PM
    Hey, I started to work with Room, first time though, and I'm used to use the Repository pattern and it comes from an usecase, the thing is that I always did an api call, so my usecase called a repository that contains my service, but now, first I want to check : if there's internet connection, if there's not, call the repository from room, and if there is internet connection call the repository from service, do I have to put both on the constructor? I mean, how would be the flow? Presenter sends find X --> I have an use case to find it --> I have a repository to get it from there So, the thing is where I have to do the check for internet connection and if it's a or b do some action? Let's say, should be : UI: User type name of the cat UI -> Presenter with the name of the cat Presenter -> Have an use case that it's GetCatUseCase that I have to put a parameter that it's the name GetCatUseCase -> On my old projects I just call the service, but now sometimes I'll have to call the repository from roomdb and other repository from service... Any ideas how to organize it?
    g
    1 reply · 2 participants
  • j

    Joan Colmenero

    07/04/2019, 9:37 PM
    Do I have to have 1 repository and then an interface one method to go to service and other to go to room?
    i
    1 reply · 2 participants
  • u

    ursus

    07/08/2019, 8:39 PM
    R.string is an int, it doesnt change based on localization
    a
    1 reply · 2 participants
  • u

    ursus

    07/09/2019, 6:38 AM
    no I dont, maybe you should look at dependency inversion
    a
    r
    8 replies · 3 participants
  • t

    tschuchort

    07/09/2019, 12:48 PM
    Whether or not R is part of Android framework is totally irrelevant. You have to ask yourself what you are actually trying to achieve with your architecture instead of following arbitrary rules for their own sake. Mostly we are concerned with testability since reusing ViewModels on a different platform never happens anyway. Regardless, I would say that using resources in the ViewModel always warrants a closer look whether you are mixing concerns
    a
    1 reply · 2 participants
  • w

    woodii

    07/11/2019, 1:39 PM
    Hey everyone, currently I am facing an issue with the "new" Navigation Components? Whats the correct way to set different toolbar actions for different fragments while using a single activity. Currently I am using get/set methods in the activity to access the toolbar from each fragment and remove/set the correct menuitems. It works but seems wrong imo. Does anyone have any cleaner ways to solve this?
    p
    u
    3 replies · 3 participants
  • u

    ursus

    07/13/2019, 10:42 PM
    your state data would look like this (1st page list, idle status) (1st page list, started status) (2nd page list, started status) <--- this is a problem (2nd page list, success status)
    f
    a
    +2
    135 replies · 5 participants
  • u

    ursus

    07/20/2019, 4:33 AM
    that feels kind of weird; should I maybe map it? i.e.
    State(val message: List<Message>, ...)
    ->
    ExternalState(val items: List<Item>,...)
    m
    27 replies · 2 participants
  • i

    Ive Vasiljevic

    07/24/2019, 3:30 PM
    Should I make a repository as an
    Object
    or
    Class
    m
    u
    +3
    8 replies · 6 participants
  • u

    ursus

    07/26/2019, 3:49 AM
    Hi, I have a margin item decoration which overrides getItemOffsets and for simplicity lets say adds bottom margin X to every 3rd item, and some smaller X/2 margin to others. So my issue is that without invalidating the item decoration, views keep these margins, and when animation recyclerview via notifyItemInserted and friends (via DiffUtil), it causes wrong margin (not big margin every 3rd item) So I google'd, I need to invalidate like this
    adapter.items = diff.list
    diff.result.dispatchUpdatesTo(adapter)
    recyclerView.invalidateItemDecorations()
    Which does make the margins correct, however this doesn't get calculated into the animations*, and view jump to some incorrect intial position and animate to their end position* Has anyone encountered this? Its very annoying. Do I need to write my own ItemAnimator?
    :google: 1
    e
    2 replies · 2 participants
  • p

    Pablichjenkov

    07/31/2019, 4:17 AM
    Some folks from iOS has been talking for some time about the popularity of MVVM-Coordinator or just Coordinators Architecture in iOS. Has anyone tried a similar approach to tackle navigation logic in Android?
    r
    r
    20 replies · 3 participants
  • m

    Melih Aksoy

    07/31/2019, 1:00 PM
    Hey all ! I’ve recently open sourced an example modularized app - using some of most common libraries, tried to implement cases like structured DI, clean architecture, navigation between features etc. ( you can see modularization graph & DI graph on README ). I’ll be writing about many things I’ve came across and learned during development when I have enough time ! I’m trying to improve it with more cases to cover, not going too fast, but still it’s something. If you have any suggestions, it’d be great hear ! https://github.com/melihaksoy/Android-Kotlin-Modulerized-CleanArchitecture
    👍🏼 2
    👍 10
    a
    m
    6 replies · 3 participants
  • k

    kevin.cianfarini

    08/03/2019, 4:04 PM
    Does anyone know if flow extensions for
    DataSource.Factory
    already exist as a package? If not, is there somewhere that makes sense to contribute them?
    m
    d
    7 replies · 3 participants
  • a

    Adam Hurwitz

    08/06/2019, 6:20 PM
    I'm happy to share the live sample app for the Android Unidirectional Data Flow (UDF) pattern, featuring Coinverse. Code in the wild is always better to learn from than slide samples. Coinverse’s Open App showcases a live UDF pattern which makes the app more readable, easier to develop for, and debug. Next step - JUnit testing the ViewModels! 🧪🔬🥼 https://buff.ly/2T9Yyw3
    ❤️ 2
    👍 3
    m
    2 replies · 2 participants
  • n

    nicopasso

    08/07/2019, 10:09 AM
    We are trying to understand how viewmodels and recyclerviews can work together. In our case we have a custom view, used in an activity, with its own viewmodel. Now this custom view need to be part of the layout of items in a recyclerview. That means each ViewHolder will have a ViewModel attached to it. We think it’s not a good solution but we’re wondering what would it be a way to structure this type of situation. ViewModel attached to the adapter (we think it’s bad)? use DataBinding to connect VH and VM? we don’t have databinding set up in the project though. What do you guys think?
    g
    p
    +1
    11 replies · 4 participants
  • v

    voben

    08/07/2019, 6:48 PM
    What’s the best way to retrieve LiveData value in a click listener? Is it ok to just perform a null check to synchronously get the livedata value?
    button.setOnClickListener {
         if (viewmodel.getMyLiveData().value != null) {
             // do something
         }
    }
    a
    g
    +2
    22 replies · 5 participants
  • m

    Melih Aksoy

    08/08/2019, 12:18 PM
    Hey all ! I was wondering how do you structure your project to apply dependency inversion between modules - it seems to end up in low modules depending on high ones for sake of inversion - but I was wondering if this is correct approach in general, or something else ?
    e
    i
    +2
    13 replies · 5 participants
  • j

    jermainedilao

    08/09/2019, 9:59 AM
    Hi guys! I have a question regarding MVVM. Let’s say I have a ViewPager that has 3 pages and has automatic scrolling feature. (this viewpager goes back to page 1 when reaching page 3). The auto scrolling feature is PAUSED everytime the viewpager receives a touch action. Now, should the logic of setting view pager’s current item to 1 if it reaches 3, and the pausing of auto scroll when view pager receives touch event RESIDE in ViewModel? In my understanding. Purely UI logic can stay in activity/fragment. Logic that can reside in ViewModel can include enabling/disabling buttons (depending on the input), validating inputs, etc. Any inputs are greatly appreciated! 🙂
    a
    u
    2 replies · 3 participants
  • u

    ursus

    08/14/2019, 12:23 AM
    Hi, has anyone tried to automate generating DiffUtil.Callback methods? Mostly `areContentsTheSame`and
    getChangePayload
    ) Say I have a model, the usual case fo areItemsEqual is to use equals(), but what if I dont want to compare all the fields? So, I could write a reflection util / codegen for this, but it requires to have some sort of a @Exclude annotation on a given field *which in turn means that our data/domain layer Foo model knows about diff util stuff so not sure if this is the way to go* should it maybe be manual code and keep reflection (traversing all the fields) unit test to check if new fields are added) (edited) -- or, create a UI layer level model from it, and use just the plain equals from it (or not, doesnt matter, since now diffutil annotations make sense)
    r
    1 reply · 2 participants
  • i

    Ive Vasiljevic

    08/14/2019, 2:14 PM
    How would I combine usage of Android Services and MVVM architecture? Should I start the service inside of my activity/fragment class and inside of View Model class listen when service has been connected? Or should I include repo that starts the service and sends data back to View Model observables ?
    w
    r
    3 replies · 3 participants
Powered by Linen
Title
i

Ive Vasiljevic

08/14/2019, 2:14 PM
How would I combine usage of Android Services and MVVM architecture? Should I start the service inside of my activity/fragment class and inside of View Model class listen when service has been connected? Or should I include repo that starts the service and sends data back to View Model observables ?
w

Will Shelor

08/15/2019, 6:24 PM
We handle the service in the repository layer- if the viewmodel subscribes to our livedata and finds the state to be unititalized, it kicks of the request.
Also, our services expose livedata that can be subscribed to
r

rkeazor

08/18/2019, 2:33 PM
I don't think you need to keep any information about the start the service itself in the ViewModel layer just to maintain the integrity of the service. Just start it in the Activity or fragment. what triggers the start of it can be in the Viewmodel layer
View count: 5