Let items be removed from read it later category

This commit is contained in:
Shinokuni 2021-07-17 14:59:50 +02:00
parent ef195b4231
commit 4c618b4044
4 changed files with 18 additions and 14 deletions

View File

@ -430,27 +430,28 @@ public class MainActivity extends AppCompatActivity implements SwipeRefreshLayou
@Override
public void onSwipe(@NotNull RecyclerView.ViewHolder viewHolder, int direction) {
Item item = adapter.getItemWithFeed(viewHolder.getBindingAdapterPosition()).getItem();
if (direction == ItemTouchHelper.LEFT) { // set item read state
ItemWithFeed itemWithFeed = adapter.getItemWithFeed(viewHolder.getBindingAdapterPosition());
item.setRead(!item.isRead());
itemWithFeed.getItem().setRead(!itemWithFeed.getItem().isRead());
viewModel.setItemReadState(itemWithFeed)
viewModel.setItemReadState(item)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.doOnError(throwable -> Utils.showSnackbar(binding.mainRoot, throwable.getMessage()))
.subscribe();
adapter.notifyItemChanged(viewHolder.getBindingAdapterPosition());
} else { // add item to read it later section
viewModel.setItemReadItLater((int) adapter.getItemId(viewHolder.getBindingAdapterPosition()))
} else { // set item read it later state
item.setReadItLater(!item.isReadItLater());
viewModel.setItemReadItLater(item.isReadItLater(), item.getId())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.doOnError(throwable -> Utils.showSnackbar(binding.mainRoot, throwable.getMessage()))
.subscribe();
if (viewModel.getFilterType() == FilterType.READ_IT_LATER_FILTER)
adapter.notifyItemChanged(viewHolder.getBindingAdapterPosition());
}
adapter.notifyItemChanged(viewHolder.getBindingAdapterPosition());
}
@Override

View File

@ -249,8 +249,8 @@ public class MainViewModel extends ViewModel {
return repository.setAllItemsReadState(read);
}
public Completable setItemReadItLater(int itemId) {
return database.itemDao().setReadItLater(itemId);
public Completable setItemReadItLater(boolean readLater, int itemId) {
return database.itemDao().setReadItLater(readLater, itemId);
}
//endregion

View File

@ -166,7 +166,10 @@ class SyncWorker(context: Context, parameters: WorkerParameters) : Worker(contex
val itemId = intent?.getIntExtra(ReadropsKeys.ITEM_ID, 0)!!
with(get<Database>()) {
itemDao().setReadItLater(itemId)
val item = itemDao().select(itemId)
item.isReadItLater = !item.isReadItLater
itemDao().setReadItLater(item.isReadItLater, itemId)
.subscribeOn(Schedulers.io())
.subscribe()
}

View File

@ -49,8 +49,8 @@ public interface ItemDao extends BaseDao<Item> {
@Query("Update Item set read = :readState Where feed_id = :feedId")
Completable setAllFeedItemsReadState(int feedId, int readState);
@Query("Update Item set read_it_later = 1 Where id = :itemId")
Completable setReadItLater(int itemId);
@Query("Update Item set read_it_later = :readLater Where id = :itemId")
Completable setReadItLater(boolean readLater, int itemId);
@Query("Select count(*) From Item Where feed_id = :feedId And read = 0")
int getUnreadCount(int feedId);