Created
January 31, 2020 23:44
-
-
Save omayib/1b36b34552a71331047b13f3d9772f5f to your computer and use it in GitHub Desktop.
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 ProfileActivity: GaragePresenter.Contract.OnLoadCarSucceed { | |
lateinit var garagePresenter : GaragePresenter; | |
fun onCreate(){ | |
garagePresenter = GaragePresenter() | |
garagePresenter.setOnLoadCarSucceedListener(this) | |
garagePresenter.loadTheCars() // we just only need this function on this page | |
} | |
override fun onLoadSucceed() { | |
println("ProfileActivity : on load succeed") | |
} | |
} | |
class GarageActivity : GaragePresenter.Contract.OnLoadCarSucceed, GaragePresenter.Contract.OnAddCarSucceed, | |
GaragePresenter.Contract.OnDeleteCarSucceed, GaragePresenter.Contract.OnFailure { | |
lateinit var garagePresenter : GaragePresenter; | |
fun onCreate(){ | |
garagePresenter = GaragePresenter() | |
garagePresenter.setOnLoadCarSucceedListener(this) | |
garagePresenter.setOnAddCarSucceedListener(this) | |
garagePresenter.setOnDeleteCarSucceedListener(this) | |
garagePresenter.setOnFailureListener(this) | |
garagePresenter.loadTheCars() | |
garagePresenter.deleteTheCars() | |
garagePresenter.addTheCar() | |
garagePresenter.otherCase() | |
} | |
override fun onLoadSucceed() { | |
println("GarageActivity : on load succeed") | |
} | |
override fun onDeleteSucceed() { | |
println("GarageActivity : on delete succeed") | |
} | |
override fun onAddSucceed() { | |
println("GarageActivity : on add succeed") | |
} | |
override fun onFailure() { | |
println("GarageActivity : on something failure happen") | |
} | |
} | |
class GaragePresenter{ | |
private lateinit var viewOnLoadCarSucceed: Contract.OnLoadCarSucceed | |
private lateinit var viewOnAddCarSucceed: Contract.OnAddCarSucceed | |
private lateinit var viewDeleteCarSucceed: Contract.OnDeleteCarSucceed | |
private lateinit var viewonFailure: Contract.OnFailure | |
fun setOnLoadCarSucceedListener(listener:Contract.OnLoadCarSucceed){ | |
this.viewOnLoadCarSucceed = listener | |
} | |
fun setOnAddCarSucceedListener(listener: Contract.OnAddCarSucceed){ | |
this.viewOnAddCarSucceed = listener | |
} | |
fun setOnDeleteCarSucceedListener(listener: Contract.OnDeleteCarSucceed){ | |
this.viewDeleteCarSucceed = listener | |
} | |
fun setOnFailureListener(listener:Contract.OnFailure){ | |
this.viewonFailure = listener | |
} | |
fun loadTheCars(){ | |
//do some logic here and finally trigger the succeed callback | |
this.viewOnLoadCarSucceed.onLoadSucceed() | |
} | |
fun deleteTheCars(){ | |
//do some logic here and finally trigger the succeed callback | |
this.viewDeleteCarSucceed.onDeleteSucceed() | |
} | |
fun addTheCar(){ | |
//do some logic here and finally trigger the succeed callback | |
this.viewOnAddCarSucceed.onAddSucceed() | |
} | |
fun otherCase(){ | |
//do some logic here but it was wrong and finally trigger the failure callback | |
this.viewonFailure.onFailure() | |
} | |
interface Contract{ | |
interface OnLoadCarSucceed { | |
fun onLoadSucceed() | |
} | |
interface OnDeleteCarSucceed { | |
fun onDeleteSucceed() | |
} | |
interface OnAddCarSucceed{ | |
fun onAddSucceed() | |
} | |
interface OnFailure{ | |
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