Optimize imports. Keep tracking of every subscription

This commit is contained in:
inorichi 2015-10-12 21:33:53 +02:00
parent e7116bdcab
commit 38da2ba35b
12 changed files with 28 additions and 53 deletions

View File

@ -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;

View File

@ -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(

View File

@ -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 {

View File

@ -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 {

View File

@ -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();
}
}

View File

@ -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);

View File

@ -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<Manga> 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);
}
}

View File

@ -33,7 +33,7 @@ public class CatalogueListActivity extends BaseActivity implements CatalogueList
setupToolbar(toolbar);
presenter = new CatalogueListPresenter(this);
presenter.initializeSource();
presenter.initialize();
}
@Override

View File

@ -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 {

View File

@ -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;

View File

@ -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;

View File

@ -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;
}