Unsubscribe subscriptions

This commit is contained in:
inorichi 2015-10-01 14:51:07 +02:00
parent 4e795b69e5
commit e386257d34
2 changed files with 16 additions and 1 deletions

View file

@ -11,6 +11,7 @@ import eu.kanade.mangafeed.data.models.Manga;
import eu.kanade.mangafeed.ui.activity.MangaDetailActivity;
import eu.kanade.mangafeed.ui.adapter.LibraryAdapter;
import eu.kanade.mangafeed.view.LibraryView;
import rx.Subscription;
import static rx.android.schedulers.AndroidSchedulers.mainThread;
@ -22,6 +23,7 @@ public class LibraryPresenter extends BasePresenter {
@Inject PreferencesHelper prefs;
LibraryAdapter<Manga> adapter;
private Subscription mangaListSubscription;
public LibraryPresenter(LibraryView view) {
this.view = view;
@ -45,7 +47,7 @@ public class LibraryPresenter extends BasePresenter {
}
public void initializeMangas() {
db.manga.getWithUnread()
mangaListSubscription = db.manga.getWithUnread()
.observeOn(mainThread())
.subscribe(mangas -> {
adapter = new LibraryAdapter<>(view.getActivity(), mangas);
@ -57,4 +59,10 @@ public class LibraryPresenter extends BasePresenter {
adapter.getFilter().filter(query);
}
public void destroySubscriptions() {
if (mangaListSubscription != null) {
mangaListSubscription.unsubscribe();
}
}
}

View file

@ -59,6 +59,13 @@ public class LibraryFragment extends BaseFragment implements LibraryView {
presenter.initializeMangas();
}
@Override
public void onDestroy() {
super.onDestroy();
presenter.destroySubscriptions();
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.library, menu);