mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-17 15:19:15 +01:00
Don't restart library subscription
This commit is contained in:
parent
c6df23b1aa
commit
920a71601b
@ -1,7 +1,5 @@
|
|||||||
package eu.kanade.mangafeed.data.models;
|
package eu.kanade.mangafeed.data.models;
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
|
@ -7,13 +7,12 @@ import javax.inject.Inject;
|
|||||||
|
|
||||||
import eu.kanade.mangafeed.data.helpers.DatabaseHelper;
|
import eu.kanade.mangafeed.data.helpers.DatabaseHelper;
|
||||||
import eu.kanade.mangafeed.data.helpers.PreferencesHelper;
|
import eu.kanade.mangafeed.data.helpers.PreferencesHelper;
|
||||||
import eu.kanade.mangafeed.data.models.Manga;
|
import eu.kanade.mangafeed.ui.adapter.LibraryAdapter;
|
||||||
import eu.kanade.mangafeed.ui.fragment.LibraryFragment;
|
import eu.kanade.mangafeed.ui.fragment.LibraryFragment;
|
||||||
import rx.Observable;
|
import rx.Observable;
|
||||||
import rx.Subscription;
|
import rx.Subscription;
|
||||||
import rx.android.schedulers.AndroidSchedulers;
|
import rx.android.schedulers.AndroidSchedulers;
|
||||||
import rx.schedulers.Schedulers;
|
import rx.schedulers.Schedulers;
|
||||||
import uk.co.ribot.easyadapter.EasyAdapter;
|
|
||||||
|
|
||||||
public class LibraryPresenter extends BasePresenter<LibraryFragment> {
|
public class LibraryPresenter extends BasePresenter<LibraryFragment> {
|
||||||
|
|
||||||
@ -36,31 +35,26 @@ public class LibraryPresenter extends BasePresenter<LibraryFragment> {
|
|||||||
|
|
||||||
public void getFavoriteMangas() {
|
public void getFavoriteMangas() {
|
||||||
if (mFavoriteMangasSubscription != null)
|
if (mFavoriteMangasSubscription != null)
|
||||||
remove(mFavoriteMangasSubscription);
|
return;
|
||||||
|
|
||||||
mFavoriteMangasSubscription = db.getMangasWithUnread()
|
add(mFavoriteMangasSubscription = db.getMangasWithUnread()
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.compose(deliverLatestCache())
|
.compose(deliverLatestCache())
|
||||||
.subscribe(this.split((view, mangas) -> {
|
.subscribe(this.split(LibraryFragment::onNextMangas)));
|
||||||
view.getAdapter().setNewItems(mangas);
|
|
||||||
}));
|
|
||||||
|
|
||||||
add(mFavoriteMangasSubscription);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onDelete(SparseBooleanArray checkedItems, EasyAdapter<Manga> adapter) {
|
public void onDelete(SparseBooleanArray checkedItems, LibraryAdapter adapter) {
|
||||||
remove(mDeleteMangaSubscription);
|
if (mDeleteMangaSubscription != null)
|
||||||
|
remove(mDeleteMangaSubscription);
|
||||||
|
|
||||||
mDeleteMangaSubscription = Observable.range(0, checkedItems.size())
|
add(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());
|
||||||
|
|
||||||
add(mDeleteMangaSubscription);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,6 @@ import eu.kanade.mangafeed.ui.fragment.MangaInfoFragment;
|
|||||||
import rx.Observable;
|
import rx.Observable;
|
||||||
import rx.Subscription;
|
import rx.Subscription;
|
||||||
import rx.android.schedulers.AndroidSchedulers;
|
import rx.android.schedulers.AndroidSchedulers;
|
||||||
import rx.schedulers.Schedulers;
|
|
||||||
|
|
||||||
public class MangaInfoPresenter extends BasePresenter<MangaInfoFragment> {
|
public class MangaInfoPresenter extends BasePresenter<MangaInfoFragment> {
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ import eu.kanade.mangafeed.data.models.Manga;
|
|||||||
import rx.Observable;
|
import rx.Observable;
|
||||||
import uk.co.ribot.easyadapter.EasyAdapter;
|
import uk.co.ribot.easyadapter.EasyAdapter;
|
||||||
|
|
||||||
public class LibraryAdapter<T> extends EasyAdapter<T> implements Filterable {
|
public class LibraryAdapter extends EasyAdapter<Manga> implements Filterable {
|
||||||
|
|
||||||
List<Manga> mangas;
|
List<Manga> mangas;
|
||||||
Filter filter;
|
Filter filter;
|
||||||
@ -20,9 +20,9 @@ public class LibraryAdapter<T> extends EasyAdapter<T> implements Filterable {
|
|||||||
filter = new LibraryFilter();
|
filter = new LibraryFilter();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNewItems(List<T> list) {
|
public void setNewItems(List<Manga> list) {
|
||||||
super.setItems(list);
|
super.setItems(list);
|
||||||
mangas = (List<Manga>)list;
|
mangas = list;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -57,7 +57,7 @@ public class LibraryAdapter<T> extends EasyAdapter<T> implements Filterable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void publishResults(CharSequence constraint, FilterResults results) {
|
public void publishResults(CharSequence constraint, FilterResults results) {
|
||||||
setItems((List<T>) results.values);
|
setItems((List<Manga >) results.values);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,6 +12,8 @@ import android.view.View;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.GridView;
|
import android.widget.GridView;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import butterknife.Bind;
|
import butterknife.Bind;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import butterknife.OnItemClick;
|
import butterknife.OnItemClick;
|
||||||
@ -28,7 +30,7 @@ public class LibraryFragment extends BaseFragment<LibraryPresenter> {
|
|||||||
|
|
||||||
@Bind(R.id.gridView) GridView grid;
|
@Bind(R.id.gridView) GridView grid;
|
||||||
private MainActivity activity;
|
private MainActivity activity;
|
||||||
private LibraryAdapter<Manga> adapter;
|
private LibraryAdapter adapter;
|
||||||
|
|
||||||
public static LibraryFragment newInstance() {
|
public static LibraryFragment newInstance() {
|
||||||
LibraryFragment fragment = new LibraryFragment();
|
LibraryFragment fragment = new LibraryFragment();
|
||||||
@ -82,12 +84,12 @@ public class LibraryFragment extends BaseFragment<LibraryPresenter> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void createAdapter() {
|
private void createAdapter() {
|
||||||
adapter = new LibraryAdapter<>(getActivity());
|
adapter = new LibraryAdapter(getActivity());
|
||||||
grid.setAdapter(adapter);
|
grid.setAdapter(adapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
public LibraryAdapter<Manga> getAdapter() {
|
public void onNextMangas(List<Manga> mangas) {
|
||||||
return adapter;
|
adapter.setNewItems(mangas);
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnItemClick(R.id.gridView)
|
@OnItemClick(R.id.gridView)
|
||||||
|
Loading…
Reference in New Issue
Block a user