Skip to content

Instantly share code, notes, and snippets.

@whalemare
Created May 27, 2017 09:42
Show Gist options
  • Save whalemare/8477f07c66504cdafc2e4bbe519b8aff to your computer and use it in GitHub Desktop.
Save whalemare/8477f07c66504cdafc2e4bbe519b8aff to your computer and use it in GitHub Desktop.
MvpPresenter, Kotlin: how avoid check isViewAttached()
package ru.whalemare.vkbirthday.mvp.presenter.base
import com.hannesdorfmann.mosby.mvp.MvpBasePresenter
import com.hannesdorfmann.mosby.mvp.MvpView
/**
* @since 2017
* @author Anton Vlasov - whalemare
*/
open class BaseMvpPresenterK<V : MvpView> : MvpBasePresenter<V>() {
fun isActive(body: (v: V) -> Unit) {
if (isViewAttached) {
body(view!!)
}
}
}
/**
* @since 2017
* @author Anton Vlasov - whalemare
*/
class NoteMakerPresenterImpl : BaseMvpPresenterK<NoteMakerView>(), NoteMakerPresenter {
override fun onClickNoteView() {
isActive { it.showKeyboard() }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment