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

    10/26/2019, 4:07 AM
    This message was deleted.
    t
    m
    +3
    • 6
    • 6
  • d

    Danil Novoselov

    10/26/2019, 10:14 AM
    Hi, guys!! I have got a trouble with our lovely system )) Imagine we have 3 fragments A -> B -> C. I need to go from C -> A using
    fragmentManager.popBackStack()
    . I did not put the B fragment to back stack, so I used
    fragmentTransaction.replace(...).commit()
    . BUT! when use
    fragmentManager.popBackStack()
    on fragment C I go to the fragment A, but fragment C is overdrawn over (or behind I do not understand) fragment A. Do we have a nice solution to manage this situation? I know, that we can use
    popBackStack()
    for specific transaction, but I do need to put fragment B to backstack
    m
    e
    • 3
    • 3
  • k

    Khan

    10/26/2019, 11:08 AM
    Hi guys! I have a question regarding paging component. My structure is something like this: ViewModel -> Datasource -> Repository. I am passing viewModelScope to Datasource and starting coroutine inside DataSource class, which is then calling Repository where actual api call is being made. Its working fine for me. But i wanna know if there is anything wrong with this implementation structure.
    r
    d
    • 3
    • 17
  • a

    Aveepsit Chowdhury

    10/26/2019, 12:09 PM
    Hello everyone, I'm super new to Android and trying to build a App with the mvvm architecture. From the many tutorials on YouTube I could figure out how to use Observerable and LiveData for data from ViewModel to View but how do I send the events of the View to the ViewModel like button clicks?
    r
    p
    • 3
    • 3
  • n

    Nikola Milovic

    10/26/2019, 3:00 PM
    https://hastebin.com/axukizulop.bash DaggerApplicationComp is not found, i tried rebuidling and cleaning the project, I tried a lot of stuff online and nothing has worked Nothing is being generated
    t
    • 2
    • 6
  • s

    SrSouza

    10/26/2019, 5:11 PM
    Hi guys, anyone using Android Studio 4.0 Canary and being able to create a new Vector Asset? For me appears: Nothing to show
    r
    l
    • 3
    • 2
  • s

    Sergio C.

    10/26/2019, 9:22 PM
    I'm trying the new composable functions in AS 4 but where is the preview window? I have no preview window..
    ✔️ 1
    m
    • 2
    • 2
  • j

    J6ey

    10/26/2019, 11:07 PM
    Hi guys is there still a need to use Butterknife in Kotlin? Don't we now have an easier way to bind views i.e., https://kotlinlang.org/docs/tutorials/android-plugin.html#view-binding
    j
    r
    • 3
    • 5
  • m

    Mirza Adil

    10/27/2019, 9:08 AM
    Hi guys, use databinding it is easier and native.
    g
    j
    • 3
    • 2
  • a

    Ayden

    10/27/2019, 9:18 AM
    Hi guys. I have a question here. I have a BaseActivity which has the
    showProgressBar(visibility: Boolean)
    function, this will toggle the ProgressBar visibility based on the value. Then, I have a RecipeListActivity which extends BaseActivity that will send the boolean data type in the
    showProgressBar
    when the button is clicked.
    BaseActivity .kt
    
    fun showProgressBar(visibility: Boolean) {
        progressBar.visibility = if (visibility) View.INVISIBLE else View.VISIBLE
    }
    RecipeListActivity.kt
    
    activity_content.test.setOnClickListener(View.OnClickListener { view ->
        val visibility = view.visibility != View.VISIBLE
        showProgressBar(visibility)
    })
    But right now the value of the visibility in the
    showProgressBar
    is showing
    8
    or
    0
    instead of true or false. Did I miss out anything?
    s
    m
    • 3
    • 5
  • a

    Aslam Hossin

    10/28/2019, 2:19 AM
    At last
    Dagger2
    documentation is published officially https://developer.android.com/training/dependency-injection/dagger-basics
    :yes: 1
    👍 1
    👍🏻 14
    ❤️ 2
    🗡️ 4
    d
    f
    • 3
    • 2
  • v

    voddan

    10/28/2019, 8:36 AM
    Hi everyone! I've stumbled upon this old blog post "Advocating Against Android Fragments" from 2014 which argues that dealing with Fragments is a nightmare and I am better off with custom views for everything. Is this still true in 2019? Did Google do anything to fix this? https://medium.com/square-corner-blog/advocating-against-android-fragments-81fd0b462c97
    j
    m
    +5
    • 8
    • 7
  • b

    Bacho Kurtanidze

    10/28/2019, 9:46 AM
    hey guys, how do you normally handle loading state change, do you create progress bar in view/fragment before executing a network call and hiding it when you get response or do you create a wrapper class like this, setting up LiveData for it in view model and then handling its state change in view
    Untitled
    p
    t
    a
    • 4
    • 3
  • b

    Bacho Kurtanidze

    10/28/2019, 9:56 AM
    thanks for your answer, your approach seems better than mine, thing that drove me to post this question was that i needed to indicate models type even when creating loading and error states while data was null
    t
    f
    • 3
    • 3
  • b

    BigDisgrace

    10/28/2019, 11:50 AM
    Can anyone help me to solve my issue? https://stackoverflow.com/questions/58579715/how-to-pause-play-multiple-mediaplayer-objects-with-one-button
    🇳🇴 1
    g
    m
    k
    • 4
    • 5
  • j

    John

    10/29/2019, 1:35 PM
    Has anyone found a way to force reinitiation of a viewmodel?
    s
    b
    s
    • 4
    • 13
  • v

    vapoyan

    10/29/2019, 2:15 PM
    Mockk
    Hey Guys, In my current application I am using mockito for mocking, currently I want to switch to mockk, so right now I have a lot of code which look like
    verify(loggingService, times(1)).log(any(), any())
    is there a way to write wrapper method which will use mockk verify, so I I will not change all 8900 calls in my project ?
    9️⃣ 2
    🙂 1
    🤔 1
    8️⃣ 2
    0️⃣ 2
    ⭕ 2
    m
    r
    g
    • 4
    • 6
  • k

    Khan

    10/29/2019, 4:02 PM
    Hello. I am using Object{} which has integers which i am passing around and saving those integers in db. Does this approach have any issue? OR should i use IntDef or Enum for this purpose?
    g
    d
    z
    • 4
    • 11
  • l

    Luca Nicoletti

    10/30/2019, 8:47 AM
    Can anyone point me to the source code of the
    Lint
    android provides by default?
    w
    • 2
    • 2
  • s

    Saulnguyen

    10/30/2019, 9:02 AM
    How do you think about jetpack compose. Look good, right ? https://developer.android.com/jetpack/compose
    l
    k
    +2
    • 5
    • 8
  • k

    Kulwinder Singh

    10/30/2019, 11:58 AM
    How i can send constructor variables while using
    viewModels
    ktx extension function ?
    Untitled
    h
    b
    +3
    • 6
    • 11
  • a

    aidanvii

    10/30/2019, 2:42 PM
    To someone more experienced working with Regex patterns. I have a regex pattern that I use to sanitise bad json responses from our backend, replacing empty objects (
    {}
    ) with null, and empty lists (
    []
    ) with null. The pattern is as follows:
    Regex("""\{}|\[]""")
    This compiles and works just fine in a unit test, but on android it crashes with:
    Caused by: java.util.regex.PatternSyntaxException: Syntax error in regexp pattern near index 3
        \{}|\[]
           ^
            at java.util.regex.Pattern.compileImpl(Native Method)
            at java.util.regex.Pattern.compile(Pattern.java:1344)
            at java.util.regex.Pattern.<init>(Pattern.java:1328)
            at java.util.regex.Pattern.compile(Pattern.java:950)
            at kotlin.text.Regex.<init>(Regex.kt:89)
    All I can surmise from this is that the underlying native implementation on Android is different.
    r
    • 2
    • 6
  • t

    theopaintsil

    10/30/2019, 4:19 PM
    is anybody else having issues with ButterKnife?
    🇳🇴 4
    c
    g
    +2
    • 5
    • 17
  • a

    am414

    10/30/2019, 8:01 PM
    thanks in advance https://kotlinlang.slack.com/archives/C0B8Y8BHC/p1572465499006700
    j
    m
    • 3
    • 5
  • a

    Anastasia Finogenova

    10/30/2019, 10:04 PM
    It was mentioned, I believe multiple times , including in the what is new in AS
    t
    • 2
    • 1
  • a

    Anastasia Finogenova

    10/30/2019, 10:05 PM
    I don't think that anyone promoted it as a better version of databinding more as a lite version
    r
    • 2
    • 1
  • a

    Anastasia Finogenova

    10/30/2019, 10:23 PM
    They didn't tell more at this one it seemed but maybe you will find something additional. I think you got it. I am not a googler but I talked to Yigit about it at the last IO and he told me that they don't want people to face issues that finidViewById entails but at the same time not everyone wants to go all the way databinding cause it could be an overhead and it seems too complex. And when they looked at how people use databinding they realized that many don't use expressions or custom adapters but just access views and that's how they decided to give people view binding as a type safe and not that complex way to serve that purpose. And also eliminate the need for 3 party libraries like ButterKnife.
    👍 1
    r
    j
    • 3
    • 4
  • s

    Somesh

    10/31/2019, 6:15 AM
    Hello Guys, I am having hard time figuring out how I can connect my
    Repository
    and `ViewModel`'s livedata in-case of
    @GET
    request and observe them in fragment. I don't have this problem when the request type is
    @POST
    because I can use
    Transformation.switchMap
    on body and whenever the body changes repository's function gets invoked and emit value to the response live data something like this
    val matchSetsDetail: LiveData<Resource<MatchDetailBean>> = Transformations.switchMap(matchIdLiveData) { matchId ->
            val body = MatchSetRequest(matchId)
            repository.getMatchSet(body)
        }
    but in case of
    @GET
    request I have several query parameter the my View supplies I have this retrofit API call in repository class and the code looks like this
    fun checkInCheckOutUser(apiKey: String, userId: Int, status: String, latitude: Double, longitude: Double, checkedOn: Long): LiveData<Resource<BaseResponse>> = liveData {
            emit(Resource.Loading())
            try {
                val response: Response<BaseResponse> = ApiClient.coachApi.checkInCheckOutUser(apiKey, userId, status, latitude, longitude, checkedOn)
                if (response.isSuccessful && response.body() != null) {
                    if (response.body()!!.isValidKey && response.body()!!.success) {
                        emit(Resource.Success(response.body()!!))
                    } else {
                        emit(Resource.Failure(response.body()!!.message))
                    }
                } else {
                    emit(Resource.Failure())
                }
            } catch (e: Exception) {
                emit(Resource.Failure())
            }
        }
    and
    ViewModel
    class CheckInMapViewModel : ViewModel() {
        val checkInResponse: LiveData<Resource<BaseResponse>> = MutableLiveData()
    
        fun checkInCheckOut(apiKey: String, userId: Int, status: String, latitude: Double, longitude: Double, checkedOn: Long): LiveData<Resource<BaseResponse>>  {
            return repository.checkInCheckOutUser(apiKey,userId,status,latitude,longitude,checkedOn)
        }
    }
    Main problem is I want to observe
    checkInResponse
    but don't know how to pass repository's livedata same as I did with my post request above using
    Transformations.switchMap
    . Can anyone help me with this case?
    p
    k
    b
    • 4
    • 7
  • j

    James

    10/31/2019, 9:14 AM
    https://stackoverflow.com/questions/58588775/using-android-library-in-kotlin-multiplatform-library
    r
    d
    • 3
    • 2
  • h

    haroldadmin

    10/31/2019, 7:32 PM
    How do I exclude a property in a data class from being Parcelized?
    @Parcelize
    data class State(
      val userId: String = 1234,
      val userResource: Resource<User> = Resource.Uninitialized
    ): Parcelable
    I want to exclude the
    userResource
    property from being Parcelized, as the
    Resource
    class is not Parcelable. Here is the warning I get from the IDE:
    Type is not directly supported by @Parcelize. Annotate the field with @RawValue if you want to be serialized using 'writeValue()'
    @Transient
    does not work, and neither does
    @IgnoreOnParcel
    (I get the warning that it is not applicable on properties in primary constructor). Any way to solve this?
    n
    r
    • 3
    • 6
Powered by Linen
Title
h

haroldadmin

10/31/2019, 7:32 PM
How do I exclude a property in a data class from being Parcelized?
@Parcelize
data class State(
  val userId: String = 1234,
  val userResource: Resource<User> = Resource.Uninitialized
): Parcelable
I want to exclude the
userResource
property from being Parcelized, as the
Resource
class is not Parcelable. Here is the warning I get from the IDE:
Type is not directly supported by @Parcelize. Annotate the field with @RawValue if you want to be serialized using 'writeValue()'
@Transient
does not work, and neither does
@IgnoreOnParcel
(I get the warning that it is not applicable on properties in primary constructor). Any way to solve this?
n

nglauber

10/31/2019, 7:47 PM
Have you tried remove this property from the primary constructor?
h

haroldadmin

10/31/2019, 8:02 PM
That works, but it requires me to create a secondary constructor. All the parcelable properties go in the primary constructor, and the un-parcelable ones go in the secondary constructor. However this involves a dealbreaker: we can not have `val`s in secondary constructors. So the only solution is to do something like this:
@Parcelize
data class State(
  val userId: Int = 1234
): Parcelable {
  private lateinit var resource: Resource<User>
  constructor(missionId: Int, userRes: Resource<User>) {
    this.resource = userRes
  }
}
This, of course is not great because I lose immutability (resource is now a var). Also, the auto-generated copy function does not accept secondary constructor params.
n

nglauber

10/31/2019, 8:23 PM
yeah… you’re right… 😞 maybe you can wrap your class and just serialize the internal props that you want… 🤷‍♂️
r

rkeazor

11/01/2019, 12:13 PM
a simple way would just the factor pattern
factory pattery
or the secondary constructor ,would just call the primary constructor. or don't use the @Parcerlize annotation , and just override everything manually
View count: 39