Skip to content

Commit

Permalink
added setRetainInstance()
Browse files Browse the repository at this point in the history
  • Loading branch information
sockeqwe committed Sep 1, 2015
1 parent 7004658 commit 14f360e
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public abstract class MvpActivity<V extends MvpView, P extends MvpPresenter<V>>

protected ActivityMvpDelegate mvpDelegate;
protected P presenter;
protected boolean retainInstance;

@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -128,7 +129,11 @@ public abstract class MvpActivity<V extends MvpView, P extends MvpPresenter<V>>
}

@Override public boolean isRetainingInstance() {
return false;
return retainInstance && isChangingConfigurations();
}

@Override public void setRetainInstance(boolean retainInstance) {
this.retainInstance = retainInstance;
}

@Override public Object onRetainNonMosbyCustomNonConfigurationInstance() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@
/**
* The MvpDelegate callback that will be called from {@link
* FragmentMvpDelegate} or {@link ViewGroupMvpDelegate}. This interface must be implemented by all
* Fragment or android.view.View that you want to support mosbys mvp. Please note that Activties need a special callback {@link ActivityMvpDelegateCallback}
* Fragment or android.view.View that you want to support mosbys mvp. Please note that Activties
* need a special callback {@link ActivityMvpDelegateCallback}
*
* @param <V> The type of {@link MvpView}
* @param <P> The type of {@link MvpPresenter}
* @author Hannes Dorfmann
* @since 1.1.0
* @see ActivityMvpDelegateCallback
* @since 1.1.0
*/
public interface BaseMvpDelegateCallback<V extends MvpView, P extends MvpPresenter<V>> {

Expand Down Expand Up @@ -71,4 +72,13 @@ public interface BaseMvpDelegateCallback<V extends MvpView, P extends MvpPresent
* @return true if the view is retaining, hence the presenter should be retaining as well.
*/
public boolean isRetainingInstance();

/**
* Mark this instance as retaining. This means that the feature of a retaining instance is
* enabled.
*
* @param retainingInstance true if retaining instance feature is enabled, otherwise false
* @see #isRetainingInstance()
*/
public void setRetainInstance(boolean retainingInstance);
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,8 @@ public MvpFrameLayout(Context context, AttributeSet attrs, int defStyleAttr, int
@Override public boolean isRetainingInstance() {
return false;
}

@Override public void setRetainInstance(boolean retainingInstance) {
throw new UnsupportedOperationException("Retainining Instance is not supported / implemented yet");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,9 @@ public MvpLinearLayout(Context context, AttributeSet attrs, int defStyleAttr, in
@Override public boolean isRetainingInstance() {
return false;
}


@Override public void setRetainInstance(boolean retainingInstance) {
throw new UnsupportedOperationException("Retainining Instance is not supported / implemented yet");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,9 @@ public MvpRelativeLayout(Context context, AttributeSet attrs, int defStyleAttr,
@Override public boolean isRetainingInstance() {
return false;
}

@Override public void setRetainInstance(boolean retainingInstance) {
throw new UnsupportedOperationException(
"Retainining Instance is not supported / implemented yet");
}
}

0 comments on commit 14f360e

Please sign in to comment.