From 64d3f384be4c2741d72c596cdd767b1c860693ef Mon Sep 17 00:00:00 2001 From: Shinokuni Date: Thu, 6 Jun 2019 15:15:12 +0200 Subject: [PATCH] Fix item duplicates when getting last modified items --- .../readrops/app/repositories/NextNewsRepository.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/readrops/app/repositories/NextNewsRepository.java b/app/src/main/java/com/readrops/app/repositories/NextNewsRepository.java index 15726052..528269bf 100644 --- a/app/src/main/java/com/readrops/app/repositories/NextNewsRepository.java +++ b/app/src/main/java/com/readrops/app/repositories/NextNewsRepository.java @@ -95,7 +95,7 @@ public class NextNewsRepository extends ARepository { insertFeeds(syncResult.getFeeds(), account); timings.addSplit("insert feeds"); - insertItems(syncResult.getItems(), account); + insertItems(syncResult.getItems(), account, syncType == NextNewsAPI.SyncType.INITIAL_SYNC); timings.addSplit("insert items"); timings.dumpToLog(); @@ -187,17 +187,22 @@ public class NextNewsRepository extends ARepository { database.folderDao().insert(newFolders); } - private void insertItems(List items, Account account) { + private void insertItems(List items, Account account, boolean initialSync) { List newItems = new ArrayList<>(); for (NextNewsItem nextNewsItem : items) { + + if (!initialSync) { + if (database.itemDao().remoteItemExists(nextNewsItem.getId())) + break; + } + Feed feed = database.feedDao().getFeedByRemoteId(nextNewsItem.getFeedId(), account.getId()); Item item = ItemMatcher.nextNewsItemToItem(nextNewsItem, feed); item.setReadTime(Utils.readTimeFromString(item.getContent())); newItems.add(item); - } Collections.sort(newItems, Item::compareTo);