Search in sources :

Example 1 with MugenCallbacks

use of com.mugen.MugenCallbacks in project TeamCityApp by vase4kin.

the class TestsPresenterImpl method initViews.

/**
 * {@inheritDoc}
 */
@Override
protected void initViews() {
    super.initViews();
    mView.setListener(this);
    mView.setOnLoadMoreListener(new MugenCallbacks() {

        @Override
        public void onLoadMore() {
            mIsLoadMoreLoading = true;
            mView.addLoadMore();
            mDataManager.loadMore(new OnLoadingListener<List<TestOccurrences.TestOccurrence>>() {

                @Override
                public void onSuccess(List<TestOccurrences.TestOccurrence> data) {
                    mView.removeLoadMore();
                    mView.addMoreBuilds(new TestsDataModelImpl(data));
                    mIsLoadMoreLoading = false;
                }

                @Override
                public void onFail(String errorMessage) {
                    mView.removeLoadMore();
                    mView.showRetryLoadMoreSnackBar();
                    mIsLoadMoreLoading = false;
                }
            });
        }

        @Override
        public boolean isLoading() {
            return mIsLoadMoreLoading;
        }

        @Override
        public boolean hasLoadedAllItems() {
            return !mDataManager.canLoadMore();
        }
    });
    mView.replaceSkeletonViewContent();
}
Also used : TestsDataModelImpl(com.github.vase4kin.teamcityapp.tests.data.TestsDataModelImpl) MugenCallbacks(com.mugen.MugenCallbacks) TestOccurrences(com.github.vase4kin.teamcityapp.tests.api.TestOccurrences) List(java.util.List) OnLoadingListener(com.github.vase4kin.teamcityapp.account.create.data.OnLoadingListener)

Example 2 with MugenCallbacks

use of com.mugen.MugenCallbacks in project TeamCityApp by vase4kin.

the class ChangesPresenterImpl method initViews.

/**
 * {@inheritDoc}
 */
@Override
protected void initViews() {
    super.initViews();
    mView.setLoadMoreListener(new MugenCallbacks() {

        @Override
        public void onLoadMore() {
            mIsLoadMoreLoading = true;
            mView.addLoadMore();
            mDataManager.loadMore(new OnLoadingListener<List<Changes.Change>>() {

                @Override
                public void onSuccess(List<Changes.Change> data) {
                    mView.removeLoadMore();
                    mView.addMoreBuilds(new ChangesDataModelImpl(data));
                    mIsLoadMoreLoading = false;
                }

                @Override
                public void onFail(String errorMessage) {
                    mView.removeLoadMore();
                    mView.showRetryLoadMoreSnackBar();
                    mIsLoadMoreLoading = false;
                }
            });
        }

        @Override
        public boolean isLoading() {
            return mIsLoadMoreLoading;
        }

        @Override
        public boolean hasLoadedAllItems() {
            return !mDataManager.canLoadMore();
        }
    });
    mView.replaceSkeletonViewContent();
}
Also used : Changes(com.github.vase4kin.teamcityapp.changes.api.Changes) MugenCallbacks(com.mugen.MugenCallbacks) List(java.util.List) OnLoadingListener(com.github.vase4kin.teamcityapp.account.create.data.OnLoadingListener) ChangesDataModelImpl(com.github.vase4kin.teamcityapp.changes.data.ChangesDataModelImpl)

Example 3 with MugenCallbacks

use of com.mugen.MugenCallbacks in project TeamCityApp by vase4kin.

the class ChangesPresenterImplTest method testInitViews.

@Test
public void testInitViews() throws Exception {
    when(mDataManager.canLoadMore()).thenReturn(false);
    mPresenter.initViews();
    verify(mView).setLoadMoreListener(mOnLoadMoreListenerArgumentCaptor.capture());
    MugenCallbacks onLoadMoreListener = mOnLoadMoreListenerArgumentCaptor.getValue();
    assertThat(onLoadMoreListener.hasLoadedAllItems(), is(true));
    verify(mDataManager).canLoadMore();
    onLoadMoreListener.onLoadMore();
    verify(mView).addLoadMore();
    verify(mDataManager).loadMore(mOnChangesLoadingListener.capture());
    assertThat(mPresenter.mIsLoadMoreLoading, is(true));
    OnLoadingListener<List<Changes.Change>> onChangesLoadingListener = mOnChangesLoadingListener.getValue();
    List<Changes.Change> changes = Collections.emptyList();
    onChangesLoadingListener.onSuccess(changes);
    verify(mView).removeLoadMore();
    verify(mView).addMoreBuilds(any(ChangesDataModelImpl.class));
    assertThat(mPresenter.mIsLoadMoreLoading, is(false));
    onChangesLoadingListener.onFail("error");
    verify(mView, times(2)).removeLoadMore();
    verify(mView).showRetryLoadMoreSnackBar();
    assertThat(mPresenter.mIsLoadMoreLoading, is(false));
}
Also used : Changes(com.github.vase4kin.teamcityapp.changes.api.Changes) MugenCallbacks(com.mugen.MugenCallbacks) List(java.util.List) ChangesDataModelImpl(com.github.vase4kin.teamcityapp.changes.data.ChangesDataModelImpl) Test(org.junit.Test)

Example 4 with MugenCallbacks

use of com.mugen.MugenCallbacks in project TeamCityApp by vase4kin.

the class TestsPresenterImplTest method testInitViews.

@Test
public void testInitViews() throws Exception {
    when(mDataManager.canLoadMore()).thenReturn(false);
    mPresenter.initViews();
    verify(mView).setOnLoadMoreListener(mOnLoadMoreListenerArgumentCaptor.capture());
    MugenCallbacks onLoadMoreListener = mOnLoadMoreListenerArgumentCaptor.getValue();
    assertThat(onLoadMoreListener.hasLoadedAllItems(), is(true));
    verify(mDataManager).canLoadMore();
    onLoadMoreListener.onLoadMore();
    verify(mView).addLoadMore();
    verify(mDataManager).loadMore(mOnLoadingListenerArgumentCaptor.capture());
    assertThat(mPresenter.mIsLoadMoreLoading, is(true));
    OnLoadingListener<List<TestOccurrences.TestOccurrence>> listOnLoadingListener = mOnLoadingListenerArgumentCaptor.getValue();
    List<TestOccurrences.TestOccurrence> tests = Collections.emptyList();
    listOnLoadingListener.onSuccess(tests);
    verify(mView).removeLoadMore();
    verify(mView).addMoreBuilds(any(TestsDataModelImpl.class));
    assertThat(mPresenter.mIsLoadMoreLoading, is(false));
    listOnLoadingListener.onFail("error");
    verify(mView, times(2)).removeLoadMore();
    verify(mView).showRetryLoadMoreSnackBar();
    assertThat(mPresenter.mIsLoadMoreLoading, is(false));
}
Also used : TestsDataModelImpl(com.github.vase4kin.teamcityapp.tests.data.TestsDataModelImpl) MugenCallbacks(com.mugen.MugenCallbacks) TestOccurrences(com.github.vase4kin.teamcityapp.tests.api.TestOccurrences) List(java.util.List) Test(org.junit.Test)

Aggregations

MugenCallbacks (com.mugen.MugenCallbacks)4 List (java.util.List)4 OnLoadingListener (com.github.vase4kin.teamcityapp.account.create.data.OnLoadingListener)2 Changes (com.github.vase4kin.teamcityapp.changes.api.Changes)2 ChangesDataModelImpl (com.github.vase4kin.teamcityapp.changes.data.ChangesDataModelImpl)2 TestOccurrences (com.github.vase4kin.teamcityapp.tests.api.TestOccurrences)2 TestsDataModelImpl (com.github.vase4kin.teamcityapp.tests.data.TestsDataModelImpl)2 Test (org.junit.Test)2