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

    리오

    08/05/2019, 9:45 PM
    I am trying to disable a login button if username edittext is empty. In LoginViewModel, there is a live data for username
    val username = MutableLiveData<String>()
    . In the xml, the edit text is defined as:
    <com.google.android.material.textfield.TextInputEditText
                    android:id="@+id/username"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:ems="10"
                    android:hint="@string/username_or_email"
                    android:inputType="textPersonName"
                    android:text="@={loginViewModel.username}" />
    The login button is defined as:
    <Button
                android:id="@+id/login"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="65dp"
                android:enabled="@{loginViewModel.loginButtonEnabled}"
                android:onClick="@{() -> loginViewModel.onLogin()}"
                android:text="@string/login"
                app:layout_constraintEnd_toEndOf="@+id/password_text_input_layout"
                app:layout_constraintTop_toBottomOf="@+id/password_text_input_layout" />
    The
    loginButtonEnabled
    is a variable in the LoginViewModel.
    val loginButtonEnabled = Transformations.map(username) {
            null != it
        }
    a
    • 2
    • 1
  • u

    리오

    08/05/2019, 9:46 PM
    So far, the button is always disabled no matter what the username edittext value is. Should I be using a onchanged listener instead?
    w
    m
    g
    • 4
    • 13
  • m

    morozov

    08/06/2019, 1:19 PM
    Hello guys, who can help with ktlint? I try to add my custom ruleset who can take the time?
    w
    t
    • 3
    • 22
  • s

    samp

    08/07/2019, 6:33 AM
    Why android test stripped out kotlin classes?
    k
    • 2
    • 1
  • v

    Vishal

    08/07/2019, 6:49 AM
    I'm new to kotlin, and created a sample Multiplatform application(common code will be shared between Android and IOS) using https://kotlinlang.org/docs/tutorials/native/mpp-ios-android.html#creating-an-android-project reference. Everything is working fine except
    bin
    folder is not getting generated in `SharedCode/build`folder i rebuild the project, and was getting jar for andorid but not getting
    SharedCode/build/bin/iOS/main/debug/framework/SharedCode.framewor
    only these folders are getting generated, see attached image.
    k
    • 2
    • 1
  • a

    Alex Davidyuk

    08/07/2019, 4:43 PM
    I have a ImageButton with a drawable shape as the background. The shape has a solid android:color="someColor". I'm wondering how I could animate the color with a breathing/puslating effect so that it beckons the user to tap on the button? Anybody have ideas? I've look around on multiple stack overflow approaches, but they're quite dated and I couldn't translate the Java code presented to the proper Kotlin. Any help would be appreaciated!
    v
    g
    m
    • 4
    • 5
  • j

    jw

    08/07/2019, 5:17 PM
    it gets removed by kotlinc/javac because it's a compile-time constant
    👍 4
    t
    • 2
    • 2
  • p

    Paul Dhaliwal

    08/07/2019, 8:13 PM
    In a lot of cases on android calls like this come up
    ContextCompat.getColor(context, color.colorPrimaryDark)
    which gives the error “type mismatch Required Context, Found Context?” I can get around this error by using “context as Context” or “context!!“, however these don’t feel like the right approaches. The Kotlin doc says !! is for “NPE-lovers” which I am not lol. What’s the best way to handle these situations? I’m still new to Kotlin and development in general and don’t want to develop any bad habits. Thanks!
    j
    a
    a
    • 4
    • 7
  • s

    scottiedog45

    08/08/2019, 1:20 AM
    how does a ViewModel provider (something like
    singleLargeTextInputViewModel = ViewModelProviders.of(this, SingleLargeInputViewModel.FACTORY(NetworkService())).get(
                SingleLargeInputViewModel::class.java
            )
    ) “know” (????) that a view model already exists? Or would it?
    a
    • 2
    • 3
  • m

    myanmarking

    08/08/2019, 9:07 AM
    i guess this will work:
    ZoneId.of(timeZone.id)
    ☝️ 1
    d
    • 2
    • 1
  • b

    Branimir Conjar

    08/08/2019, 3:29 PM
    I have the following code:
    arguments?.getString(FORCED_EMAIL).let {
          binding.etEmail.setText(it)
          binding.etEmail.isFocusable = false
          binding.etEmail.isEnabled = false
        }
    getString()
    returns null. Anyone has an idea why this goes through and executes statements inside let?
    j
    • 2
    • 1
  • t

    TheDukerChip

    08/09/2019, 4:31 AM
    Does anyone know where to file a bug for
    androidx.biometric
    ?
    d
    l
    • 3
    • 2
  • j

    jermainedilao

    08/09/2019, 10:01 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!
    m
    i
    +2
    • 5
    • 6
  • g

    Gunslingor

    08/11/2019, 3:25 PM
    Any idea's why this font isn't wrapping correctly?
    k
    a
    +2
    • 5
    • 20
  • h

    henrikhorbovyi

    08/12/2019, 4:06 PM
    Hey guys... Is it a bad practice to leave
    logs
    on the code (with the purpose of future debug)?
    c
    k
    j
    • 4
    • 22
  • s

    Simon Schubert

    08/12/2019, 4:14 PM
    Usually one of the first things I create in a new android project is a L class. Which makes logging easier and also prevents logs to go into a non-debug versions
    object L {
    
        private const val TAG = "FOOBAR"
    
        fun e(log: String) {
            if (BuildConfig.DEBUG) {
                Log.e(TAG, log)
            }
        }
        ...
    }
    h
    t
    +2
    • 5
    • 18
  • m

    Marc Knaup

    08/12/2019, 9:15 PM
    So, for coroutines there’s that nice
    val myData = liveData { … }
    extension. How can I achieve the same with
    MutableLiveData
    ? There is no
    mutableLiveData { … }
    . 1. Load document from DB using a coroutine upon activation (
    onActive
    ). 2. Update view model when Fragment requests changes & save them to DB (also using a coroutine).
    d
    l
    +3
    • 6
    • 35
  • i

    ivano

    08/13/2019, 12:04 PM
    @Parcelize
    class RemoteDeclarationRepository : DeclarationRepositoryInterface {
    
        private val declareService: ProActiveDeclareApi
            get() = Api()
    
        override fun getDeclarations(periodId: Int, offset: Int, limit: Int): Single<DeclarationsResponse> {
            return declareService.getDeclarations(periodId, offset, limit)
        }
    
        override fun getDeclarationPeriod(id: Int): Single<DeclarationPeriod> {
            return declareService.getPeriod(id).map { it.data }
        }       //and so on 50 times almost
    a
    a
    • 3
    • 6
  • m

    Marc Knaup

    08/13/2019, 12:15 PM
    Question regarding coroutines vs. Android lifecycle: Saving to & loading data from a database should not happen on the main thread, hence using coroutines are great for that. Now let’s say I have an activity and save data in
    onPause
    or
    onStop
    , e.g. in case the user switches to another application. The launched coroutine’s scope however cannot be bound to the activity’s lifecycle because the save operation may not have finished by the time the activity gets destroyed. Even worse the whole app may be destroyed or hibernated because there are no activities left, which would abort the save operation. How would I model that properly? • The most simple solution I can think of is to block the main thread on
    onStop
    and wait for the coroutine to complete. But that’s somewhat counter-productive 🤔 OTOH that would ensure that if the user switches to another activity they’d not risk seeing stale data because the save hasn’t completed yet. • Another solution could be a long-running service for any kind of database I/O but that seems unnecessarily complex (and may even need a foreground service?).
    i
    l
    +2
    • 5
    • 83
  • p

    Pablichjenkov

    08/13/2019, 8:14 PM
    Is out there any Retrofit CallAdapter that returns
    Flow<T>
    . Is it a bad design?
    j
    g
    • 3
    • 14
  • a

    arekolek

    08/14/2019, 6:29 AM
    Anybody usining
    @Parcelize
    got rid of this lint error?
    a
    e
    +2
    • 5
    • 11
  • a

    alex.tavella

    08/14/2019, 5:12 PM
    Do you guys think
    @VisibleForTesting
    a bad practice for unit testing internals of a component?
    d
    m
    +3
    • 6
    • 11
  • m

    Mohamed Hamdan

    08/14/2019, 8:31 PM
    Hi all, A while ago there was someone asking about eventbus libraries and all answers were about not using any kind of eventbus libraries, I want to know what should we use instead of eventbus libraries.
    j
    j
    +7
    • 10
    • 21
  • r

    raghuramjampala

    08/15/2019, 2:25 PM
    Hi all, I have created an internal view which should only be used in the module where it is created, but I can see it in xml in the other module which has the dependency (It is hidden from kotlin but visible from XML). How Do I make it hidden from the other module’s xml as well?
    a
    c
    • 3
    • 9
  • j

    jmfayard

    08/15/2019, 4:13 PM
    Would someone be nice enough to proof-read this article?
    Better dependency management in Android Studio 3.5 with Gradle buildSrcVersions
    https://dev.to/jmfayard/new-in-android-studio-3-5-dependency-management-with-gradle-buildsrcversions-22ia-temp-slug-2042205?preview=373ea29273e40c80e4579a999bbc305e8246511e13d599564be52fba5f20607b13305942fd8c4855b5e1807a66249612df27e19193a563106eb8d275 I will publish once Android Studio 3.5 is released (should be real soon now)
    c
    l
    • 3
    • 8
  • u

    리오

    08/15/2019, 8:39 PM
    Can fragments itself host bottom navigation? I got it to work on activity class but I can't seem to implement it inside the fragments. The reason for wanting to add the bottom navigation to the fragment is because I want to build a single activity application. I actually created a stackoverflow question, and the post has more information about the code https://stackoverflow.com/questions/57514369/how-to-add-bottom-navigation-listeners-to-fragments. Any input suggestion is welcome 😊 thx.
    a
    m
    • 3
    • 4
  • y

    Yuri

    08/15/2019, 11:10 PM
    Hey guys, I’m trying to migrate RxJava code dealing with SharedPreferences to Kotlin Flow. How correct migration should look like?
    private val keyChangesObservable: Observable<String>
    
      init {
        keyChangesObservable = io.reactivex.Observable.create(ObservableOnSubscribe<String> { emitter ->
          val listener = SharedPreferences.OnSharedPreferenceChangeListener { _, key -> emitter.onNext(key) }
          emitter.setCancellable { prefs.unregisterOnSharedPreferenceChangeListener(listener) }
          prefs.registerOnSharedPreferenceChangeListener(listener)
        }).share()
      }
    g
    l
    e
    • 4
    • 4
  • p

    Paul Dhaliwal

    08/16/2019, 12:06 AM
    I've created a line chart by making a custom view. I want to be able to animate the line in the chart and the axis lines and value labels seperately. Does this require creating a custom viewgroup which contains custom views for the plotted line, axis lines, and value labels seperately? Or is it better to do this all in one custom view? As an example of how I'd like to be able to control animations I'm looking at the Google Fit App, which has custom animations for the different elements in its graphs. Thanks!!
    p
    • 2
    • 3
  • k

    Kulwinder Singh

    08/16/2019, 6:08 AM
    Hi, What is best way to detect "No Internet connection" using Retrofit + Coroutines, currently i have added interceptor
    private val realInterceptor = Interceptor { chain ->
            if (!NetworkConnection.getInstance().isConnected) {
                throw NoInternetException()
            }
    	/..../
        }
    but to work with this i have to add
    try/catch
    block on every request, there are so many requests. Below is sample of how i'm handling each network request->
    val response = apiService.getItems().toNetworkResult()
            when (response) {
                is NetworkResult.Success -> onDataLoaded(response.data)
                is NetworkResult.Error -> toast(response.errorCode)
            }
    and this is how
    toNetworkResult
    looks like
    fun <T : Any> Response<T>.toNetworkResult(): NetworkResult<T> {
        val response = this
        if (response.isSuccessful)
            return NetworkResult.Success(response.body()!!)
    
        val error = GsonUtils.toObject<ErrorResponse>(response.errorBody()!!.string())
        return NetworkResult.Error(response.code(), error)
    }
    I just want to know if it is possible to handle it inside
    toNetworkResult()
    or any other similar solution i can implement, where i don't have to add
    try/catch
    on every request
    g
    l
    +2
    • 5
    • 16
  • z

    Zaraki596

    08/16/2019, 12:33 PM
    https://stackoverflow.com/questions/57458511/how-do-i-achieve-on-scroll-behavior-where-both-the-toolbar-and-bottom-navigation
    g
    • 2
    • 1
Powered by Linen
Title
z

Zaraki596

08/16/2019, 12:33 PM
https://stackoverflow.com/questions/57458511/how-do-i-achieve-on-scroll-behavior-where-both-the-toolbar-and-bottom-navigation
g

gildor

08/16/2019, 12:57 PM
This is not related to Kotlin, please check channel topic
View count: 5