Delete mangas

This commit is contained in:
inorichi 2015-10-03 00:14:40 +02:00
parent a6c59bbc10
commit 53f86c4f4b
4 changed files with 36 additions and 1 deletions

View file

@ -4,6 +4,7 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:name=".App"

View file

@ -1,6 +1,8 @@
package eu.kanade.mangafeed.data.managers;
import com.pushtorefresh.storio.sqlite.StorIOSQLite;
import com.pushtorefresh.storio.sqlite.operations.delete.DeleteResult;
import com.pushtorefresh.storio.sqlite.operations.delete.DeleteResults;
import com.pushtorefresh.storio.sqlite.operations.put.PutResult;
import com.pushtorefresh.storio.sqlite.queries.Query;
import com.pushtorefresh.storio.sqlite.queries.RawQuery;
@ -78,4 +80,18 @@ public class MangaManager extends BaseManager {
return m;
}
public Observable<DeleteResult> delete(Manga manga) {
return db.delete()
.object(manga)
.prepare()
.createObservable();
}
public Observable<DeleteResults<Manga>> delete(List<Manga> mangas) {
return db.delete()
.objects(mangas)
.prepare()
.createObservable();
}
}

View file

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

View file

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