Use a constant for greader read string and add comments for FreshRSSAPI
This commit is contained in:
parent
421794f995
commit
dd2903dd32
@ -1,6 +1,7 @@
|
||||
package com.readrops.readropslibrary.services.freshrss;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.readrops.readropslibrary.services.API;
|
||||
import com.readrops.readropslibrary.services.Credentials;
|
||||
@ -21,6 +22,8 @@ import okhttp3.RequestBody;
|
||||
|
||||
public class FreshRSSAPI extends API<FreshRSSService> {
|
||||
|
||||
private static final String GOOGLE_READ = "user/-/state/com.google/read";
|
||||
|
||||
public FreshRSSAPI(Credentials credentials) {
|
||||
super(credentials, FreshRSSService.class, FreshRSSService.END_POINT);
|
||||
}
|
||||
@ -48,16 +51,34 @@ public class FreshRSSAPI extends API<FreshRSSService> {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a write token to modify feeds, folders and items on the server
|
||||
*
|
||||
* @return the write token generated by the server
|
||||
*/
|
||||
public Single<String> getWriteToken() {
|
||||
return api.getWriteToken()
|
||||
.flatMap(responseBody -> Single.just(responseBody.string()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve user information : name, email, id, profileId
|
||||
*
|
||||
* @return user information
|
||||
*/
|
||||
public Single<FreshRSSUserInfo> getUserInfo() {
|
||||
return api.getUserInfo();
|
||||
}
|
||||
|
||||
public Single<FreshRSSSyncResult> sync(@NonNull SyncType syncType, @NonNull FreshRSSSyncData syncData, String writeToken) {
|
||||
/**
|
||||
* Synchronize feeds, folders, items and push read/unread items
|
||||
*
|
||||
* @param syncType INITIAL or CLASSIC
|
||||
* @param syncData data to sync (read/unread items ids, lastModified timestamp)
|
||||
* @param writeToken token for making modifications on the server
|
||||
* @return the result of the synchronization
|
||||
*/
|
||||
public Single<FreshRSSSyncResult> sync(@NonNull SyncType syncType, @NonNull FreshRSSSyncData syncData, @NonNull String writeToken) {
|
||||
FreshRSSSyncResult syncResult = new FreshRSSSyncResult();
|
||||
|
||||
return setItemsReadState(syncData, writeToken)
|
||||
@ -72,9 +93,9 @@ public class FreshRSSAPI extends API<FreshRSSService> {
|
||||
|
||||
switch (syncType) {
|
||||
case INITIAL_SYNC:
|
||||
return getItems(EXCLUDE_ITEMS.EXCLUDE_READ_ITEMS.value, 10000, null);
|
||||
return getItems(GOOGLE_READ, 10000, null);
|
||||
case CLASSIC_SYNC:
|
||||
return getItems(EXCLUDE_ITEMS.EXCLUDE_READ_ITEMS.value, 10000, syncData.getLastModified());
|
||||
return getItems(GOOGLE_READ, 10000, syncData.getLastModified());
|
||||
}
|
||||
|
||||
return Single.error(new Exception("Unknown sync type"));
|
||||
@ -87,50 +108,129 @@ public class FreshRSSAPI extends API<FreshRSSService> {
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the feeds folders
|
||||
*
|
||||
* @return the feeds folders
|
||||
*/
|
||||
public Single<FreshRSSFolders> getFolders() {
|
||||
return api.getFolders();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the feeds
|
||||
*
|
||||
* @return the feeds
|
||||
*/
|
||||
public Single<FreshRSSFeeds> getFeeds() {
|
||||
return api.getFeeds();
|
||||
}
|
||||
|
||||
public Single<FreshRSSItems> getItems(String excludeTarget, Integer max, Long lastModified) {
|
||||
/**
|
||||
* Fetch the items
|
||||
*
|
||||
* @param excludeTarget type of items to exclude (currently only read items)
|
||||
* @param max max number of items to fetch
|
||||
* @param lastModified fetch only items created after this timestamp
|
||||
* @return the items
|
||||
*/
|
||||
public Single<FreshRSSItems> getItems(@NonNull String excludeTarget, @NonNull Integer max, @Nullable Long lastModified) {
|
||||
return api.getItems(excludeTarget, max, lastModified);
|
||||
}
|
||||
|
||||
public Completable markItemsReadUnread(Boolean read, List<String> itemIds, String token) {
|
||||
|
||||
/**
|
||||
* Mark items read or unread
|
||||
*
|
||||
* @param read true for read, false for unread
|
||||
* @param itemIds items ids to mark
|
||||
* @param token token for modifications
|
||||
* @return Completable
|
||||
*/
|
||||
public Completable markItemsReadUnread(@NonNull Boolean read, @NonNull List<String> itemIds, @NonNull String token) {
|
||||
if (read)
|
||||
return api.setItemsReadState(token, EXCLUDE_ITEMS.EXCLUDE_READ_ITEMS.value, null, itemIds);
|
||||
return api.setItemsReadState(token, GOOGLE_READ, null, itemIds);
|
||||
else
|
||||
return api.setItemsReadState(token, null, EXCLUDE_ITEMS.EXCLUDE_READ_ITEMS.value, itemIds);
|
||||
return api.setItemsReadState(token, null, GOOGLE_READ, itemIds);
|
||||
}
|
||||
|
||||
public Completable createFeed(String token, String feedUrl) {
|
||||
/**
|
||||
* Create a new feed
|
||||
*
|
||||
* @param token token for modifications
|
||||
* @param feedUrl url of the feed to parse
|
||||
* @return Completable
|
||||
*/
|
||||
public Completable createFeed(@NonNull String token, @NonNull String feedUrl) {
|
||||
return api.createOrDeleteFeed(token, "feed/" + feedUrl, "subscribe");
|
||||
}
|
||||
|
||||
public Completable deleteFeed(String token, String feedUrl) {
|
||||
/**
|
||||
* Delete a feed
|
||||
*
|
||||
* @param token token for modifications
|
||||
* @param feedUrl url of the feed to delete
|
||||
* @return Completable
|
||||
*/
|
||||
public Completable deleteFeed(@NonNull String token, @NonNull String feedUrl) {
|
||||
return api.createOrDeleteFeed(token, "feed/" + feedUrl, "unsubscribe");
|
||||
}
|
||||
|
||||
public Completable updateFeed(String token, String feedUrl, String title, String folderId) {
|
||||
/**
|
||||
* Update feed title and folder
|
||||
*
|
||||
* @param token token for modifications
|
||||
* @param feedUrl url of the feed to update
|
||||
* @param title new title
|
||||
* @param folderId id of the new folder
|
||||
* @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");
|
||||
}
|
||||
|
||||
public Completable createFolder(String token, String tagName) {
|
||||
/**
|
||||
* Create a new folder
|
||||
*
|
||||
* @param token token for modifications
|
||||
* @param tagName name of the new folder
|
||||
* @return Completable
|
||||
*/
|
||||
public Completable createFolder(@NonNull String token, @NonNull String tagName) {
|
||||
return api.createFolder(token, "user/-/label/" + tagName);
|
||||
}
|
||||
|
||||
public Completable updateFolder(String token, String folderId, String name) {
|
||||
/**
|
||||
* Update folder name
|
||||
*
|
||||
* @param token token for modifications
|
||||
* @param folderId id of the folder
|
||||
* @param name new folder name
|
||||
* @return Completable
|
||||
*/
|
||||
public Completable updateFolder(@NonNull String token, @NonNull String folderId, @NonNull String name) {
|
||||
return api.updateFolder(token, folderId, "user/-/label/" + name);
|
||||
}
|
||||
|
||||
public Completable deleteFolder(String token, String folderId) {
|
||||
/**
|
||||
* Delete a folder
|
||||
*
|
||||
* @param token token for modifications
|
||||
* @param folderId id of the folder to delete
|
||||
* @return Completable
|
||||
*/
|
||||
public Completable deleteFolder(@NonNull String token, @NonNull String folderId) {
|
||||
return api.deleteFolder(token, folderId);
|
||||
}
|
||||
|
||||
private Completable setItemsReadState(FreshRSSSyncData syncData, String token) {
|
||||
/**
|
||||
* Set the state of items
|
||||
*
|
||||
* @param syncData data containing items to mark
|
||||
* @param token token for modifications
|
||||
* @return A concatenation of two completable (read and unread completable)
|
||||
*/
|
||||
private Completable setItemsReadState(@NonNull FreshRSSSyncData syncData, @NonNull String token) {
|
||||
Completable readItemsCompletable;
|
||||
if (syncData.getReadItemsIds().isEmpty())
|
||||
readItemsCompletable = Completable.complete();
|
||||
@ -145,14 +245,4 @@ public class FreshRSSAPI extends API<FreshRSSService> {
|
||||
|
||||
return readItemsCompletable.concatWith(unreadItemsCompletable);
|
||||
}
|
||||
|
||||
public enum EXCLUDE_ITEMS {
|
||||
EXCLUDE_READ_ITEMS("user/-/state/com.google/read");
|
||||
|
||||
String value;
|
||||
|
||||
EXCLUDE_ITEMS(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user