Use a single SyncResult class for both FreshRSS and Nextcloud News

This commit is contained in:
Shinokuni 2020-02-05 17:25:39 +01:00
parent cc65dcdc25
commit 237a2fc9c9
6 changed files with 28 additions and 120 deletions

View File

@ -15,10 +15,10 @@ import com.readrops.readropsdb.entities.Folder;
import com.readrops.readropsdb.entities.Item;
import com.readrops.readropsdb.entities.account.Account;
import com.readrops.readropslibrary.services.Credentials;
import com.readrops.readropslibrary.services.SyncResult;
import com.readrops.readropslibrary.services.SyncType;
import com.readrops.readropslibrary.services.nextcloudnews.NextNewsAPI;
import com.readrops.readropslibrary.services.nextcloudnews.NextNewsSyncData;
import com.readrops.readropslibrary.services.nextcloudnews.NextNewsSyncResult;
import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsUser;
import com.readrops.readropslibrary.utils.UnknownFormatException;
@ -100,7 +100,7 @@ public class NextNewsRepository extends ARepository<NextNewsAPI> {
}
TimingLogger timings = new TimingLogger(TAG, "nextcloud news " + syncType.name().toLowerCase());
NextNewsSyncResult syncResult = api.sync(syncType, syncData);
SyncResult syncResult = api.sync(syncType, syncData);
timings.addSplit("server queries");
if (!syncResult.isError()) {

View File

@ -0,0 +1,16 @@
package com.readrops.readropslibrary.services
import com.readrops.readropsdb.entities.Feed
import com.readrops.readropsdb.entities.Folder
import com.readrops.readropsdb.entities.Item
class SyncResult {
var items: List<Item> = listOf()
var feeds: List<Feed> = listOf()
var folders: List<Folder> = listOf()
var isError: Boolean = false
}

View File

@ -8,6 +8,7 @@ import com.readrops.readropsdb.entities.Folder;
import com.readrops.readropsdb.entities.Item;
import com.readrops.readropslibrary.services.API;
import com.readrops.readropslibrary.services.Credentials;
import com.readrops.readropslibrary.services.SyncResult;
import com.readrops.readropslibrary.services.SyncType;
import com.readrops.readropslibrary.services.freshrss.adapters.FreshRSSFeedsAdapter;
import com.readrops.readropslibrary.services.freshrss.adapters.FreshRSSFoldersAdapter;
@ -94,8 +95,8 @@ public class FreshRSSAPI extends API<FreshRSSService> {
* @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();
public Single<SyncResult> sync(@NonNull SyncType syncType, @NonNull FreshRSSSyncData syncData, @NonNull String writeToken) {
SyncResult syncResult = new SyncResult();
return setItemsReadState(syncData, writeToken)
.andThen(getFolders()

View File

@ -1,56 +0,0 @@
package com.readrops.readropslibrary.services.freshrss;
import com.readrops.readropsdb.entities.Feed;
import com.readrops.readropsdb.entities.Folder;
import com.readrops.readropsdb.entities.Item;
import java.util.ArrayList;
import java.util.List;
public class FreshRSSSyncResult {
private List<Folder> folders;
private List<Feed> feeds;
private List<Item> items;
private long lastUpdated;
public FreshRSSSyncResult() {
feeds = new ArrayList<>();
items = new ArrayList<>();
}
public List<Feed> getFeeds() {
return feeds;
}
public void setFeeds(List<Feed> feeds) {
this.feeds = feeds;
}
public List<Item> getItems() {
return items;
}
public void setItems(List<Item> items) {
this.items = items;
}
public long getLastUpdated() {
return lastUpdated;
}
public void setLastUpdated(long lastUpdated) {
this.lastUpdated = lastUpdated;
}
public List<Folder> getFolders() {
return folders;
}
public void setFolders(List<Folder> folders) {
this.folders = folders;
}
}

View File

@ -10,6 +10,7 @@ import com.readrops.readropsdb.entities.Folder;
import com.readrops.readropsdb.entities.Item;
import com.readrops.readropslibrary.services.API;
import com.readrops.readropslibrary.services.Credentials;
import com.readrops.readropslibrary.services.SyncResult;
import com.readrops.readropslibrary.services.SyncType;
import com.readrops.readropslibrary.services.nextcloudnews.adapters.NextNewsFeedsAdapter;
import com.readrops.readropslibrary.services.nextcloudnews.adapters.NextNewsFoldersAdapter;
@ -70,8 +71,8 @@ public class NextNewsAPI extends API<NextNewsService> {
return response.body();
}
public NextNewsSyncResult sync(@NonNull SyncType syncType, @Nullable NextNewsSyncData data) throws IOException {
NextNewsSyncResult syncResult = new NextNewsSyncResult();
public SyncResult sync(@NonNull SyncType syncType, @Nullable NextNewsSyncData data) throws IOException {
SyncResult syncResult = new SyncResult();
switch (syncType) {
case INITIAL_SYNC:
initialSync(syncResult);
@ -87,7 +88,7 @@ public class NextNewsAPI extends API<NextNewsService> {
return syncResult;
}
private void initialSync(NextNewsSyncResult syncResult) throws IOException {
private void initialSync(SyncResult syncResult) throws IOException {
getFeedsAndFolders(syncResult);
Response<List<Item>> itemsResponse = api.getItems(3, false, MAX_ITEMS).execute();
@ -100,7 +101,7 @@ public class NextNewsAPI extends API<NextNewsService> {
syncResult.setItems(itemList);
}
private void classicSync(NextNewsSyncResult syncResult, NextNewsSyncData data) throws IOException {
private void classicSync(SyncResult syncResult, NextNewsSyncData data) throws IOException {
putModifiedItems(data, syncResult);
getFeedsAndFolders(syncResult);
@ -114,7 +115,7 @@ public class NextNewsAPI extends API<NextNewsService> {
syncResult.setItems(itemList);
}
private void getFeedsAndFolders(NextNewsSyncResult syncResult) throws IOException {
private void getFeedsAndFolders(SyncResult syncResult) throws IOException {
Response<List<Feed>> feedResponse = api.getFeeds().execute();
List<Feed> feedList = feedResponse.body();
@ -135,7 +136,7 @@ public class NextNewsAPI extends API<NextNewsService> {
}
private void putModifiedItems(NextNewsSyncData data, NextNewsSyncResult syncResult) throws IOException {
private void putModifiedItems(NextNewsSyncData data, SyncResult syncResult) throws IOException {
if (!data.getReadItems().isEmpty()) {
Map<String, List<String>> itemIdsMap = new HashMap<>();
itemIdsMap.put("items", data.getReadItems());

View File

@ -1,54 +0,0 @@
package com.readrops.readropslibrary.services.nextcloudnews;
import com.readrops.readropsdb.entities.Feed;
import com.readrops.readropsdb.entities.Folder;
import com.readrops.readropsdb.entities.Item;
import java.util.List;
public class NextNewsSyncResult {
private List<Folder> folders;
private List<Feed> feeds;
private List<Item> items;
private boolean error;
public NextNewsSyncResult() {
// empty constructor
}
public List<Folder> getFolders() {
return folders;
}
public void setFolders(List<Folder> folders) {
this.folders = folders;
}
public List<Feed> getFeeds() {
return feeds;
}
public void setFeeds(List<Feed> feeds) {
this.feeds = feeds;
}
public List<Item> getItems() {
return items;
}
public void setItems(List<Item> items) {
this.items = items;
}
public boolean isError() {
return error;
}
public void setError(boolean error) {
this.error = error;
}
}