mercredi 3 avril 2019

How to extend all views with my BasePresenter

Im working on a project and doing mvp on it, now, I have a BaseActivity for all my Activities and a BasePresenter that works with the view of the Activity I'm in, this is done to attach, ditach and know wherever my view is null or not while working with my presenter.

Now, this is working fine for my first view with this

abstract class BasePresenter<T : LoginContract.View> : Presenter<T> {

    private var mMvpView: T? = null

    val isViewAttached: Boolean
        get() = mMvpView != null

    override fun attachView(view: T) {
        mMvpView = view
    }

    override fun detachView() {
        mMvpView = null
    }
}

And in my presenter , I'm calling it like this

class LoginPresenter: BasePresenter<LoginContract.View>(), LoginContract.Presenter {

....

But now , I'm creating a new presenter that is called RegisterPresenter and when I use BasePresenter<> to extend my class with the presenter, it asks to put LoginContract.View in there.

I know that because is coded this way here

abstract class BasePresenter<T : LoginContract.View> : Presenter<T> {
...

But I wonder if there is an approach where I can extend multiple views like this

abstract class BasePresenter<T : multipleViews> : Presenter<T> {

Aucun commentaire:

Enregistrer un commentaire