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 aMvpPresenterthat 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 voidattachView(V view)Set or attach the view to this presentervoiddetachView(boolean retainInstance)Will be called if the view has been destroyed.protected VgetView()Get the attached view.protected booleanisViewAttached()Checks if a view is attached to this presenter.
-
-
-
Method Detail
-
attachView
public void attachView(V view)
Description copied from interface:MvpPresenterSet or attach the view to this presenter- Specified by:
attachViewin 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:MvpPresenterWill be called if the view has been destroyed. Typically this method will be invoked fromActivity.detachView()orFragment.onDestroyView()- Specified by:
detachViewin interfaceMvpPresenter<V extends MvpView>- Parameters:
retainInstance- flag used to retain instance
-
-