Delete mangas
This commit is contained in:
parent
a6c59bbc10
commit
53f86c4f4b
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||||
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:name=".App"
|
android:name=".App"
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package eu.kanade.mangafeed.data.managers;
|
package eu.kanade.mangafeed.data.managers;
|
||||||
|
|
||||||
import com.pushtorefresh.storio.sqlite.StorIOSQLite;
|
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.operations.put.PutResult;
|
||||||
import com.pushtorefresh.storio.sqlite.queries.Query;
|
import com.pushtorefresh.storio.sqlite.queries.Query;
|
||||||
import com.pushtorefresh.storio.sqlite.queries.RawQuery;
|
import com.pushtorefresh.storio.sqlite.queries.RawQuery;
|
||||||
@ -78,4 +80,18 @@ public class MangaManager extends BaseManager {
|
|||||||
return m;
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package eu.kanade.mangafeed.presenter;
|
package eu.kanade.mangafeed.presenter;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.util.SparseBooleanArray;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
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.activity.MangaDetailActivity;
|
||||||
import eu.kanade.mangafeed.ui.adapter.LibraryAdapter;
|
import eu.kanade.mangafeed.ui.adapter.LibraryAdapter;
|
||||||
import eu.kanade.mangafeed.view.LibraryView;
|
import eu.kanade.mangafeed.view.LibraryView;
|
||||||
|
import rx.Observable;
|
||||||
|
import rx.schedulers.Schedulers;
|
||||||
|
|
||||||
import static rx.android.schedulers.AndroidSchedulers.mainThread;
|
import static rx.android.schedulers.AndroidSchedulers.mainThread;
|
||||||
|
|
||||||
@ -59,4 +62,14 @@ public class LibraryPresenter extends BasePresenter {
|
|||||||
adapter.getFilter().filter(query);
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -83,7 +83,6 @@ public class LibraryFragment extends BaseFragment implements LibraryView {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// LibraryView
|
// LibraryView
|
||||||
|
|
||||||
public void setAdapter(EasyAdapter adapter) {
|
public void setAdapter(EasyAdapter adapter) {
|
||||||
@ -118,6 +117,12 @@ public class LibraryFragment extends BaseFragment implements LibraryView {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user