@@ -0,0 +1,3151 @@
+package com.setiawanpaiman.sunnyreader.ui.presenter;%0A%0Aimport com.setiawanpaiman.sunnyreader.Constants;%0Aimport com.setiawanpaiman.sunnyreader.util.RxUtils;%0A%0Aimport rx.Observable;%0Aimport rx.Scheduler;%0Aimport rx.Subscriber;%0Aimport rx.Subscription;%0Aimport rx.android.schedulers.AndroidSchedulers;%0Aimport rx.functions.Action0;%0A%0Apublic abstract class EndlessListPresenter%3CModel%3E implements EndlessListContract.Presenter%3CModel%3E %7B%0A%0A    private EndlessListContract.View%3CModel%3E mView;%0A    private Scheduler mScheduler;%0A%0A    private Subscription mSubscription;%0A    private boolean mLoadMoreTriggered;%0A    private int mCurrentPage = Constants.FIRST_PAGE;%0A%0A    public EndlessListPresenter(EndlessListContract.View%3CModel%3E view,%0A                                Scheduler scheduler) %7B%0A        mView = view;%0A        mScheduler = scheduler;%0A    %7D%0A%0A    @Override%0A    public int getCurrentPage() %7B%0A        return mCurrentPage;%0A    %7D%0A%0A    @Override%0A    public void onRestoreInstanceState(int page) %7B%0A        mCurrentPage = page;%0A    %7D%0A%0A    @Override%0A    public boolean isLoadIsInProgress() %7B%0A        return RxUtils.isSubscriptionActive(mSubscription);%0A    %7D%0A%0A    @Override%0A    public void loadData(final boolean refresh) %7B%0A        if (refresh) RxUtils.unsubscribeAll(mSubscription);%0A        else if (isLoadIsInProgress()) %7B%0A            mLoadMoreTriggered = true;%0A            return;%0A        %7D%0A%0A        mCurrentPage = refresh ? Constants.FIRST_PAGE : mCurrentPage + 1;%0A        mView.setProgressVisibility(true, refresh);%0A        mSubscription = createRequestObservable(mCurrentPage)%0A                .doOnUnsubscribe(new Action0() %7B%0A                    @Override%0A                    public void call() %7B%0A                        if (mLoadMoreTriggered) %7B%0A                            mLoadMoreTriggered = false;%0A                            loadData(false);%0A                        %7D%0A                    %7D%0A                %7D)%0A                .observeOn(AndroidSchedulers.mainThread(), true)%0A                .subscribeOn(mScheduler)%0A                .subscribe(new Subscriber%3CModel%3E() %7B%0A                    boolean firstOnNext = true;%0A%0A                    @Override%0A                    public void onCompleted() %7B%0A                        mView.setProgressVisibility(false, refresh);%0A                    %7D%0A%0A                    @Override%0A                    public void onError(Throwable e) %7B%0A                        // reset current page if error occurred%0A                        if (!refresh) mCurrentPage--;%0A                        mView.setProgressVisibility(false, refresh);%0A                    %7D%0A%0A                    @Override%0A                    public void onNext(Model story) %7B%0A                        if (refresh && firstOnNext) %7B%0A                            mView.showData(story, true);%0A                        %7D else %7B%0A                            mView.showData(story, false);%0A                        %7D%0A                        firstOnNext = false;%0A                    %7D%0A                %7D);%0A    %7D%0A%0A    @Override%0A    public void onDestroy() %7B%0A        RxUtils.unsubscribeAll(mSubscription);%0A    %7D%0A%0A    public abstract Observable%3CModel%3E createRequestObservable(int page);%0A%7D%0A

Move TopStoriesPresenter implementation to EndlessListPresenter