https://kotlinlang.org logo
#android
Title
# android
m

morozov

06/20/2017, 9:01 AM
In this code i need to write
return true
My function:
Copy code
override fun onBackPressed(): Boolean {
        if (amountCalculator?.visible ?: false)
            amountCalculator?.let { it.toggle(presenter.goal.amount) }
        else if (initialBalanceCalculator?.visible ?: false)
            initialBalanceCalculator?.let { it.toggle(presenter.goal.initialBalance) }
        else return false
        return true
    }
😲 2
s

scott

06/20/2017, 3:21 PM
morozov: why all the nullable types? are those views? they can be lateinit var, or delegate lazy bind references
s

scott

06/21/2017, 3:43 PM
right. so is that a presenter class? if so you shouldn't be referencing the views directly, but calling through an interface for normal MVP.
m

morozov

06/21/2017, 3:48 PM
nope this method i used in my fragment.
s

scott

06/21/2017, 3:50 PM
so if you are handling back in your fragment, that's cool. but then why are the views nullable?
why not use lateinit var or a delegate
even !! null assertion is better if you are positive that when back button is clicked those views exist.
although it's probobly best to use a val someView by bindViewDelegate(R.id.someview)
or lateinit