Last active
April 1, 2020 14:32
-
-
Save Dssdiego/1f04ab62868f38b9414cc33d99baaf44 to your computer and use it in GitHub Desktop.
MVC Pattern Android (Kotlin)
This file contains hidden or 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
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() | |
} | |
} |
This file contains hidden or 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
abstract class BaseController<V> { | |
protected var view: V? = null | |
fun attachView(view: V) { | |
this.view = view | |
} | |
fun detachView() { | |
this.view = null | |
} | |
} |
This file contains hidden or 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
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