From e386257d34507dce4c32c268b9d2cc8b378349d0 Mon Sep 17 00:00:00 2001 From: inorichi Date: Thu, 1 Oct 2015 14:51:07 +0200 Subject: [PATCH] Unsubscribe subscriptions --- .../kanade/mangafeed/presenter/LibraryPresenter.java | 10 +++++++++- .../kanade/mangafeed/ui/fragment/LibraryFragment.java | 7 +++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/kanade/mangafeed/presenter/LibraryPresenter.java b/app/src/main/java/eu/kanade/mangafeed/presenter/LibraryPresenter.java index 3d305d3259..0297420b36 100644 --- a/app/src/main/java/eu/kanade/mangafeed/presenter/LibraryPresenter.java +++ b/app/src/main/java/eu/kanade/mangafeed/presenter/LibraryPresenter.java @@ -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 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(); + } + } + } diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/fragment/LibraryFragment.java b/app/src/main/java/eu/kanade/mangafeed/ui/fragment/LibraryFragment.java index aa211ee610..ce2f776d0a 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/fragment/LibraryFragment.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/fragment/LibraryFragment.java @@ -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);