From c9ae3a5cb526dbbc0be159ee5d5f09910ae4e934 Mon Sep 17 00:00:00 2001 From: Shinokuni Date: Thu, 22 Aug 2019 14:37:06 +0200 Subject: [PATCH] Put methods setAllItemsReadState and setAllFeedItemsReadState int repository to get better control by account type repository --- .../com/readrops/app/database/dao/ItemDao.java | 6 +++--- .../com/readrops/app/repositories/ARepository.java | 14 ++++++++++++++ .../com/readrops/app/viewmodels/MainViewModel.java | 12 ++++-------- 3 files changed, 21 insertions(+), 11 deletions(-) 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 d5b210f4..ae1a75a7 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 @@ -37,11 +37,11 @@ public abstract class ItemDao implements BaseDao { @Query("Update Item Set read_changed = :readChanged, read = :readState Where id = :itemId") public abstract void setReadState(int itemId, int readState, int readChanged); - @Query("Update Item set read_changed = 1, read = :readState") - public abstract void setAllItemsReadState(int readState); + @Query("Update Item set read_changed = 1, read = :readState Where feed_id In (Select id From Feed Where account_id = :accountId)") + public abstract void setAllItemsReadState(int readState, int accountId); @Query("Update Item set read_changed = 1, read = :readState Where feed_id = :feedId") - public abstract void setAllItemsReadState(int feedId, int readState); + public abstract void setAllFeedItemsReadState(int feedId, int readState); @Query("Update Item set read_it_later = 1 Where id = :itemId") public abstract void setReadItLater(int itemId); diff --git a/app/src/main/java/com/readrops/app/repositories/ARepository.java b/app/src/main/java/com/readrops/app/repositories/ARepository.java index 3ed6ec29..daf35d55 100644 --- a/app/src/main/java/com/readrops/app/repositories/ARepository.java +++ b/app/src/main/java/com/readrops/app/repositories/ARepository.java @@ -85,6 +85,20 @@ public abstract class ARepository { }); } + public Completable setAllItemsReadState(Boolean read) { + return Completable.create(emitter -> { + database.itemDao().setAllItemsReadState(read ? 1 : 0, account.getId()); + emitter.onComplete(); + }); + } + + public Completable setAllFeedItemsReadState(int feedId, boolean read) { + return Completable.create(emitter -> { + database.itemDao().setAllFeedItemsReadState(feedId, read ? 1 : 0); + emitter.onComplete(); + }); + } + public Single getFeedCount(int accountId) { return Single.create(emitter -> emitter.onSuccess(database.feedDao().getFeedCount(accountId))); } 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 abe3d473..aeeec180 100644 --- a/app/src/main/java/com/readrops/app/viewmodels/MainViewModel.java +++ b/app/src/main/java/com/readrops/app/viewmodels/MainViewModel.java @@ -237,7 +237,6 @@ public class MainViewModel extends AndroidViewModel { //endregion - //region Item read state public Completable setItemReadState(ItemWithFeed itemWithFeed, boolean read) { @@ -255,13 +254,10 @@ public class MainViewModel extends AndroidViewModel { } public Completable setAllItemsReadState(boolean read) { - return Completable.create(emitter -> { - if (queryBuilder.getFilterType() == FilterType.FEED_FILTER) - db.itemDao().setAllItemsReadState(queryBuilder.getFilterFeedId(), read ? 1 : 0); - else - db.itemDao().setAllItemsReadState(read ? 1 : 0); - emitter.onComplete(); - }); + if (queryBuilder.getFilterType() == FilterType.FEED_FILTER) + return repository.setAllFeedItemsReadState(queryBuilder.getFilterFeedId(), read); + else + return repository.setAllItemsReadState(read); } public Completable setItemReadItLater(int itemId) {