首页 » Andorid » 临时分类 » 正文

SimpleKotlinMvpBoilerplate

SimpleKotlinMvpBoilerplate

Presentation of simple Kotlin Android MVP

This project is presentation and boilerplaye of simple MVP for Kotlin. Simplest presentation Activity:

class MainActivity : PresenterBaseActivity(), MainView {

    override val presenter: Presenter by lazy { MainPresenter(this) }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
    }
}

It is implementing view interface that is empty in this case. PresenterBaseActivity is taking care of calling Presenter onStart, onResume, onStop and onDestroy. Here is simplest presenter:

class MainPresenter(val view: MainView): Presenter() {
}

Now, let's show some more complex example. Here is really simple Activity where parcelable is proveded through argument. It is later presented on screen Presenter. This behavior is really easy to unit test.

Also full Login with error checks is presented. Node that even this complex behavior is easy to unit test. Both preference and network can be easly mocked.

下载 (0)

发表评论