V - type of the MvpViewpublic class MvpBasePresenter<V extends MvpView>
extends java.lang.Object
MvpPresenter that uses a WeakReference for referring
to the attached view.
Use ifViewAttached(ViewAction) to interact with the view. Since the view is passive,
usually a Presenter should not get any data from View: so calls like view.getUserId() should not be done.
Rather write a method in your Presenter that takes the user id as parameter like this:
void doSomething(int userId){
// do something
...
ifViewAttached( view -> view.showSuccessful())
}
| Modifier and Type | Class and Description |
|---|---|
static interface |
MvpBasePresenter.ViewAction<V>
An Action that is executed to interact with the view.
|
| Constructor and Description |
|---|
MvpBasePresenter() |
| Modifier and Type | Method and Description |
|---|---|
void |
attachView(V view) |
void |
destroy() |
void |
detachView() |
void |
detachView(boolean retainInstance)
Deprecated.
|
V |
getView()
Deprecated.
|
protected void |
ifViewAttached(boolean exceptionIfViewNotAttached,
MvpBasePresenter.ViewAction<V> action)
Executes the passed Action only if the View is attached.
|
protected void |
ifViewAttached(MvpBasePresenter.ViewAction<V> action)
Calls
ifViewAttached(boolean, ViewAction) with false as first parameter (don't throw
exception if view not attached). |
boolean |
isViewAttached()
Deprecated.
|
public void attachView(V view)
@Deprecated public V getView()
ifViewAttached(ViewAction)isViewAttached() to check if the view
is attached to avoid NullPointerExceptions.null, if view is not attached, otherwise the concrete view instance@Deprecated public boolean isViewAttached()
ifViewAttached(ViewAction)getView() to get the view instance.@Deprecated public void detachView(boolean retainInstance)
protected final void ifViewAttached(boolean exceptionIfViewNotAttached,
MvpBasePresenter.ViewAction<V> action)
exceptionIfViewNotAttached - true, if an exception should be thrown if no view is
attached while trying to execute the action. false, if no exception should be thrown (the action
will not be executed since no view is attached)action - The MvpBasePresenter.ViewAction that will be executed if a view is attached. This is
where you call view.isLoading etc. Use the view reference passed as parameter to MvpBasePresenter.ViewAction.run(Object) and not deprecated method getView()protected final void ifViewAttached(MvpBasePresenter.ViewAction<V> action)
ifViewAttached(boolean, ViewAction) with false as first parameter (don't throw
exception if view not attached).ifViewAttached(boolean, ViewAction)public void detachView()
public void destroy()