From 53f86c4f4bfa1ef69634389e620e9ad0abf310ee Mon Sep 17 00:00:00 2001 From: inorichi Date: Sat, 3 Oct 2015 00:14:40 +0200 Subject: [PATCH] Delete mangas --- app/src/main/AndroidManifest.xml | 1 + .../mangafeed/data/managers/MangaManager.java | 16 ++++++++++++++++ .../mangafeed/presenter/LibraryPresenter.java | 13 +++++++++++++ .../mangafeed/ui/fragment/LibraryFragment.java | 7 ++++++- 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index c6dbe092db..39627b74c3 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -4,6 +4,7 @@ + delete(Manga manga) { + return db.delete() + .object(manga) + .prepare() + .createObservable(); + } + + public Observable> delete(List mangas) { + return db.delete() + .objects(mangas) + .prepare() + .createObservable(); + } + } 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 35a8a82d9c..585f867ea0 100644 --- a/app/src/main/java/eu/kanade/mangafeed/presenter/LibraryPresenter.java +++ b/app/src/main/java/eu/kanade/mangafeed/presenter/LibraryPresenter.java @@ -1,6 +1,7 @@ package eu.kanade.mangafeed.presenter; import android.content.Intent; +import android.util.SparseBooleanArray; import javax.inject.Inject; @@ -11,6 +12,8 @@ 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.Observable; +import rx.schedulers.Schedulers; import static rx.android.schedulers.AndroidSchedulers.mainThread; @@ -59,4 +62,14 @@ public class LibraryPresenter extends BasePresenter { adapter.getFilter().filter(query); } + public void onDelete(SparseBooleanArray checkedItems) { + Observable.range(0, checkedItems.size()) + .observeOn(Schedulers.io()) + .map(checkedItems::keyAt) + .map(adapter::getItem) + .toList() + .flatMap(db.manga::delete) + .subscribe(); + } + } 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 425f72f422..33532d260c 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 @@ -83,7 +83,6 @@ public class LibraryFragment extends BaseFragment implements LibraryView { }); } - // LibraryView public void setAdapter(EasyAdapter adapter) { @@ -118,6 +117,12 @@ public class LibraryFragment extends BaseFragment implements LibraryView { @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { + switch (item.getItemId()) { + case R.id.action_delete: + presenter.onDelete(grid.getCheckedItemPositions()); + mode.finish(); + return true; + } return false; }