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

    amar_1995

    08/23/2020, 8:23 AM
    What is recommended way to check user token expiry ? I want to check token expiry by calling server api(using retrofit) and If token expired then move to login screen from any activity or fragment.
    j
    • 2
    • 1
  • j

    John Leeroy

    08/24/2020, 2:25 AM
    What are :android: folks' thoughts on having a high-level representation of navigation in the domain layer? I think it's an implementation concern and should stay in the presentation layer but I want to hear your thoughts and experiences.
    o
    • 2
    • 1
  • u

    ursus

    08/25/2020, 12:25 AM
    Has anybody by change got app links working with custom url scheme? (The feature which identifies a link as "yours" and will not show a disambiguation dialog) -- but doesnt seem to work with custom schemes
    g
    b
    • 3
    • 13
  • u

    ursus

    08/29/2020, 12:03 AM
    Do you keep separate settings.gradle around as not to build all the modules?
    g
    • 2
    • 5
  • m

    Mohamed Ibrahim

    08/31/2020, 10:30 AM
    should I use
    buildSrc
    or convert all
    .gradle
    files to Kotlin dsl, preparing to refactor app to Modules?
    j
    v
    • 3
    • 13
  • u

    ursus

    09/02/2020, 8:37 AM
    But I presume when prefs sync to disc, they have to rewrite the whole thing even though a single value changed, right?
    j
    • 2
    • 3
  • d

    Daniele Segato

    09/03/2020, 2:25 PM
    is it possible for a feature module to depend on another feature module?
    :yes: 2
    a
    • 2
    • 12
  • r

    Rodri Represa

    09/08/2020, 1:55 PM
    Hey guys, I'm in doubt with Retrofit and coroutines. If I have a livedata which is returning my favourites films from and API and I observe this livedata and show the films in the screen. If I add a new film in my favourites, is the livedata going to emit this new film? Do I need to call the API again?
    k
    u
    • 3
    • 2
  • s

    stantronic

    09/09/2020, 10:43 AM
    Hallo guys, wondering about the pros and cons of doing the following:
    class Activity(val delegate = ScreenDelegate()): AppCompatActivity(), Screen by delegate {
    ...methods
    }
    m
    • 2
    • 11
  • k

    KayCee

    09/10/2020, 8:54 AM
    I am trying to apply the following function but it doesn't work is there anyone give a hint why: • In the time I receive notification on onReceive of broadcast receiver I call a function in a viewmodel (which is injected into my broadcast receiver) to set aLiveData.value = newValue. However, nothing happened in my fragment. • Then I try to use a local broadcast receiver: in my broadcast receiver on receive I sendBroadcast after notication came in, register it in fragment but it didn't work too. • The last option can be use update database in the time I get notification then observe it in my fragment, but I need to implement the dao, use case and so on I might be an overkill? I still want to figure out why the first 2 options don't work.
    f
    a
    g
    • 4
    • 6
  • u

    ursus

    09/23/2020, 2:23 PM
    btw have anyone ever used gradle flavors to swap string resources like app name? the issue is I have 3 flavor dimensions, and want to AND 1st and 3rd, and it doesnt seem to work, only if I add the 2nd inbetween, however then I multiply it by all 2nd dimension's values which is stupid, I must be missing something
    j
    • 2
    • 12
  • n

    Nick

    10/01/2020, 2:22 PM
    We have a custom view that is used in a lot of places. We want to tie this to a viewmodel and keep all the business logic there. A coworker suggested just passing in the ViewModel and lifecycle owner to the custom view and then observe on the properties. This doesn’t feel right. What do you guys do?
    s
    a
    +3
    • 6
    • 25
  • c

    Christopher Elías

    10/02/2020, 1:42 PM
    Hello you all 🙋‍♂️, What do you think about this approach? On an Android project with a modularization per feature architecture, would you create a retrofit instance per each feature? Isn't this very costly? My friends and I are currently working on this kind of architecture, and we are in the stage of integrate the REST API. We are trying to isolate as much as we can every feature. But should we create a retrofit instance on each feature module that needs to call a service or should we have another module let's say "data" and handle all the retrofit thing there? What would you do?
    2️⃣ 1
    f
    • 2
    • 2
  • n

    Nick

    10/02/2020, 9:37 PM
    Is this any better than having using the backing property that we usually see? This is way has one less property to instantiate so would that make this more memory efficent?
    protected val titleLiveData = MutableLiveData<String>()
        
        fun getTitleLiveData(): LiveData<String> {
              return titleLivaData
        }
    • 1
    • 2
  • u

    ursus

    10/02/2020, 10:56 PM
    Hi, with dagger multibinding, is there a way to default to empty set if non are found? Now it throws an error
    g
    • 2
    • 9
  • f

    Florina

    10/07/2020, 8:52 AM
    👋 This is where all the architecture fans and foes gather, right? Our guide to app architecture is more than 3 years old and it’s time to recommend up to date architecture best practices. But we can’t do this without input from ... well, you! If you want to help, start by filling out this survey! Then, some people that opt in to provide even more feedback will be selected to be part of small focus groups that can help us dive deeper into architecture best practices. 🙏 Thank you for helping us improve the Android app architecture! https://docs.google.com/forms/d/e/1FAIpQLSfe-rHdqRF8sznJvj0Jyq-ttoS41aGZLEoP38G0_xQVVy162Q/viewform
    👍 3
    ✅ 2
    👏 12
    a
    b
    s
    • 4
    • 6
  • j

    Joan Colmenero

    10/09/2020, 7:46 AM
    What do you think in a project multi-module have for instance app core(or whatever) feature1 feature2 feature3 navigation <-- I'm planning to implement navigation to a multi-module project and is it a good praxis to create a navigation module which is included on each feature and inside of it contains all of the navigation between features?
    a
    s
    • 3
    • 7
  • p

    Pablo

    10/14/2020, 9:15 AM
    Good morning I have a question regarding architecture, I have a multi-module project and I'm wondering how can I split the network module, I mean I don't want to create a difference instance of Retrofit everytime so do you know an efficient way to use the same instance of Retrofit if possible but changing the service? And also is ok to create the network module and inside of it every service? Or every service we should create inside the feature module? Because the problem is about the models. Anyone of you have worked with something similar? Thanks.
    g
    j
    • 3
    • 8
  • f

    Florian

    10/15/2020, 2:49 PM
    does the logic in the observe method belong into the ViewModel?
    :yes: 3
    s
    o
    +2
    • 5
    • 23
  • u

    ursus

    10/18/2020, 5:09 AM
    Firebase then groups all of these ApiExceptions to one entry in the web UI, im guessing because the line that throws is the same 😔 Then I have to click through the instances of the crash where I now do see various 400 or 500's ... but im 90% sure its not all and just some "smart" agregate How can I "hack" the crashlytics to see these as separate exceptions (rows), so I can see actually all of these?
    w
    • 2
    • 2
  • j

    Joost Klitsie

    10/21/2020, 12:56 PM
    hi all! I am making some home-made application where I use a data flow like: Repository <-> UseCase <-> ViewModel <-> View So basically UseCase with MVVM I can find some basic introductions about the usecase pattern, but does anyone have some in-depth article/repo example? I am looking for information about things like this: • Things like observing data (should I first fetch data and after that observe on it, within the useCase) • when to fire a use case and for specific things (like would you fire a usecase to validate input while typing, or only while submitting?) • Should I observe fields from a usecase, or only the output from the execution? • What are the rules where to put specific logic, in the view model or usecase (or both)?
    j
    • 2
    • 1
  • f

    Florian

    10/21/2020, 1:33 PM
    when you use
    LiveData<Resource<T>>
    , doesn't the fragment have to make too many decisions? I.e. what to do for each result
    j
    • 2
    • 6
  • f

    Florian

    10/23/2020, 8:11 AM
    Should the fragment or the ViewModel decide when to show this snackbar? My LoginFragment pops itself from the backstack when the user is logged in:
    mainViewModel.sessionManager.firebaseUser.observe(viewLifecycleOwner) {
                if (it != null) {
                    previousSavedStateHandle.set(LOGIN_SUCCESSFUL, true)
                    binding.editTextEmail.clearFocus()
                    binding.editTextPassword.clearFocus()
                    findNavController().popBackStack()
                }
            }
    The login method in the ViewModel looks like this:
    fun login(email: String, password: String) {
            if (email.isEmpty() || password.isEmpty()) {
                viewModelScope.launch {
                    snackBarMessage.send("Please fill out all fields")
                }
                return
            }
    
            viewModelScope.launch {
                _loginLoading.value = true
                when (val result = authRepository.login(email, password)) {
                    is AsyncResult.Success -> {
                        val firebaseUser = sessionManager.firebaseUser.value!!
                        snackBarMessage.send("Logged in as ${firebaseUser.displayName}")
                    }
                    is AsyncResult.Error -> snackBarMessage.send(
                        result.throwable.localizedMessage ?: "Something went wrong"
                    )
                }
                _loginLoading.value = false
            }
        }
    My question is about that confirmation snackbar (
    "Logged in as ${firebaseUser.displayName}"
    ). Does the code that triggers the snackbar belong into the when statement inside the ViewModel (where it is right now), or can/should I put it into the
    if (it != null)
    block inside the fragment? I'm asking this because the latter option would get rid of the problem that the snackbar doesn't arrive early enough before the fragment is popped from the backstack. But I am not sure if showing a snackbar is considered "business logic" here and should be in the ViewModel. (The snackbar event is send via a Kotlin channel here that the fragment reacts to)
    j
    f
    • 3
    • 22
  • s

    Simon Lin

    10/23/2020, 9:25 AM
    If I would like to call api when Fragment onPause. Is it the case to use
    GlobalScope.launch
    ?
    // Fragment
    
    override fun onPause() {
        viewModel.leave()
    }
    // ViewModel
    
    fun leave() {
        GlobalScope.launch {
            repository.leave() 
        }
    }
    e
    • 2
    • 3
  • f

    Florian

    10/24/2020, 4:56 PM
    What the next step architecture-wise when methods in my repository become big and complex? Should I just keep it like this in the repository?
    u
    o
    n
    • 4
    • 23
  • f

    Florian

    10/27/2020, 9:15 AM
    I have this
    ItemTouchHelper
    in a Fragment. Is it okay to show the snackbar here directly or should the ViewModel trigger it via an event?
    ItemTouchHelper(object :
                    ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT or ItemTouchHelper.RIGHT) {
                    override fun onMove(
                        recyclerView: RecyclerView,
                        viewHolder: RecyclerView.ViewHolder,
                        target: RecyclerView.ViewHolder
                    ): Boolean {
                        return false
                    }
    
                    override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) {
                        val task = taskAdapter.currentList[viewHolder.adapterPosition]
                        viewModel.deleteTask(task)
    
                        Snackbar.make(requireView(), "Task deleted", Snackbar.LENGTH_LONG)
                            .setAction("UNDO") {
                                viewModel.insertTask(task)
                            }
                            .show()
                    }
                }).attachToRecyclerView(recyclerViewTasks)
    n
    c
    • 3
    • 6
  • t

    TheDukerChip

    10/28/2020, 5:44 AM
    How to hold the reference of the binding object in an activity? This is how we are handling
    private lateinit var binding: FragmentGardenBinding
    Sometimes when activity is resumed, I'm getting the following crash and it's unable to reproduce
    lateinit property binding has not been initialized
    f
    • 2
    • 3
  • r

    Rim Gazzah

    11/02/2020, 2:37 PM
    Just published a blog post about MVI architecture with android using kotlin with a github simple repo as well, constructive feedbacks are welcome 😃 : https://rimgazzeh.medium.com/mvi-architecture-with-android-fcde123e3c4a
    🙌 1
    👍 5
    p
    g
    +2
    • 5
    • 5
  • b

    Brady Aiello

    11/18/2020, 3:14 AM
    Does anyone here still use MVP? If so, do you use databinding or LiveData? And what are your reasons for using MVP?
    n
    j
    • 3
    • 5
  • u

    ursus

    11/22/2020, 2:22 AM
    Hi, I have code like this
    fun <T> get(klass: Class<T>): T = store.getOrNull(klass) ?: error("No such component '$klass' found")
    issue is my release builds are obviously proguarded, so the exception logs obviously read "No such component 'ndsjadnjka.dqw.DWQ' found" Is there a sane way around it other than whitelisting component classes to not have them renamed (which might or not be a security issue)? Maybe somehow leverage firebase crashlytics already knowing the proguard mappings?
    t
    • 2
    • 3
Powered by Linen
Title
u

ursus

11/22/2020, 2:22 AM
Hi, I have code like this
fun <T> get(klass: Class<T>): T = store.getOrNull(klass) ?: error("No such component '$klass' found")
issue is my release builds are obviously proguarded, so the exception logs obviously read "No such component 'ndsjadnjka.dqw.DWQ' found" Is there a sane way around it other than whitelisting component classes to not have them renamed (which might or not be a security issue)? Maybe somehow leverage firebase crashlytics already knowing the proguard mappings?
t

Tom Hermann

11/23/2020, 5:58 PM
You could use Proguard’s
keepnames
if it is important that value be human readable. You could switch your store to work in terms of strings, and just pass the literal name of the store you want access to. e.g.
store.get("users")
You may be able to deobfuscate using the mapping file, see: https://www.guardsquare.com/en/products/proguard/manual/retrace I would opt for passing a literal string if you don’t want to fight classname obfuscation. I generally avoid using classnames for tags, logging, caching, etc unless I’m only doing it transiently within the scope of my process.
u

ursus

11/25/2020, 8:05 PM
hm but then I need to map strings to classes right?
t

Tom Hermann

11/30/2020, 3:48 PM
Back in the day I would just have a public static final string in classes called TAG or something like that, so UserInputFragment.TAG would be the string “userInputFragment”. It’s not elegant, but you are in control of it.
View count: 4