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 1ca42490..a10c51b7 100644 --- a/app/src/main/java/com/readrops/app/activities/MainActivity.java +++ b/app/src/main/java/com/readrops/app/activities/MainActivity.java @@ -94,6 +94,7 @@ public class MainActivity extends AppCompatActivity implements SwipeRefreshLayou private int feedCount; private int feedNb; private int filterFeedId; + private boolean readItLater; private boolean showReadItems; private ListSortType sortType; @@ -121,7 +122,7 @@ public class MainActivity extends AppCompatActivity implements SwipeRefreshLayou allItems = itemWithFeeds; if (!refreshLayout.isRefreshing()) - filterItems(0); + filterItems(filterFeedId); })); refreshLayout = findViewById(R.id.swipe_refresh_layout); @@ -157,13 +158,17 @@ public class MainActivity extends AppCompatActivity implements SwipeRefreshLayou switch (id) { case DrawerManager.ARTICLES_ITEM_ID: + readItLater = false; filterItems(0); break; case DrawerManager.READ_LATER_ID: + readItLater = true; + filterItems(0); break; } } else if (drawerItem instanceof SecondaryDrawerItem) { + readItLater = false; drawer.closeDrawer(); filterItems((int)drawerItem.getIdentifier()); } @@ -180,14 +185,20 @@ public class MainActivity extends AppCompatActivity implements SwipeRefreshLayou else showRead = true; // item unread - if (id == 0) - return showRead; - else - return object.getFeedId() == id && showRead; + if (id != 0) { + if (readItLater) + return object.getItem().isReadItLater() && object.getFeedId() == id && showRead; + else + return !object.getItem().isReadItLater() && object.getFeedId() == id && showRead; + } else { + if (readItLater) + return object.getItem().isReadItLater() && showRead; + else + return !object.getItem().isReadItLater() && showRead; + } }); sortItems(); - adapter.submitList(filteredItems); } @@ -374,14 +385,15 @@ public class MainActivity extends AppCompatActivity implements SwipeRefreshLayou itemWithFeed.getItem().setRead(!itemWithFeed.getItem().isRead()); - // work-around to undo swipe as only notifyItemChanged(position) can do it, - // but we need first to update the viewHolder. - adapter.notifyItemChanged(viewHolder.getAdapterPosition(), itemWithFeed); adapter.notifyItemChanged(viewHolder.getAdapterPosition()); - - } else { // add item to read it later section - adapter.notifyItemRemoved(viewHolder.getAdapterPosition()); + viewModel.setItemReadItLater((int) adapter.getItemId(viewHolder.getAdapterPosition())) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(); + + if (readItLater) + adapter.notifyItemChanged(viewHolder.getAdapterPosition()); } } @@ -569,6 +581,4 @@ public class MainActivity extends AppCompatActivity implements SwipeRefreshLayou NEWEST_TO_OLDEST, OLDEST_TO_NEWEST } - - } 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 e7a6bd49..9035c821 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 @@ -20,7 +20,7 @@ public interface ItemDao { @Query("Select * from Item Order By pub_date DESC") LiveData> getAll(); - @Query("Select Item.id, title, clean_description, image_link, pub_date, read, Feed.name, text_color, background_color, icon_url, read_time, Feed.id as feedId, Folder.id as folder_id, Folder.name as folder_name from Item Inner Join Feed, Folder on Item.feed_id = Feed.id And Folder.id = Feed.folder_id Order By Item.id DESC") + @Query("Select Item.id, title, clean_description, image_link, pub_date, read, read_it_later, Feed.name, text_color, background_color, icon_url, read_time, Feed.id as feedId, Folder.id as folder_id, Folder.name as folder_name from Item Inner Join Feed, Folder on Item.feed_id = Feed.id And Folder.id = Feed.folder_id Order By Item.id DESC") LiveData> getAllItemWithFeeds(); @Query("Select case When :guid In (Select guid from Item) Then 'true' else 'false' end") @@ -40,6 +40,9 @@ public interface ItemDao { @Query("Update Item set read = :readState Where id = :itemId") void setReadState(int itemId, int readState); + @Query("Update Item set read_it_later = 1 Where id = :itemId") + void setReadItLater(int itemId); + @Query("Select count(*) From Item Where feed_id = :feedId And read = 0") int getUnreadCount(int feedId); diff --git a/app/src/main/java/com/readrops/app/database/entities/Item.java b/app/src/main/java/com/readrops/app/database/entities/Item.java index 4e6a5cd0..6b14a6c5 100644 --- a/app/src/main/java/com/readrops/app/database/entities/Item.java +++ b/app/src/main/java/com/readrops/app/database/entities/Item.java @@ -60,6 +60,9 @@ public class Item implements Comparable { private boolean read; + @ColumnInfo(name = "read_it_later") + private boolean readItLater; + public int getId() { return id; } @@ -175,6 +178,14 @@ public class Item implements Comparable { this.read = read; } + public boolean isReadItLater() { + return readItLater; + } + + public void setReadItLater(boolean readItLater) { + this.readItLater = readItLater; + } + public static List itemsFromRSS(List items, Feed feed) throws ParseException { List dbItems = new ArrayList<>(); 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 cae77c83..aaffced6 100644 --- a/app/src/main/java/com/readrops/app/viewmodels/MainViewModel.java +++ b/app/src/main/java/com/readrops/app/viewmodels/MainViewModel.java @@ -82,4 +82,11 @@ public class MainViewModel extends AndroidViewModel { return Completable.concat(completableList); } + + public Completable setItemReadItLater(int itemId) { + return Completable.create(emitter -> { + db.itemDao().setReadItLater(itemId); + emitter.onComplete(); + }); + } } 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 b4230eab..1c5b15be 100644 --- a/app/src/main/java/com/readrops/app/views/MainItemListAdapter.java +++ b/app/src/main/java/com/readrops/app/views/MainItemListAdapter.java @@ -72,7 +72,9 @@ public class MainItemListAdapter extends ListAdapter