Class MvpBasePresenter<V extends MvpView>
- java.lang.Object
-
- com.cheetahdigital.uikit.architecture.mvp.MvpBasePresenter<V>
-
- All Implemented Interfaces:
MvpPresenter<V>
public class MvpBasePresenter<V extends MvpView> extends java.lang.Object implements MvpPresenter<V>
A base implementation of aMvpPresenter
that uses a WeakReference for referring to the attached view.You should always check
isViewAttached()
to check if the view is attached to this presenter before callinggetView()
to access the view.- Since:
- 1.0.0
-
-
Constructor Summary
Constructors Constructor Description MvpBasePresenter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
attachView(V view)
Set or attach the view to this presentervoid
detachView(boolean retainInstance)
Will be called if the view has been destroyed.protected V
getView()
Get the attached view.protected boolean
isViewAttached()
Checks if a view is attached to this presenter.
-
-
-
Method Detail
-
attachView
public void attachView(V view)
Description copied from interface:MvpPresenter
Set or attach the view to this presenter- Specified by:
attachView
in interfaceMvpPresenter<V extends MvpView>
- Parameters:
view
- where presenter is attached
-
getView
protected V getView()
Get the attached view. You should always callisViewAttached()
to check if the view is attached to avoid NullPointerExceptions.- Returns:
null
, if view is not attached, otherwise the concrete view instance
-
isViewAttached
protected boolean isViewAttached()
Checks if a view is attached to this presenter. You should always call this method before callinggetView()
to get the view instance.- Returns:
- true if view is attached, else false
-
detachView
public void detachView(boolean retainInstance)
Description copied from interface:MvpPresenter
Will be called if the view has been destroyed. Typically this method will be invoked fromActivity.detachView()
orFragment.onDestroyView()
- Specified by:
detachView
in interfaceMvpPresenter<V extends MvpView>
- Parameters:
retainInstance
- flag used to retain instance
-
-