Skip to content

Instantly share code, notes, and snippets.

@Dssdiego
Last active April 1, 2020 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dssdiego/1f04ab62868f38b9414cc33d99baaf44 to your computer and use it in GitHub Desktop.
Save Dssdiego/1f04ab62868f38b9414cc33d99baaf44 to your computer and use it in GitHub Desktop.
MVC Pattern Android (Kotlin)
class Activity : AppCompatActivity(), Controller.View {
private val controller: Controller = Controller()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_login)
controller.attachView(this)
}
override fun onDestroy() {
controller.detachView()
super.onDestroy()
}
}
abstract class BaseController<V> {
protected var view: V? = null
fun attachView(view: V) {
this.view = view
}
fun detachView() {
this.view = null
}
}
class Controller : BaseController<Controller.View>() {
// TODO: Implementar aqui os métodos que serão executados aqui no Controller
interface View {
// TODO: Implementar aqui os métodos que serão executados na View
// fun showLoading()
// fun showError()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment