package com.khmelenko.lab.varis.presenter;

import android.text.TextUtils;

import com.khmelenko.lab.varis.mvp.MvpPresenter;
import com.khmelenko.lab.varis.network.response.Repo;
import com.khmelenko.lab.varis.network.retrofit.travis.TravisRestClientRx;
import com.khmelenko.lab.varis.view.SearchResultsView;

import java.util.List;

import javax.inject.Inject;

import io.reactivex.Single;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.schedulers.Schedulers;

/**
 * Search results presenter
 *
 * @author Dmytro Khmelenko (d.khmelenko@gmail.com)
 */
public class SearchResultsPresenter extends MvpPresenter<SearchResultsView> {

    private final TravisRestClientRx mTravisRestClient;

    private final CompositeDisposable mSubscriptions;

    @Inject
    public SearchResultsPresenter(TravisRestClientRx travisRestClient) {
        mTravisRestClient = travisRestClient;

        mSubscriptions = new CompositeDisposable();
    }

    @Override
    public void onAttach() {
        // do nothing
    }

    @Override
    public void onDetach() {
        getView().hideProgress();
        mSubscriptions.clear();
    }

    /**
     * Starts repository search
     *
     * @param query Query string for search
     */
    public void startRepoSearch(String query) {
        Single<List<Repo>> reposSingle;
        if (!TextUtils.isEmpty(query)) {
            reposSingle = mTravisRestClient.getApiService().getRepos(query);
        } else {
            reposSingle = mTravisRestClient.getApiService().getRepos();
        }
        reposSingle.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe((repos, throwable) -> {
                    getView().hideProgress();
                    if (throwable == null) {
                        getView().setSearchResults(repos);
                    } else {
                        getView().showLoadingError(throwable.getMessage());
                    }
                });
    }

}

@@ -491,24 +491,68 @@
 Disposable;%0A
+import io.reactivex.disposables.Disposable;%0A
 import io.re
@@ -1651,24 +1651,50 @@
    %7D%0A       
+ Disposable subscription =
  reposSingle
@@ -2130,16 +2130,58 @@
     %7D);%0A
+        mSubscriptions.add(subscription);%0A
     %7D%0A%0A%7D

Add missing subscription in SearchResultsPresenter