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

    frankelot

    06/17/2021, 11:28 PM
    reposting this here 🙂 hope it doesn’t come across as spam
    w
    • 2
    • 2
  • n

    Napa Ram

    06/18/2021, 9:50 AM
    Hi Everyone is ViewModel support to Kotlin Multi-platform if not how i can create my own VIewModel Please share if anyone is having good reference
    p
    • 2
    • 1
  • f

    FunkyMuse

    06/25/2021, 6:00 PM
    Hey guys I have library: serverurls Which has productFlavors local,dev,prod The server URLs are in the gradle file I want to include those in the :networking module of mine and in the : app But when i do implementation project (path: ':serverurls') I can't seem to get it to work
    g
    • 2
    • 2
  • k

    KV

    06/28/2021, 7:57 AM
    Hi guys, I am using pagination library for fetch the data from the API call, and got to know that my API calls are made 3 times, with page number: 1 , 2 , 3 With Page Number 1 -> I got success response - which is correct behaviour. But does anyone know why page number 2 and 3 triggers (which is failure)?
    private const val STARTING_PAGE_INDEX = 1
    
    class AbsencePagingDataSource(
        private val apiProvider: ApiProvider,
        private val absenceDataMapper: AbsenceDataMapper,
        private val workspaceId: String
    ) :
        PagingSource<Int, AbsenceData>() {
        lateinit var response: ListApiResponse<WorkspaceAbsenceResponse>
    
        override suspend fun load(params: LoadParams<Int>): LoadResult<Int, AbsenceData> {
            val position = params.key ?: STARTING_PAGE_INDEX
    
            val request = Endpoint.GetWorkspaceAbsence(
                workspaceId = workspaceId,
                Queries = listOf(
                    Queries.Paginate(position, 50),   -------> SEE URL BELOW
                )
            )
            return try {
                apiProvider.api.performRequest<ListApiResponse<WorkspaceAbsenceResponse>>(request).map { listApiResponse ->
                    response = listApiResponse
                }
                val endOfPaginationReached = response.data.isEmpty()
    
                LoadResult.Page(
                    data = absenceDataMapper.mapToDomain(response),
                    prevKey = if (position == STARTING_PAGE_INDEX) null else position - 1,
                    nextKey = if (endOfPaginationReached) null else position + 1
                )
            } catch (exception: IOException) {
                LoadResult.Error(exception)
            }
        }
    
        override fun getRefreshKey(state: PagingState<Int, AbsenceData>): Int? {
            return state.anchorPosition?.let { anchorPosition ->
                state.closestPageToPosition(anchorPosition)?.prevKey?.plus(1)
                    ?: state.closestPageToPosition(anchorPosition)?.nextKey?.minus(1)
            }
        }
    }
    
    URL/request looks like -> 
    ---------------------------
    1. url=<https://PATH/api/v3/workspaces/120/absences?page=1&items=50> ----> 200
    2. url=<https://PATH/api/v3/workspaces/120/absences?page=2&items=50> ----> 422
    3. url=<https://PATH/api/v3/workspaces/120/absences?page=3&items=50> ----> 422
    s
    • 2
    • 23
  • s

    suhas

    07/14/2021, 12:05 PM
    Do you guys use service layer in MVP?
    ✅ 1
    m
    j
    • 3
    • 6
  • c

    Cicero

    07/21/2021, 12:15 PM
    I came here to cry a little bit about interfaces.
    m
    • 2
    • 5
  • g

    gzhenjin

    07/22/2021, 9:16 AM
    • Can someone please explain to me the advantages and necessity of mvi ?
    👀 1
    m
    h
    • 3
    • 8
  • a

    Aaron Waller

    07/25/2021, 3:56 PM
    Anyone else facing problems with dagger-hilt version 2.38 and Gradle 7.1.0-alpha03? Since I upgraded from hilt 2.28 to 2.38 the field injection stopped working and I get the following error message:
    lateinit property analytics has not been initialized
    e
    c
    f
    • 4
    • 4
  • v

    Vyshas

    07/25/2021, 3:58 PM
    Navigation across dynamic feature modules: Navigation from a fragment in one dynamic feature module to a fragment nested in another onDemand dynamic feature module.. this cannot be done using deeplinks for sure and neither the document mentioned here(https://developer.android.com/guide/navigation/navigation-multi-module) mentions about this... What is the best way to achieve navigation in these scenarios ?
    s
    • 2
    • 1
  • a

    Alexander Suraphel

    08/07/2021, 3:20 PM
    Which MVI library are you using?
    m
    f
    c
    • 4
    • 8
  • m

    Mohamed Ibrahim

    08/10/2021, 12:31 PM
    I’m using Navigation component and, I have logout menu option in toolbar, when clicking it, it should navigate to login fragment .. clicking back button return to the previous [loggedin screen]
    r
    c
    • 3
    • 2
  • o

    oday

    08/10/2021, 3:18 PM
    does anyone have experience building the networks requests layer with RxJava and without Retrofit?
    e
    z
    • 3
    • 9
  • k

    K Merle

    08/14/2021, 5:46 PM
    Do you use
    core
    package in your apps and what do you usually put in core package?
    j
    • 2
    • 3
  • u

    ursus

    08/21/2021, 10:47 PM
    Do you guys bundle your own sqlite? (to keep control of version, etc)
    🤔 1
    g
    • 2
    • 3
  • s

    suhas

    08/22/2021, 10:13 AM
    Working on a very small project. Don't plan to add DI for now. Is it okay to pass
    context
    to Presenter in MVP?
    u
    g
    +2
    • 5
    • 5
  • w

    Will Shelor

    08/24/2021, 1:52 AM
    for those of you who debounce user interactions, do you do so at the View layer or at the ViewModel layer?
    o
    • 2
    • 1
  • d

    Dhaval Gondaliya

    08/24/2021, 7:16 AM
    Hello, I am using bottomnavigationview and drawer together, I got problem with humburger icon. When app is started and i click on humburger icon it is not opening drawer. But if i slide it from left side and close it, humburger icon will start working after that. I have attached video of this bug too.
    device-2021-08-24-124215.mp4
    • 1
    • 1
  • u

    ursus

    08/25/2021, 10:23 PM
    impossible right? Other than breaking Foo apart into composition of the 3 object which provide a(), b(), c(); and then when using ComposedFoo just include those as well and stick my method where I need. Which is annoying since lets say a, b, c are few lines, not worth extracting like that; and not even sure what the names would be, annoying...
    w
    • 2
    • 4
  • s

    Smorg

    08/26/2021, 8:23 AM
    Hi, any ideas which flow constructs could produce the following behaviour: • keeps its latest value (as
    StateFlow
    behaves), but once that value is consumed, it no longer has any value (until it receives another and the cycle continues).
    d
    s
    m
    • 4
    • 9
  • c

    Chuck Stein

    08/31/2021, 8:38 PM
    What are the advantages of having a stateless class injected via Dagger/Hilt which houses methods that operate on input data according to business logic, vs just using a file with top-level functions for this purpose? I have an app which recommends albums to listen to from your library based on your current mood. To do this recommendation, is there any downside to just passing the data set to pick from along with the mood parameters into top-level functions? Why use a class/object if it holds no state?
    a
    • 2
    • 7
  • c

    Cicero

    09/06/2021, 12:31 PM
    Hey, how do you make proper distribution of your data layer objects and why wouldn't you do something like this (code in the thread)
    u
    • 2
    • 9
  • s

    Slackbot

    09/11/2021, 1:32 AM
    This message was deleted.
    :yes: 1
    b
    • 2
    • 1
  • v

    Viktor Petrovski

    09/16/2021, 3:37 PM
    Hello 👋 I’m working on some sample project testing things and I wondered how would you guys approach the following pretty common scenario: We have a Feed of posts and a post detail screen that can be open from the feed. We can also like the post, when we like the post from post detail when we go back we also want to update the feed for the post we’ve liked. If we are not using Realm or any DB what would your approach be?
    a
    • 2
    • 2
  • b

    Brian Donovan

    09/18/2021, 3:51 PM
    can I get some better understanding on what viewModelFactory does please. ty
    :not-kotlin: 1
    👍 1
    v
    m
    • 3
    • 3
  • t

    theapache64

    10/05/2021, 12:25 PM
    ❓ Is MVVM with single activity a suited architecture for leanback based tv apps? More details in the thread 🧵
    f
    • 2
    • 3
  • u

    ursus

    10/06/2021, 11:04 PM
    Do you use semantic versioning for apps? If so, what would constitute a major change? Unless there is some big redesign, shall I never move to 2.x? 😄 I kind of like year prefix + order of release in year. 21.1, 21.2 etc
    e
    g
    • 3
    • 4
  • t

    teddy

    10/09/2021, 3:46 AM
    I wonder which one of these 3 technologies like Hilt, Dagger 2 and Koin will a company prefer a candidate to implement for take home assignment of an android dev interview ? Or it depends on the company that use which tech will ask their candidates to use that one? Which one of those 3 is popular these days? I am gonna have an interview next months, so please anyone know any good material can suggest me to study? Thanks a lot!
    w
    k
    +2
    • 5
    • 4
  • m

    martinsumera

    10/13/2021, 10:12 AM
    Hi, I’m trying to create an application with the following requirements: • Multi module application • The core module loads some data and decides what kind of feature modules should be shown to the user • The core module is able to load a view (Component) from the feature module and show it as some kind of in-app widget in the core module • In-app widget has its own logic which is hidden from core module and needs to be defined in the feature module • Feature modules should be able to be launched as a standalone application • Feature modules should be developed independently so they should have their own 3rd party library initialization, it’s own DI mechanism, it’s own architecture etc. • The core module, featured modules and standalone feature app module should be able to use some shared logic (login, notifications, network, computations … ) I’m thinking about the following architecture. I can’t decide if I should use dynamic modules or library modules for core module <-> feature module communication. I’ve created a dummy project with both approaches: • The library module works fine (but this will prohibit me from using dynamic modules feature in the future) • The dynamic module loads in-app widgets via reflection (it works so far but I’m stuck on the issues with DI in in-app widgets (link)) Which approach do you think is better for such project? Do you see any other possible issues that could arise from the following architecture?
    🤔 1
    👍 1
    b
    • 2
    • 1
  • e

    Emiliano Schiavone

    10/13/2021, 11:58 AM
    Hello, Im working on a MVI implementation and I want to know how I can structure my State. I though on a simple data class like (val isLoading, val content, val error, etc) and also for a sealed class like State { Loading, Error, Content, Idle }. I like the sealed class approach but i do not know how I can access to previous state. any idea or a better approach for sealed class for State
    o
    m
    • 3
    • 19
  • d

    Diego

    10/28/2021, 12:36 PM
    Hi guys. I'm working on a trading app. I need to list the user stocks and their value (profit or loss) among with the total value of the portfolio. For the holdings list, in an MVP architecture I would create a presenter for each list item but for this app I decided to use MVVM (Compose, ViewModels and Hilt ). My first idea was to create a different ViewModel for each list item. When using MVVM architecture, is what I'm trying to do the correct way or I should use a single ViewModel? Are you aware about any project I could have a look at? The image below is a super simplification of my actual screen, each cell complex and that's why I wanted to use a different ViewModel for each cell. Any suggestion is very welcome.
    u
    • 2
    • 3
Powered by Linen
Title
d

Diego

10/28/2021, 12:36 PM
Hi guys. I'm working on a trading app. I need to list the user stocks and their value (profit or loss) among with the total value of the portfolio. For the holdings list, in an MVP architecture I would create a presenter for each list item but for this app I decided to use MVVM (Compose, ViewModels and Hilt ). My first idea was to create a different ViewModel for each list item. When using MVVM architecture, is what I'm trying to do the correct way or I should use a single ViewModel? Are you aware about any project I could have a look at? The image below is a super simplification of my actual screen, each cell complex and that's why I wanted to use a different ViewModel for each cell. Any suggestion is very welcome.
u

undermark5

10/28/2021, 8:54 PM
If the views are presenting different types of information, they should probably have different viewmodels, if they are presenting the same type of information just in a different way they should probably use the same viewmodel. The purpose of the viewmodel is essentially to provide the backing data presented in the UI as well as to bridge UI interactions to modify said data.
So, in the sample provided above, I’d probably use the same viewmodel for all of those items.
Hopefully understanding what the purpose of the viewmodel is will help you understand how you should implement it. Basically, narrow it down to what data is needed to be able to render the view, in this case, we need which holdings a user has, and the value of each of those holdings. So actually, in theory you could actually just use one viewmodel for this entire screen and it not be a violation of any design principles (at least I’m not aware of any violations in doing that), or, you can make use of recylerview similar and then each item would have its own copy of a viewmodel with the data it specifically needs (type of holding, and value) and that would also not be a violation of design principles and allow you to reuse the individual components (compose style)
👍 2
View count: 6