Class MvpBasePresenter<V extends MvpView>

  • All Implemented Interfaces:
    MvpPresenter<V>

    public class MvpBasePresenter<V extends MvpView>
    extends java.lang.Object
    implements MvpPresenter<V>
    A base implementation of a MvpPresenter 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 calling getView() to access the view.

    Since:
    1.0.0
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void attachView​(V view)
      Set or attach the view to this presenter
      void 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • MvpBasePresenter

        public MvpBasePresenter()
    • 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 interface MvpPresenter<V extends MvpView>
        Parameters:
        view - where presenter is attached
      • getView

        protected V getView()
        Get the attached view. You should always call isViewAttached() 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 calling getView() 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 from Activity.detachView() or Fragment.onDestroyView()
        Specified by:
        detachView in interface MvpPresenter<V extends MvpView>
        Parameters:
        retainInstance - flag used to retain instance