From 38da2ba35b7419e72229c211bd763382133be3d2 Mon Sep 17 00:00:00 2001 From: inorichi Date: Mon, 12 Oct 2015 21:33:53 +0200 Subject: [PATCH] Optimize imports. Keep tracking of every subscription --- .../main/java/eu/kanade/mangafeed/App.java | 2 -- .../eu/kanade/mangafeed/AppComponent.java | 3 -- .../mangafeed/data/caches/CacheManager.java | 1 - .../mangafeed/data/helpers/NetworkHelper.java | 4 --- .../kanade/mangafeed/data/models/Manga.java | 34 ++----------------- .../presenter/CatalogueListPresenter.java | 2 +- .../mangafeed/presenter/LibraryPresenter.java | 27 ++++++++++++--- .../ui/activity/CatalogueListActivity.java | 2 +- .../mangafeed/ui/activity/MainActivity.java | 1 - .../ui/activity/MangaDetailActivity.java | 2 -- .../mangafeed/ui/adapter/LibraryAdapter.java | 1 - .../ui/fragment/LibraryFragment.java | 2 +- 12 files changed, 28 insertions(+), 53 deletions(-) diff --git a/app/src/main/java/eu/kanade/mangafeed/App.java b/app/src/main/java/eu/kanade/mangafeed/App.java index 6ea0fe4ce..e23faa437 100644 --- a/app/src/main/java/eu/kanade/mangafeed/App.java +++ b/app/src/main/java/eu/kanade/mangafeed/App.java @@ -3,8 +3,6 @@ package eu.kanade.mangafeed; import android.app.Application; import android.content.Context; -import org.acra.ACRA; -import org.acra.ReportingInteractionMode; import org.acra.annotation.ReportsCrashes; import timber.log.Timber; diff --git a/app/src/main/java/eu/kanade/mangafeed/AppComponent.java b/app/src/main/java/eu/kanade/mangafeed/AppComponent.java index 02ae634d8..093531a65 100644 --- a/app/src/main/java/eu/kanade/mangafeed/AppComponent.java +++ b/app/src/main/java/eu/kanade/mangafeed/AppComponent.java @@ -10,9 +10,6 @@ import eu.kanade.mangafeed.presenter.CatalogueListPresenter; import eu.kanade.mangafeed.presenter.CataloguePresenter; import eu.kanade.mangafeed.presenter.LibraryPresenter; import eu.kanade.mangafeed.presenter.MangaDetailPresenter; -import eu.kanade.mangafeed.ui.activity.MainActivity; -import eu.kanade.mangafeed.ui.activity.MangaDetailActivity; -import eu.kanade.mangafeed.ui.fragment.LibraryFragment; @Singleton @Component( diff --git a/app/src/main/java/eu/kanade/mangafeed/data/caches/CacheManager.java b/app/src/main/java/eu/kanade/mangafeed/data/caches/CacheManager.java index 49ddde865..715541e68 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/caches/CacheManager.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/caches/CacheManager.java @@ -18,7 +18,6 @@ import java.util.concurrent.TimeoutException; import eu.kanade.mangafeed.util.DiskUtils; import rx.Observable; -import rx.Subscriber; import rx.functions.Action0; public class CacheManager { diff --git a/app/src/main/java/eu/kanade/mangafeed/data/helpers/NetworkHelper.java b/app/src/main/java/eu/kanade/mangafeed/data/helpers/NetworkHelper.java index 4e6390fb7..a1d5f888f 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/helpers/NetworkHelper.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/helpers/NetworkHelper.java @@ -7,11 +7,7 @@ import com.squareup.okhttp.OkHttpClient; import com.squareup.okhttp.Request; import com.squareup.okhttp.Response; -import java.io.IOException; - import rx.Observable; -import rx.Subscriber; -import timber.log.Timber; public final class NetworkHelper { diff --git a/app/src/main/java/eu/kanade/mangafeed/data/models/Manga.java b/app/src/main/java/eu/kanade/mangafeed/data/models/Manga.java index 252d57017..12b12b2aa 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/models/Manga.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/models/Manga.java @@ -2,6 +2,7 @@ package eu.kanade.mangafeed.data.models; import android.support.annotation.NonNull; import android.support.annotation.Nullable; + import com.pushtorefresh.storio.sqlite.annotations.StorIOSQLiteColumn; import com.pushtorefresh.storio.sqlite.annotations.StorIOSQLiteType; @@ -106,41 +107,12 @@ public class Manga { Manga manga = (Manga) o; - if (source != manga.source) return false; - if (rank != manga.rank) return false; - if (last_update != manga.last_update) return false; - if (initialized != manga.initialized) return false; - if (viewer != manga.viewer) return false; - if (chapter_order != manga.chapter_order) return false; - if (id != null ? !id.equals(manga.id) : manga.id != null) return false; - if (!url.equals(manga.url)) return false; - if (!artist.equals(manga.artist)) return false; - if (!author.equals(manga.author)) return false; - if (!description.equals(manga.description)) return false; - if (!genre.equals(manga.genre)) return false; - if (!title.equals(manga.title)) return false; - if (!status.equals(manga.status)) return false; - return thumbnail_url.equals(manga.thumbnail_url); + return url.equals(manga.url); } @Override public int hashCode() { - int result = id != null ? id.hashCode() : 0; - result = 31 * result + source; - result = 31 * result + url.hashCode(); - result = 31 * result + artist.hashCode(); - result = 31 * result + author.hashCode(); - result = 31 * result + description.hashCode(); - result = 31 * result + genre.hashCode(); - result = 31 * result + title.hashCode(); - result = 31 * result + status.hashCode(); - result = 31 * result + thumbnail_url.hashCode(); - result = 31 * result + rank; - result = 31 * result + (int) (last_update ^ (last_update >>> 32)); - result = 31 * result + (initialized ? 1 : 0); - result = 31 * result + viewer; - result = 31 * result + chapter_order; - return result; + return url.hashCode(); } } diff --git a/app/src/main/java/eu/kanade/mangafeed/presenter/CatalogueListPresenter.java b/app/src/main/java/eu/kanade/mangafeed/presenter/CatalogueListPresenter.java index 9f6ac58d3..e847ea821 100644 --- a/app/src/main/java/eu/kanade/mangafeed/presenter/CatalogueListPresenter.java +++ b/app/src/main/java/eu/kanade/mangafeed/presenter/CatalogueListPresenter.java @@ -34,7 +34,7 @@ public class CatalogueListPresenter extends BasePresenter { App.getComponent(view.getActivity()).inject(this); } - public void initializeSource() { + public void initialize() { int sourceId = view.getIntent().getIntExtra(Intent.EXTRA_UID, -1); selectedSource = sourceManager.get(sourceId); view.setSource(selectedSource); 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 aa8343926..ca5982484 100644 --- a/app/src/main/java/eu/kanade/mangafeed/presenter/LibraryPresenter.java +++ b/app/src/main/java/eu/kanade/mangafeed/presenter/LibraryPresenter.java @@ -14,6 +14,8 @@ import eu.kanade.mangafeed.ui.adapter.LibraryAdapter; import eu.kanade.mangafeed.util.DummyDataUtil; import eu.kanade.mangafeed.view.LibraryView; import rx.Observable; +import rx.Subscription; +import rx.android.schedulers.AndroidSchedulers; import rx.schedulers.Schedulers; public class LibraryPresenter extends BasePresenter { @@ -25,6 +27,9 @@ public class LibraryPresenter extends BasePresenter { LibraryAdapter adapter; + private Subscription mFavoriteMangasSubscription; + private Subscription mDeleteMangaSubscription; + public LibraryPresenter(LibraryView view) { this.view = view; App.getComponent(view.getActivity()).inject(this); @@ -46,15 +51,23 @@ public class LibraryPresenter extends BasePresenter { view.getActivity().startActivity(intent); } - public void initializeMangas() { + public void initialize() { adapter = new LibraryAdapter<>(view.getActivity()); view.setAdapter(adapter); view.setMangaClickListener(); - subscriptions.add(db.getMangasWithUnread() - .subscribe(adapter::setNewItems) - ); + getFavoriteMangas(); + } + public void getFavoriteMangas() { + subscriptions.remove(mFavoriteMangasSubscription); + + mFavoriteMangasSubscription = db.getMangasWithUnread() + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(adapter::setNewItems); + + subscriptions.add(mFavoriteMangasSubscription); } public void onQueryTextChange(String query) { @@ -62,13 +75,17 @@ public class LibraryPresenter extends BasePresenter { } public void onDelete(SparseBooleanArray checkedItems) { - Observable.range(0, checkedItems.size()) + subscriptions.remove(mDeleteMangaSubscription); + + mDeleteMangaSubscription = Observable.range(0, checkedItems.size()) .observeOn(Schedulers.io()) .map(checkedItems::keyAt) .map(adapter::getItem) .toList() .flatMap(db::deleteMangas) .subscribe(); + + subscriptions.add(mDeleteMangaSubscription); } } diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/activity/CatalogueListActivity.java b/app/src/main/java/eu/kanade/mangafeed/ui/activity/CatalogueListActivity.java index a938dbaaa..97dd0461b 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/activity/CatalogueListActivity.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/activity/CatalogueListActivity.java @@ -33,7 +33,7 @@ public class CatalogueListActivity extends BaseActivity implements CatalogueList setupToolbar(toolbar); presenter = new CatalogueListPresenter(this); - presenter.initializeSource(); + presenter.initialize(); } @Override diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/activity/MainActivity.java b/app/src/main/java/eu/kanade/mangafeed/ui/activity/MainActivity.java index d6bb7ab7c..42d3929fd 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/activity/MainActivity.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/activity/MainActivity.java @@ -15,7 +15,6 @@ import butterknife.ButterKnife; import eu.kanade.mangafeed.R; import eu.kanade.mangafeed.ui.fragment.CatalogueFragment; import eu.kanade.mangafeed.ui.fragment.LibraryFragment; -import rx.subscriptions.CompositeSubscription; public class MainActivity extends BaseActivity { diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/activity/MangaDetailActivity.java b/app/src/main/java/eu/kanade/mangafeed/ui/activity/MangaDetailActivity.java index 69305263e..8372984a9 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/activity/MangaDetailActivity.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/activity/MangaDetailActivity.java @@ -4,8 +4,6 @@ import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.support.v7.widget.Toolbar; -import android.view.Menu; -import android.view.MenuItem; import android.widget.ListView; import java.util.List; diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/adapter/LibraryAdapter.java b/app/src/main/java/eu/kanade/mangafeed/ui/adapter/LibraryAdapter.java index 84ca3ea4d..723a97adc 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/adapter/LibraryAdapter.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/adapter/LibraryAdapter.java @@ -4,7 +4,6 @@ import android.content.Context; import android.widget.Filter; import android.widget.Filterable; -import java.util.ArrayList; import java.util.List; import eu.kanade.mangafeed.data.models.Manga; 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 530cb2c56..7944df604 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 @@ -50,7 +50,7 @@ public class LibraryFragment extends BaseFragment implements LibraryView { activity.setToolbarTitle(getString(R.string.library_title)); ButterKnife.bind(this, view); - presenter.initializeMangas(); + presenter.initialize(); return view; }