Created
August 17, 2018 17:00
-
-
Save folkyatina/42ed9375a2095435a6e9f595aa92e646 to your computer and use it in GitHub Desktop.
Super simple MVP for Android + Navigator as an example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.songsterr.mvp | |
import android.arch.lifecycle.ViewModel | |
// Immutable view state | |
interface ViewState | |
interface View<in S: ViewState> { | |
fun render(state: S) {} | |
} | |
abstract class Presenter< S: ViewState, V: View<S>>(protected var state: S): ViewModel() { | |
var view: V? = null | |
fun takeView(view: V) { | |
this.view = view | |
view.render(state) | |
} | |
fun dropView() { | |
this.view = null | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment