diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index c6dbe092d..39627b74c 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 35a8a82d9..585f867ea 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 425f72f42..33532d260 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; }