use of com.hannesdorfmann.mosby3.mvp.MvpView in project mosby by sockeqwe.
the class ViewGroupMvpDelegateImplTest method initComponents.
@Before
public void initComponents() {
view = new MvpView() {
};
savedState = null;
presenter = Mockito.mock(MvpPresenter.class);
callback = Mockito.mock(PartialViewGroupMvpDelegateCallbackImpl.class);
Mockito.doCallRealMethod().when(callback).setPresenter(presenter);
Mockito.doCallRealMethod().when(callback).getPresenter();
Mockito.doCallRealMethod().when(callback).superOnSaveInstanceState();
activity = Mockito.mock(FragmentActivity.class);
application = Mockito.mock(Application.class);
androidView = Mockito.mock(View.class);
Mockito.when(callback.getMvpView()).thenReturn(view);
Mockito.when(callback.getContext()).thenReturn(activity);
Mockito.when(activity.getApplication()).thenReturn(application);
Mockito.when(androidView.isInEditMode()).thenReturn(false);
delegate = new ViewGroupMvpDelegateImpl<>(androidView, callback, true);
}
use of com.hannesdorfmann.mosby3.mvp.MvpView in project mosby by sockeqwe.
the class ViewGroupMvpDelegateImplTest method dontKeepPresenterIfSecondPresenterInPresenterManager.
/**
* Checks if two Views one that keeps presenter, the other who doesn't keep presenter during
* screen orientation changes work properly
*
* https://github.com/sockeqwe/mosby/issues/231
*/
@Test
public void dontKeepPresenterIfSecondPresenterInPresenterManager() {
MvpView view1 = new MvpView() {
};
MvpPresenter<MvpView> presenter1 = Mockito.mock(MvpPresenter.class);
PartialViewGroupMvpDelegateCallbackImpl callback1 = Mockito.mock(PartialViewGroupMvpDelegateCallbackImpl.class);
Mockito.doCallRealMethod().when(callback1).setPresenter(presenter1);
Mockito.doCallRealMethod().when(callback1).getPresenter();
View androidView1 = Mockito.mock(View.class);
Mockito.when(callback1.getMvpView()).thenReturn(view1);
Mockito.when(callback1.getContext()).thenReturn(activity);
Mockito.when(androidView1.isInEditMode()).thenReturn(false);
Mockito.when(callback1.createPresenter()).thenReturn(presenter1);
ViewGroupMvpDelegateImpl<MvpView, MvpPresenter<MvpView>> keepDeelgate = new ViewGroupMvpDelegateImpl<MvpView, MvpPresenter<MvpView>>(androidView1, callback1, true);
delegate = new ViewGroupMvpDelegateImpl<MvpView, MvpPresenter<MvpView>>(androidView, callback, false);
keepDeelgate.onAttachedToWindow();
startViewGroup(1, 1, 1);
finishViewGroup(1, 1, true, false);
delegate = new ViewGroupMvpDelegateImpl<MvpView, MvpPresenter<MvpView>>(androidView, callback, false);
startViewGroup(2, 2, 2);
finishViewGroup(2, 2, false, true);
keepDeelgate.onDetachedFromWindow();
}
use of com.hannesdorfmann.mosby3.mvp.MvpView in project mosby by sockeqwe.
the class ActivityMvpDelegateImplTest method initComponents.
@Before
public void initComponents() {
view = new MvpView() {
};
presenter = Mockito.mock(MvpPresenter.class);
callback = Mockito.mock(PartialMvpDelegateCallbackImpl.class);
activity = Mockito.mock(Activity.class);
application = Mockito.mock(Application.class);
Mockito.doCallRealMethod().when(callback).setPresenter(presenter);
Mockito.doCallRealMethod().when(callback).getPresenter();
Mockito.when(callback.getMvpView()).thenReturn(view);
Mockito.when(activity.getApplication()).thenReturn(application);
Mockito.when(callback.createPresenter()).thenReturn(presenter);
}
use of com.hannesdorfmann.mosby3.mvp.MvpView in project mosby by sockeqwe.
the class FragmentMvpViewStateDelegateImpl method onViewCreated.
@Override
public void onViewCreated(View view, Bundle bundle) {
super.onViewCreated(view, bundle);
if (bundle != null && keepPresenterInstanceDuringScreenOrientationChanges) {
mosbyViewId = bundle.getString(KEY_MOSBY_VIEW_ID);
if (DEBUG) {
Log.d(DEBUG_TAG, "MosbyView ID = " + mosbyViewId + " for MvpView: " + delegateCallback.getMvpView());
}
}
if (mosbyViewId != null) {
VS viewState = PresenterManager.getViewState(fragment.getActivity(), mosbyViewId);
if (viewState != null) {
//
// ViewState restored from PresenterManager
//
delegateCallback.setViewState(viewState);
applyViewState = true;
applyViewStateFromMemory = 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;
delegateCallback.setViewState(viewState);
applyViewState = true;
applyViewStateFromMemory = false;
if (keepPresenterInstanceDuringScreenOrientationChanges) {
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(fragment.getActivity(), mosbyViewId, viewState);
}
if (DEBUG) {
Log.d(DEBUG_TAG, "Recreated ViewState from bundle for view: " + delegateCallback.getMvpView() + " viewState: " + viewState);
}
return;
}
}
//
if (keepPresenterInstanceDuringScreenOrientationChanges) {
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(fragment.getActivity(), mosbyViewId, viewState);
}
delegateCallback.setViewState(viewState);
applyViewState = false;
applyViewStateFromMemory = false;
if (DEBUG) {
Log.d(DEBUG_TAG, "Created a new ViewState instance for view: " + delegateCallback.getMvpView() + " viewState: " + viewState);
}
}
use of com.hannesdorfmann.mosby3.mvp.MvpView in project mosby by sockeqwe.
the class FragmentMvpViewStateDelegateImplTest method initComponents.
@Before
public void initComponents() {
view = new MvpView() {
};
viewState = Mockito.mock(ViewState.class);
presenter = Mockito.mock(MvpPresenter.class);
callback = Mockito.spy(PartialMvpViewStateDelegateCallbackImpl.class);
Mockito.doCallRealMethod().when(callback).setPresenter(presenter);
Mockito.doCallRealMethod().when(callback).getPresenter();
Mockito.doCallRealMethod().when(callback).setViewState(viewState);
Mockito.doCallRealMethod().when(callback).getViewState();
fragment = PowerMockito.mock(Fragment.class);
activity = Mockito.mock(FragmentActivity.class);
application = Mockito.mock(Application.class);
Mockito.when(callback.getMvpView()).thenReturn(view);
Mockito.when(fragment.getActivity()).thenReturn(activity);
Mockito.when(activity.getApplication()).thenReturn(application);
Mockito.when(callback.createPresenter()).thenReturn(presenter);
Mockito.when(callback.createViewState()).thenReturn(viewState);
delegate = new FragmentMvpViewStateDelegateImpl<>(fragment, callback, true, true);
}
Aggregations