Optimize imports. Keep tracking of every subscription
This commit is contained in:
parent
e7116bdcab
commit
38da2ba35b
12 changed files with 28 additions and 53 deletions
|
@ -3,8 +3,6 @@ package eu.kanade.mangafeed;
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import org.acra.ACRA;
|
|
||||||
import org.acra.ReportingInteractionMode;
|
|
||||||
import org.acra.annotation.ReportsCrashes;
|
import org.acra.annotation.ReportsCrashes;
|
||||||
|
|
||||||
import timber.log.Timber;
|
import timber.log.Timber;
|
||||||
|
|
|
@ -10,9 +10,6 @@ import eu.kanade.mangafeed.presenter.CatalogueListPresenter;
|
||||||
import eu.kanade.mangafeed.presenter.CataloguePresenter;
|
import eu.kanade.mangafeed.presenter.CataloguePresenter;
|
||||||
import eu.kanade.mangafeed.presenter.LibraryPresenter;
|
import eu.kanade.mangafeed.presenter.LibraryPresenter;
|
||||||
import eu.kanade.mangafeed.presenter.MangaDetailPresenter;
|
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
|
@Singleton
|
||||||
@Component(
|
@Component(
|
||||||
|
|
|
@ -18,7 +18,6 @@ import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
import eu.kanade.mangafeed.util.DiskUtils;
|
import eu.kanade.mangafeed.util.DiskUtils;
|
||||||
import rx.Observable;
|
import rx.Observable;
|
||||||
import rx.Subscriber;
|
|
||||||
import rx.functions.Action0;
|
import rx.functions.Action0;
|
||||||
|
|
||||||
public class CacheManager {
|
public class CacheManager {
|
||||||
|
|
|
@ -7,11 +7,7 @@ import com.squareup.okhttp.OkHttpClient;
|
||||||
import com.squareup.okhttp.Request;
|
import com.squareup.okhttp.Request;
|
||||||
import com.squareup.okhttp.Response;
|
import com.squareup.okhttp.Response;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import rx.Observable;
|
import rx.Observable;
|
||||||
import rx.Subscriber;
|
|
||||||
import timber.log.Timber;
|
|
||||||
|
|
||||||
public final class NetworkHelper {
|
public final class NetworkHelper {
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ package eu.kanade.mangafeed.data.models;
|
||||||
|
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
import com.pushtorefresh.storio.sqlite.annotations.StorIOSQLiteColumn;
|
import com.pushtorefresh.storio.sqlite.annotations.StorIOSQLiteColumn;
|
||||||
import com.pushtorefresh.storio.sqlite.annotations.StorIOSQLiteType;
|
import com.pushtorefresh.storio.sqlite.annotations.StorIOSQLiteType;
|
||||||
|
|
||||||
|
@ -106,41 +107,12 @@ public class Manga {
|
||||||
|
|
||||||
Manga manga = (Manga) o;
|
Manga manga = (Manga) o;
|
||||||
|
|
||||||
if (source != manga.source) return false;
|
return url.equals(manga.url);
|
||||||
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);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int result = id != null ? id.hashCode() : 0;
|
return url.hashCode();
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ public class CatalogueListPresenter extends BasePresenter {
|
||||||
App.getComponent(view.getActivity()).inject(this);
|
App.getComponent(view.getActivity()).inject(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initializeSource() {
|
public void initialize() {
|
||||||
int sourceId = view.getIntent().getIntExtra(Intent.EXTRA_UID, -1);
|
int sourceId = view.getIntent().getIntExtra(Intent.EXTRA_UID, -1);
|
||||||
selectedSource = sourceManager.get(sourceId);
|
selectedSource = sourceManager.get(sourceId);
|
||||||
view.setSource(selectedSource);
|
view.setSource(selectedSource);
|
||||||
|
|
|
@ -14,6 +14,8 @@ import eu.kanade.mangafeed.ui.adapter.LibraryAdapter;
|
||||||
import eu.kanade.mangafeed.util.DummyDataUtil;
|
import eu.kanade.mangafeed.util.DummyDataUtil;
|
||||||
import eu.kanade.mangafeed.view.LibraryView;
|
import eu.kanade.mangafeed.view.LibraryView;
|
||||||
import rx.Observable;
|
import rx.Observable;
|
||||||
|
import rx.Subscription;
|
||||||
|
import rx.android.schedulers.AndroidSchedulers;
|
||||||
import rx.schedulers.Schedulers;
|
import rx.schedulers.Schedulers;
|
||||||
|
|
||||||
public class LibraryPresenter extends BasePresenter {
|
public class LibraryPresenter extends BasePresenter {
|
||||||
|
@ -25,6 +27,9 @@ public class LibraryPresenter extends BasePresenter {
|
||||||
|
|
||||||
LibraryAdapter<Manga> adapter;
|
LibraryAdapter<Manga> adapter;
|
||||||
|
|
||||||
|
private Subscription mFavoriteMangasSubscription;
|
||||||
|
private Subscription mDeleteMangaSubscription;
|
||||||
|
|
||||||
public LibraryPresenter(LibraryView view) {
|
public LibraryPresenter(LibraryView view) {
|
||||||
this.view = view;
|
this.view = view;
|
||||||
App.getComponent(view.getActivity()).inject(this);
|
App.getComponent(view.getActivity()).inject(this);
|
||||||
|
@ -46,15 +51,23 @@ public class LibraryPresenter extends BasePresenter {
|
||||||
view.getActivity().startActivity(intent);
|
view.getActivity().startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initializeMangas() {
|
public void initialize() {
|
||||||
adapter = new LibraryAdapter<>(view.getActivity());
|
adapter = new LibraryAdapter<>(view.getActivity());
|
||||||
view.setAdapter(adapter);
|
view.setAdapter(adapter);
|
||||||
view.setMangaClickListener();
|
view.setMangaClickListener();
|
||||||
|
|
||||||
subscriptions.add(db.getMangasWithUnread()
|
getFavoriteMangas();
|
||||||
.subscribe(adapter::setNewItems)
|
}
|
||||||
);
|
|
||||||
|
|
||||||
|
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) {
|
public void onQueryTextChange(String query) {
|
||||||
|
@ -62,13 +75,17 @@ public class LibraryPresenter extends BasePresenter {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onDelete(SparseBooleanArray checkedItems) {
|
public void onDelete(SparseBooleanArray checkedItems) {
|
||||||
Observable.range(0, checkedItems.size())
|
subscriptions.remove(mDeleteMangaSubscription);
|
||||||
|
|
||||||
|
mDeleteMangaSubscription = Observable.range(0, checkedItems.size())
|
||||||
.observeOn(Schedulers.io())
|
.observeOn(Schedulers.io())
|
||||||
.map(checkedItems::keyAt)
|
.map(checkedItems::keyAt)
|
||||||
.map(adapter::getItem)
|
.map(adapter::getItem)
|
||||||
.toList()
|
.toList()
|
||||||
.flatMap(db::deleteMangas)
|
.flatMap(db::deleteMangas)
|
||||||
.subscribe();
|
.subscribe();
|
||||||
|
|
||||||
|
subscriptions.add(mDeleteMangaSubscription);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ public class CatalogueListActivity extends BaseActivity implements CatalogueList
|
||||||
setupToolbar(toolbar);
|
setupToolbar(toolbar);
|
||||||
|
|
||||||
presenter = new CatalogueListPresenter(this);
|
presenter = new CatalogueListPresenter(this);
|
||||||
presenter.initializeSource();
|
presenter.initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -15,7 +15,6 @@ import butterknife.ButterKnife;
|
||||||
import eu.kanade.mangafeed.R;
|
import eu.kanade.mangafeed.R;
|
||||||
import eu.kanade.mangafeed.ui.fragment.CatalogueFragment;
|
import eu.kanade.mangafeed.ui.fragment.CatalogueFragment;
|
||||||
import eu.kanade.mangafeed.ui.fragment.LibraryFragment;
|
import eu.kanade.mangafeed.ui.fragment.LibraryFragment;
|
||||||
import rx.subscriptions.CompositeSubscription;
|
|
||||||
|
|
||||||
public class MainActivity extends BaseActivity {
|
public class MainActivity extends BaseActivity {
|
||||||
|
|
||||||
|
|
|
@ -4,8 +4,6 @@ import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.view.Menu;
|
|
||||||
import android.view.MenuItem;
|
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
|
@ -4,7 +4,6 @@ import android.content.Context;
|
||||||
import android.widget.Filter;
|
import android.widget.Filter;
|
||||||
import android.widget.Filterable;
|
import android.widget.Filterable;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import eu.kanade.mangafeed.data.models.Manga;
|
import eu.kanade.mangafeed.data.models.Manga;
|
||||||
|
|
|
@ -50,7 +50,7 @@ public class LibraryFragment extends BaseFragment implements LibraryView {
|
||||||
activity.setToolbarTitle(getString(R.string.library_title));
|
activity.setToolbarTitle(getString(R.string.library_title));
|
||||||
ButterKnife.bind(this, view);
|
ButterKnife.bind(this, view);
|
||||||
|
|
||||||
presenter.initializeMangas();
|
presenter.initialize();
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue