Search in sources :

Example 1 with BuildDetails

use of com.github.vase4kin.teamcityapp.overview.data.BuildDetails in project TeamCityApp by vase4kin.

the class OverviewPresenterImpl method onCreate.

/**
 * {@inheritDoc}
 */
@Override
public void onCreate() {
    mView.initViews(this);
    mInteractor.setListener(this);
    mView.showSkeletonView();
    BuildDetails buildDetails = mInteractor.getBuildDetails();
    loadBuildDetails(buildDetails.isRunning());
}
Also used : BuildDetails(com.github.vase4kin.teamcityapp.overview.data.BuildDetails)

Example 2 with BuildDetails

use of com.github.vase4kin.teamcityapp.overview.data.BuildDetails in project TeamCityApp by vase4kin.

the class BuildListPresenterImpl method onResetFiltersSnackBarActionClick.

/**
 * {@inheritDoc}
 */
@Override
public void onResetFiltersSnackBarActionClick() {
    mView.disableSwipeToRefresh();
    mView.showRefreshAnimation();
    mView.hideErrorView();
    mView.hideEmpty();
    mView.showData(new BuildListDataModelImpl(Collections.<BuildDetails>emptyList()));
    mDataManager.load(mValueExtractor.getId(), loadingListener, true);
}
Also used : BuildDetails(com.github.vase4kin.teamcityapp.overview.data.BuildDetails) BuildListDataModelImpl(com.github.vase4kin.teamcityapp.buildlist.data.BuildListDataModelImpl)

Example 3 with BuildDetails

use of com.github.vase4kin.teamcityapp.overview.data.BuildDetails in project TeamCityApp by vase4kin.

the class BuildListDataModelImplTest method testAddDataModel.

@Test
public void testAddDataModel() throws Exception {
    BuildDetails build = new BuildDetailsImpl(mBuild);
    BuildListDataModel dataModel = new BuildListDataModelImpl(Collections.singletonList(build));
    mDataModel.addMoreBuilds(dataModel);
    assertThat(mDataModel.getBuild(1), is(mBuild));
    assertThat(mDataModel.getItemCount(), is(2));
}
Also used : BuildDetailsImpl(com.github.vase4kin.teamcityapp.overview.data.BuildDetailsImpl) BuildDetails(com.github.vase4kin.teamcityapp.overview.data.BuildDetails) Test(org.junit.Test)

Example 4 with BuildDetails

use of com.github.vase4kin.teamcityapp.overview.data.BuildDetails in project TeamCityApp by vase4kin.

the class BuildListDataManagerImpl method loadBuilds.

/**
 * {@inheritDoc}
 */
public void loadBuilds(@NonNull Observable<Builds> call, @NonNull final OnLoadingListener<List<BuildDetails>> loadingListener) {
    mSubscriptions.clear();
    Subscription subscription = call.flatMap(new Func1<Builds, Observable<Build>>() {

        @Override
        public Observable<Build> call(Builds builds) {
            if (builds.getCount() == 0) {
                return Observable.from(Collections.<Build>emptyList());
            } else {
                mLoadMoreUrl = builds.getNextHref();
                return Observable.from(builds.getObjects());
            }
        }
    }).flatMap(new Func1<Build, Observable<Build>>() {

        @Override
        public Observable<Build> call(Build build) {
            // Make sure cache is updated
            final BuildDetails serverBuildDetails = new BuildDetailsImpl(build);
            // If server build's running update cache immediately
            if (serverBuildDetails.isRunning()) {
                return mRepository.build(build.getHref(), true);
            } else {
                // Call cache
                return mRepository.build(build.getHref(), false).flatMap(new Func1<Build, Observable<Build>>() {

                    @Override
                    public Observable<Build> call(Build build) {
                        BuildDetails cacheBuildDetails = new BuildDetailsImpl(build);
                        // If cache's not updated -> update it
                        return mRepository.build(build.getHref(), // Don't update cache if server and cache builds are finished
                        !(serverBuildDetails.isFinished() == cacheBuildDetails.isFinished()));
                    }
                });
            }
        }
    }).flatMap(new Func1<Build, Observable<BuildDetails>>() {

        @Override
        public Observable<BuildDetails> call(Build build) {
            return Observable.<BuildDetails>just(new BuildDetailsImpl(build));
        }
    }).toSortedList(new Func2<BuildDetails, BuildDetails, Integer>() {

        @Override
        public Integer call(BuildDetails build, BuildDetails build2) {
            return (build.isQueued() == build2.isQueued()) ? 0 : (build.isQueued() ? -1 : 1);
        }
    }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<List<BuildDetails>>() {

        @Override
        public void onCompleted() {
        }

        @Override
        public void onError(Throwable e) {
            loadingListener.onFail(e.getMessage());
        }

        @Override
        public void onNext(List<BuildDetails> builds) {
            loadingListener.onSuccess(builds);
        }
    });
    mSubscriptions.add(subscription);
}
Also used : BuildDetails(com.github.vase4kin.teamcityapp.overview.data.BuildDetails) Builds(com.github.vase4kin.teamcityapp.buildlist.api.Builds) Observable(rx.Observable) BuildDetailsImpl(com.github.vase4kin.teamcityapp.overview.data.BuildDetailsImpl) Build(com.github.vase4kin.teamcityapp.buildlist.api.Build) List(java.util.List) Subscription(rx.Subscription) Func1(rx.functions.Func1) Func2(rx.functions.Func2)

Example 5 with BuildDetails

use of com.github.vase4kin.teamcityapp.overview.data.BuildDetails in project TeamCityApp by vase4kin.

the class BuildListPresenterImpl method onFilterBuildsActivityResult.

/**
 * {@inheritDoc}
 */
@Override
public void onFilterBuildsActivityResult(BuildListFilter filter) {
    mView.showBuildFilterAppliedSnackBar();
    mView.disableSwipeToRefresh();
    mView.showRefreshAnimation();
    mView.hideErrorView();
    mView.hideEmpty();
    mView.showData(new BuildListDataModelImpl(Collections.<BuildDetails>emptyList()));
    mDataManager.load(mValueExtractor.getId(), filter, loadingListener, true);
}
Also used : BuildDetails(com.github.vase4kin.teamcityapp.overview.data.BuildDetails) BuildListDataModelImpl(com.github.vase4kin.teamcityapp.buildlist.data.BuildListDataModelImpl)

Aggregations

BuildDetails (com.github.vase4kin.teamcityapp.overview.data.BuildDetails)5 BuildListDataModelImpl (com.github.vase4kin.teamcityapp.buildlist.data.BuildListDataModelImpl)2 BuildDetailsImpl (com.github.vase4kin.teamcityapp.overview.data.BuildDetailsImpl)2 Build (com.github.vase4kin.teamcityapp.buildlist.api.Build)1 Builds (com.github.vase4kin.teamcityapp.buildlist.api.Builds)1 List (java.util.List)1 Test (org.junit.Test)1 Observable (rx.Observable)1 Subscription (rx.Subscription)1 Func1 (rx.functions.Func1)1 Func2 (rx.functions.Func2)1