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 5b9c5bb8..9ab07da9 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 @@ -64,4 +64,7 @@ public abstract class ItemDao implements BaseDao { @Query("Update Item set read_changed = 0 Where feed_id in (Select id From Feed Where account_id = :accountId)") public abstract void resetReadChanges(int accountId); + + @Query("Update Item set read = :read Where remoteId = :remoteId") + public abstract void setReadState(String remoteId, boolean read); } 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 46fe3642..bf4b8883 100644 --- a/app/src/main/java/com/readrops/app/repositories/FreshRSSRepository.java +++ b/app/src/main/java/com/readrops/app/repositories/FreshRSSRepository.java @@ -90,9 +90,9 @@ public class FreshRSSRepository extends ARepository { emitter.onSuccess(syncData); }).flatMap(syncData1 -> api.sync(syncType, syncData1, account.getWriteToken())) .flatMapObservable(syncResult -> { - insertFolders(syncResult.getFolders(), account); - insertFeeds(syncResult.getFeeds(), account); - insertItems(syncResult.getItems(), account, syncType == SyncType.INITIAL_SYNC); + insertFolders(syncResult.getFolders()); + insertFeeds(syncResult.getFeeds()); + insertItems(syncResult.getItems(), syncType == SyncType.INITIAL_SYNC); account.setLastModified(syncResult.getLastUpdated()); database.accountDao().updateLastModified(account.getId(), syncResult.getLastUpdated()); @@ -169,7 +169,7 @@ public class FreshRSSRepository extends ARepository { .andThen(super.deleteFolder(folder)); } - private List insertFeeds(List freshRSSFeeds, Account account) { + private void insertFeeds(List freshRSSFeeds) { List feeds = new ArrayList<>(); for (FreshRSSFeed freshRSSFeed : freshRSSFeeds) { @@ -184,10 +184,9 @@ public class FreshRSSRepository extends ARepository { setFaviconUtils(insertedFeeds); } - return insertedFeeds; } - private void insertFolders(List freshRSSFolders, Account account) { + private void insertFolders(List freshRSSFolders) { List folders = new ArrayList<>(); for (FreshRSSFolder freshRSSFolder : freshRSSFolders) { @@ -205,15 +204,15 @@ public class FreshRSSRepository extends ARepository { database.folderDao().foldersUpsert(folders, account); } - private void insertItems(List items, Account account, boolean initialSync) { + private void insertItems(List items, boolean initialSync) { List newItems = new ArrayList<>(); for (FreshRSSItem freshRSSItem : items) { int feedId = database.feedDao().getFeedIdByRemoteId(String.valueOf(freshRSSItem.getOrigin().getStreamId()), account.getId()); - if (!initialSync && feedId > 0) { - if (database.itemDao().remoteItemExists(freshRSSItem.getId(), feedId)) - break; + if (!initialSync && feedId > 0 && database.itemDao().remoteItemExists(freshRSSItem.getId(), feedId)) { + database.itemDao().setReadState(freshRSSItem.getId(), freshRSSItem.isRead()); + break; } Item item = ItemMatcher.freshRSSItemtoItem(freshRSSItem, feedId); diff --git a/app/src/main/java/com/readrops/app/utils/ItemMatcher.java b/app/src/main/java/com/readrops/app/utils/ItemMatcher.java index d4755576..d0e62ba0 100644 --- a/app/src/main/java/com/readrops/app/utils/ItemMatcher.java +++ b/app/src/main/java/com/readrops/app/utils/ItemMatcher.java @@ -57,6 +57,7 @@ public final class ItemMatcher { newItem.setLink(item.getAlternate().get(0).getHref()); newItem.setFeedId(feedId); newItem.setRemoteId(item.getId()); + newItem.setRead(item.isRead()); return newItem; } diff --git a/readropslibrary/src/main/java/com/readrops/readropslibrary/services/freshrss/FreshRSSAPI.java b/readropslibrary/src/main/java/com/readrops/readropslibrary/services/freshrss/FreshRSSAPI.java index d98bce84..8a680676 100644 --- a/readropslibrary/src/main/java/com/readrops/readropslibrary/services/freshrss/FreshRSSAPI.java +++ b/readropslibrary/src/main/java/com/readrops/readropslibrary/services/freshrss/FreshRSSAPI.java @@ -22,7 +22,9 @@ import okhttp3.RequestBody; public class FreshRSSAPI extends API { - private static final String GOOGLE_READ = "user/-/state/com.google/read"; + public static final String GOOGLE_READ = "user/-/state/com.google/read"; + + private static final String FEED_PREFIX = "feed/"; public FreshRSSAPI(Credentials credentials) { super(credentials, FreshRSSService.class, FreshRSSService.END_POINT); @@ -134,7 +136,7 @@ public class FreshRSSAPI extends API { * @param lastModified fetch only items created after this timestamp * @return the items */ - public Single getItems(@NonNull String excludeTarget, @NonNull Integer max, @Nullable Long lastModified) { + public Single getItems(@Nullable String excludeTarget, int max, @Nullable Long lastModified) { return api.getItems(excludeTarget, max, lastModified); } @@ -147,7 +149,7 @@ public class FreshRSSAPI extends API { * @param token token for modifications * @return Completable */ - public Completable markItemsReadUnread(@NonNull Boolean read, @NonNull List itemIds, @NonNull String token) { + public Completable markItemsReadUnread(boolean read, @NonNull List itemIds, @NonNull String token) { if (read) return api.setItemsReadState(token, GOOGLE_READ, null, itemIds); else @@ -162,7 +164,7 @@ public class FreshRSSAPI extends API { * @return Completable */ public Completable createFeed(@NonNull String token, @NonNull String feedUrl) { - return api.createOrDeleteFeed(token, "feed/" + feedUrl, "subscribe"); + return api.createOrDeleteFeed(token, FEED_PREFIX + feedUrl, "subscribe"); } /** @@ -173,7 +175,7 @@ public class FreshRSSAPI extends API { * @return Completable */ public Completable deleteFeed(@NonNull String token, @NonNull String feedUrl) { - return api.createOrDeleteFeed(token, "feed/" + feedUrl, "unsubscribe"); + return api.createOrDeleteFeed(token, FEED_PREFIX + feedUrl, "unsubscribe"); } /** @@ -186,7 +188,7 @@ public class FreshRSSAPI extends API { * @return Completable */ public Completable updateFeed(@NonNull String token, @NonNull String feedUrl, @NonNull String title, @NonNull String folderId) { - return api.updateFeed(token, "feed/" + feedUrl, title, folderId, "edit"); + return api.updateFeed(token, FEED_PREFIX + feedUrl, title, folderId, "edit"); } /** diff --git a/readropslibrary/src/main/java/com/readrops/readropslibrary/services/freshrss/FreshRSSService.java b/readropslibrary/src/main/java/com/readrops/readropslibrary/services/freshrss/FreshRSSService.java index 7a4f8216..80069f5e 100644 --- a/readropslibrary/src/main/java/com/readrops/readropslibrary/services/freshrss/FreshRSSService.java +++ b/readropslibrary/src/main/java/com/readrops/readropslibrary/services/freshrss/FreshRSSService.java @@ -35,7 +35,7 @@ public interface FreshRSSService { Single getFeeds(); @GET("reader/api/0/stream/contents/user/-/state/com.google/reading-list") - Single getItems(@Query("xt") String excludeTarget, @Query("n") Integer max, @Query("ot") Long lastModified); + Single getItems(@Query("xt") String excludeTarget, @Query("n") int max, @Query("ot") Long lastModified); @GET("reader/api/0/tag/list?output=json") Single getFolders(); diff --git a/readropslibrary/src/main/java/com/readrops/readropslibrary/services/freshrss/json/FreshRSSItem.java b/readropslibrary/src/main/java/com/readrops/readropslibrary/services/freshrss/json/FreshRSSItem.java index 16717655..a72aa7f3 100644 --- a/readropslibrary/src/main/java/com/readrops/readropslibrary/services/freshrss/json/FreshRSSItem.java +++ b/readropslibrary/src/main/java/com/readrops/readropslibrary/services/freshrss/json/FreshRSSItem.java @@ -1,6 +1,8 @@ package com.readrops.readropslibrary.services.freshrss.json; +import com.readrops.readropslibrary.services.freshrss.FreshRSSAPI; + import java.util.List; public class FreshRSSItem { @@ -105,4 +107,8 @@ public class FreshRSSItem { this.title = title; } + public boolean isRead() { + return categories.contains(FreshRSSAPI.GOOGLE_READ); + } + }