Skip to content

Instantly share code, notes, and snippets.

@omayib
Created January 31, 2020 23:44
Show Gist options
  • Save omayib/2af8431383d5c2d6e6cdf8dbcdc62bbf to your computer and use it in GitHub Desktop.
Save omayib/2af8431383d5c2d6e6cdf8dbcdc62bbf to your computer and use it in GitHub Desktop.
class ProfileActivity: GaragePresenter.Contract.View {
lateinit var garagePresenter : GaragePresenter;
fun onCreate(){
garagePresenter = GaragePresenter(this)
garagePresenter.loadTheCars() // we just only need this function on this page
}
override fun onDeleteSucceed() {
// tidak dipakai,dirty code, sia-sia!
}
override fun onAddSucceed() {
// tidak dipakai,dirty code, sia-sia!
}
override fun onFailure() {
// tidak dipakai,dirty code, sia-sia!
}
override fun onLoadSucceed() {
println("first.solution.ProfileActivity : on load succeed")
}
}
class GarageActivity: GaragePresenter.Contract.View {
lateinit var garagePresenter : GaragePresenter;
fun onCreate(){
garagePresenter = GaragePresenter(this)
garagePresenter.loadTheCars()
garagePresenter.deleteTheCars()
garagePresenter.addTheCar()
garagePresenter.otherCase()
}
override fun onLoadSucceed() {
println("first.solution.GarageActivity : on load succeed")
}
override fun onDeleteSucceed() {
println("first.solution.GarageActivity : on delete succeed")
}
override fun onAddSucceed() {
println("first.solution.GarageActivity : on add succeed")
}
override fun onFailure() {
println("first.solution.GarageActivity : on something failure happen")
}
}
class GaragePresenter{
lateinit var view: Contract.View
constructor(view: Contract.View) {
this.view = view
}
fun loadTheCars(){
//do some logic here and finally trigger the succeed callback
this.view.onLoadSucceed()
}
fun deleteTheCars(){
//do some logic here and finally trigger the succeed callback
this.view.onDeleteSucceed()
}
fun addTheCar(){
//do some logic here and finally trigger the succeed callback
this.view.onAddSucceed()
}
fun otherCase(){
//do some logic here but it was wrong and finally trigger the failure callback
this.view.onFailure()
}
interface Contract{
interface View{
fun onLoadSucceed()
fun onDeleteSucceed()
fun onAddSucceed()
fun onFailure()
}
}
}
fun main() {
var loginActivity = ProfileActivity()
loginActivity.onCreate()
var garageActivity = GarageActivity()
garageActivity.onCreate()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment