From af5138c1cb9507106be87a3286fd1c3ff96e8198 Mon Sep 17 00:00:00 2001 From: Shinokuni Date: Fri, 2 Jul 2021 14:30:01 +0200 Subject: [PATCH] =?UTF-8?q?Insert=20starred=20items=20at=20initial=20synch?= =?UTF-8?q?ronisation=20and=20don=C2=B4t=20forget=20starred=20items=20whic?= =?UTF-8?q?h=20are=20read?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/repositories/FreshRSSRepository.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/readrops/app/repositories/FreshRSSRepository.java b/app/src/main/java/com/readrops/app/repositories/FreshRSSRepository.java index a0398ebf..5bd7d593 100644 --- a/app/src/main/java/com/readrops/app/repositories/FreshRSSRepository.java +++ b/app/src/main/java/com/readrops/app/repositories/FreshRSSRepository.java @@ -130,6 +130,9 @@ public class FreshRSSRepository extends ARepository { insertItems(syncResult.getItems()); logger.addSplit("items insertion"); + insertItems(syncResult.getStarredItems()); + logger.addSplit("starred items insertion"); + insertItemsIds(syncResult.getUnreadIds(), syncResult.getStarredIds()); logger.addSplit("insert and update items ids"); @@ -256,10 +259,20 @@ public class FreshRSSRepository extends ARepository { private void insertItemsIds(List unreadIds, List starredIds) { database.itemStateDao().deleteItemsStates(account.getId()); - database.itemStateDao().insertItemStates(unreadIds.stream().map(id -> - new ItemState(0, false, starredIds.stream() - .anyMatch(starredId -> starredId.equals(id)), id, account.getId())) - .collect(Collectors.toList())); + database.itemStateDao().insertItemStates(unreadIds.stream().map(id -> { + boolean starred = starredIds.stream().filter(starredId -> starredId.equals(id)).count() == 1; + starredIds.remove(id); + + return new ItemState(0, false, starred, id, account.getId()); + } + ).collect(Collectors.toList())); + + // insert starred items ids which are read + if (!starredIds.isEmpty()) { + database.itemStateDao().insertItemStates(starredIds.stream().map(id -> + new ItemState(0, true, true, id, account.getId())) + .collect(Collectors.toList())); + } } }