use of com.hannesdorfmann.mosby3.mvp.viewstate.ViewState in project mosby by sockeqwe.
the class ActivityMvpViewStateDelegateImpl method onPostCreate.
@Override
public void onPostCreate(Bundle bundle) {
super.onPostCreate(bundle);
if (mosbyViewId != null) {
VS viewState = PresenterManager.getViewState(activity, mosbyViewId);
if (viewState != null) {
//
// ViewState restored from PresenterManager
//
setViewState(viewState, true, true);
if (DEBUG) {
Log.d(DEBUG_TAG, "ViewState reused from Mosby internal cache for view: " + delegateCallback.getMvpView() + " viewState: " + viewState);
}
return;
}
}
VS viewState = delegateCallback.createViewState();
if (viewState == null) {
throw new NullPointerException("ViewState returned from createViewState() is null! MvpView that has returned null as ViewState is: " + delegateCallback.getMvpView());
}
if (bundle != null && viewState instanceof RestorableViewState) {
// A little bit hacky that we need an instance of the viewstate to restore a view state
// (may creates another view state object) but I don't know any better way :)
RestorableViewState restoredViewState = ((RestorableViewState) viewState).restoreInstanceState(bundle);
if (restoredViewState != null) {
//
// ViewState restored from bundle
//
viewState = (VS) restoredViewState;
setViewState(viewState, true, false);
if (keepPresenterInstance) {
if (mosbyViewId == null) {
throw new IllegalStateException("The (internal) Mosby View id is null although bundle is not null. This should never happen. This seems to be a Mosby internal error. Please report this issue at https://github.com/sockeqwe/mosby/issues");
}
PresenterManager.putViewState(activity, mosbyViewId, viewState);
}
if (DEBUG) {
Log.d(DEBUG_TAG, "Recreated ViewState from bundle for view: " + delegateCallback.getMvpView() + " viewState: " + viewState);
}
return;
}
}
//
if (keepPresenterInstance) {
if (mosbyViewId == null) {
throw new IllegalStateException("The (internal) Mosby View id is null. This should never happen. This seems to be a Mosby internal error. Please report this issue at https://github.com/sockeqwe/mosby/issues");
}
PresenterManager.putViewState(activity, mosbyViewId, viewState);
}
setViewState(viewState, false, false);
if (DEBUG) {
Log.d(DEBUG_TAG, "Created a new ViewState instance for view: " + delegateCallback.getMvpView() + " viewState: " + viewState);
}
delegateCallback.onNewViewStateInstance();
}
use of com.hannesdorfmann.mosby3.mvp.viewstate.ViewState in project mosby by sockeqwe.
the class ViewGroupMvpViewStateDelegateImpl method onSaveInstanceState.
/**
* Must be called from {@link View#onSaveInstanceState()}
*/
@Override
public Parcelable onSaveInstanceState() {
VS viewState = delegateCallback.getViewState();
if (viewState == null) {
throw new NullPointerException("ViewState returned from getViewState() is null for MvpView " + delegateCallback.getMvpView());
}
Parcelable superState = delegateCallback.superOnSaveInstanceState();
if (keepPresenter) {
if (viewState instanceof RestorableParcelableViewState) {
return new MosbyViewStateSavedState(superState, mosbyViewId, (RestorableParcelableViewState) viewState);
}
return new MosbyViewStateSavedState(superState, mosbyViewId, null);
} else {
return superState;
}
}
use of com.hannesdorfmann.mosby3.mvp.viewstate.ViewState in project mosby by sockeqwe.
the class ActivityMvpViewStateDelegateImplTestNew method dontKeepPresenterAndViewState.
@Test
public void dontKeepPresenterAndViewState() {
ActivityMvpViewStateDelegateImpl<MvpView, MvpPresenter<MvpView>, ViewState<MvpView>> delegate = new ActivityMvpViewStateDelegateImpl<>(activity, callback, false);
startActivity(delegate, null, 1, 1, 1, 1, 1, 0, null, 0, 1, 0);
Bundle bundle = BundleMocker.create();
finishActivity(delegate, bundle, false, 1, true, false);
startActivity(delegate, bundle, 2, 2, 2, 2, 2, 0, null, 0, 2, 0);
finishActivity(delegate, bundle, false, 2, false, true);
}
use of com.hannesdorfmann.mosby3.mvp.viewstate.ViewState in project mosby by sockeqwe.
the class ActivityMvpViewStateDelegateImplTestNew method appStartFinishing.
@Test
public void appStartFinishing() {
ActivityMvpViewStateDelegateImpl<MvpView, MvpPresenter<MvpView>, ViewState<MvpView>> delegate = new ActivityMvpViewStateDelegateImpl<>(activity, callback, true);
startActivity(delegate, null, 1, 1, 1, 1, 1, 0, null, 0, 1, 0);
Bundle bundle = BundleMocker.create();
finishActivity(delegate, bundle, false, 1, false, true);
}
use of com.hannesdorfmann.mosby3.mvp.viewstate.ViewState in project mosby by sockeqwe.
the class ActivityMvpViewStateDelegateImplTestNew method initComponents.
@Before
public void initComponents() {
view = new MvpView() {
};
viewState = Mockito.mock(ViewState.class);
presenter = Mockito.mock(MvpPresenter.class);
callback = Mockito.spy(PartialMvpViewStateDelegateCallbackImpl.class);
activity = Mockito.mock(Activity.class);
application = Mockito.mock(Application.class);
Mockito.doCallRealMethod().when(callback).setPresenter(presenter);
Mockito.doCallRealMethod().when(callback).getPresenter();
Mockito.doCallRealMethod().when(callback).setViewState(viewState);
Mockito.doCallRealMethod().when(callback).getViewState();
Mockito.when(callback.getMvpView()).thenReturn(view);
Mockito.when(activity.getApplication()).thenReturn(application);
Mockito.when(callback.createPresenter()).thenReturn(presenter);
Mockito.when(callback.createViewState()).thenReturn(viewState);
}
Aggregations