In this code i need to write `return true` My func...
# android
m
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
morozov: why all the nullable types? are those views? they can be lateinit var, or delegate lazy bind references
s
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
nope this method i used in my fragment.
s
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