diff --git a/app/src/main/java/com/readrops/app/activities/MainActivity.java b/app/src/main/java/com/readrops/app/activities/MainActivity.java index 5d1ff900..01c619cf 100644 --- a/app/src/main/java/com/readrops/app/activities/MainActivity.java +++ b/app/src/main/java/com/readrops/app/activities/MainActivity.java @@ -83,6 +83,7 @@ public class MainActivity extends AppCompatActivity implements SwipeRefreshLayou private int feedCount; private int feedNb; private boolean scrollToTop; + private boolean allItemsSelected; private ActionMode actionMode; @@ -247,29 +248,17 @@ public class MainActivity extends AppCompatActivity implements SwipeRefreshLayou public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) { switch (menuItem.getItemId()) { case R.id.item_mark_read: - viewModel.setItemsReadState(getIdsFromPositions(adapter.getSelection()), true) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .doOnError(throwable -> Toast.makeText(getApplicationContext(), - "Error when updating in db", Toast.LENGTH_LONG).show()) - .subscribe(); - adapter.updateSelection(true); - + setReadState(true, allItemsSelected); break; case R.id.item_mark_unread: - viewModel.setItemsReadState(getIdsFromPositions(adapter.getSelection()), false) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .doOnError(throwable -> Toast.makeText(getApplicationContext(), - "Error when updating in db", Toast.LENGTH_LONG).show()) - .subscribe(); - adapter.updateSelection(false); - + setReadState(false, allItemsSelected); + break; + case R.id.item_select_all: + adapter.selectAll(); + allItemsSelected = true; break; } - updateDrawerFeeds(); - actionMode.finish(); return true; } @@ -366,6 +355,28 @@ public class MainActivity extends AppCompatActivity implements SwipeRefreshLayou }); } + private void setReadState(boolean read, boolean allItems) { + if (allItems) { + viewModel.setAllItemsReadState(read) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(); + + allItemsSelected = false; + } else { + viewModel.setItemsReadState(getIdsFromPositions(adapter.getSelection()), read) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .doOnError(throwable -> Toast.makeText(getApplicationContext(), + "Error when updating in db", Toast.LENGTH_LONG).show()) + .subscribe(); + } + + adapter.updateSelection(read); + updateDrawerFeeds(); + actionMode.finish(); + } + @Override public void onRefresh() { Log.d(TAG, "syncing started"); diff --git a/app/src/main/java/com/readrops/app/database/dao/ItemDao.java b/app/src/main/java/com/readrops/app/database/dao/ItemDao.java index 2a6b0e7b..11d2d70c 100644 --- a/app/src/main/java/com/readrops/app/database/dao/ItemDao.java +++ b/app/src/main/java/com/readrops/app/database/dao/ItemDao.java @@ -31,12 +31,15 @@ public interface ItemDao { /** * Set an item read or unread - * @param itemId if of the item to update + * @param itemId id of the item to update * @param readState 1 for read, 0 for unread */ @Query("Update Item set read = :readState Where id = :itemId") void setReadState(int itemId, int readState); + @Query("Update Item set read = :readState") + void setAllItemsReadState(int readState); + @Query("Update Item set read_it_later = 1 Where id = :itemId") void setReadItLater(int itemId); diff --git a/app/src/main/java/com/readrops/app/viewmodels/MainViewModel.java b/app/src/main/java/com/readrops/app/viewmodels/MainViewModel.java index 7ead9399..840a1dd8 100644 --- a/app/src/main/java/com/readrops/app/viewmodels/MainViewModel.java +++ b/app/src/main/java/com/readrops/app/viewmodels/MainViewModel.java @@ -150,6 +150,13 @@ public class MainViewModel extends AndroidViewModel { return Completable.concat(completableList); } + public Completable setAllItemsReadState(boolean read) { + return Completable.create(emitter -> { + db.itemDao().setAllItemsReadState(read ? 1 : 0); + emitter.onComplete(); + }); + } + public Completable setItemReadItLater(int itemId) { return Completable.create(emitter -> { db.itemDao().setReadItLater(itemId); diff --git a/app/src/main/java/com/readrops/app/views/MainItemListAdapter.java b/app/src/main/java/com/readrops/app/views/MainItemListAdapter.java index d6da6043..cd4e5323 100644 --- a/app/src/main/java/com/readrops/app/views/MainItemListAdapter.java +++ b/app/src/main/java/com/readrops/app/views/MainItemListAdapter.java @@ -195,6 +195,15 @@ public class MainItemListAdapter extends PagedListAdapter + + \ No newline at end of file diff --git a/app/src/main/res/values-fr-rFR/strings.xml b/app/src/main/res/values-fr-rFR/strings.xml index f9679a5d..59133cee 100644 --- a/app/src/main/res/values-fr-rFR/strings.xml +++ b/app/src/main/res/values-fr-rFR/strings.xml @@ -49,5 +49,6 @@ Marquer comme non lu Marquer comme lu + Tout sélectionner \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 47d374a8..fbeb1af5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -51,4 +51,5 @@ Mark as non read Mark as read + Select all