From 4454c5c02850c0c12f2e5c0dac91661e4f559ab4 Mon Sep 17 00:00:00 2001 From: Shinokuni Date: Mon, 13 Jan 2020 11:25:14 +0100 Subject: [PATCH] Use adapters with Nextcloud News create feed and folder api calls --- .../app/repositories/NextNewsRepository.java | 12 +++++------- .../services/nextcloudnews/NextNewsAPI.java | 17 +++++++---------- .../services/nextcloudnews/NextNewsService.java | 6 ++---- 3 files changed, 14 insertions(+), 21 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 5710cd18..238a5867 100644 --- a/app/src/main/java/com/readrops/app/repositories/NextNewsRepository.java +++ b/app/src/main/java/com/readrops/app/repositories/NextNewsRepository.java @@ -20,9 +20,7 @@ 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.NextNewsFeed; -import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsFeeds; import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsFolder; -import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsFolders; import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsRenameFeed; import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsUser; import com.readrops.readropslibrary.utils.UnknownFormatException; @@ -144,12 +142,12 @@ public class NextNewsRepository extends ARepository { FeedInsertionResult insertionResult = new FeedInsertionResult(); try { - NextNewsFeeds nextNewsFeeds = api.createFeed(result.getUrl(), 0); + List nextNewsFeeds = api.createFeed(result.getUrl(), 0); if (nextNewsFeeds != null) { - /*List newFeeds = insertFeeds(nextNewsFeeds.getFeeds()); + List newFeeds = insertFeeds(nextNewsFeeds); // there is always only one object in the list, see nextcloud news api doc - insertionResult.setFeed(newFeeds.get(0));*/ + insertionResult.setFeed(newFeeds.get(0)); } else insertionResult.setInsertionError(FeedInsertionResult.FeedInsertionError.UNKNOWN_ERROR); @@ -216,10 +214,10 @@ public class NextNewsRepository extends ARepository { return Single.create(emitter -> { try { int folderRemoteId = folder.getRemoteId() == null ? 0 : Integer.parseInt(folder.getRemoteId()); - NextNewsFolders folders = api.createFolder(new NextNewsFolder(folderRemoteId, folder.getName())); + List folders = api.createFolder(new NextNewsFolder(folderRemoteId, folder.getName())); if (folders != null) { - NextNewsFolder nextNewsFolder = folders.getFolders().get(0); // always only one item returned by the server, see doc + Folder nextNewsFolder = folders.get(0); // always only one item returned by the server, see doc folder.setName(nextNewsFolder.getName()); folder.setRemoteId(String.valueOf(nextNewsFolder.getId())); diff --git a/readropslibrary/src/main/java/com/readrops/readropslibrary/services/nextcloudnews/NextNewsAPI.java b/readropslibrary/src/main/java/com/readrops/readropslibrary/services/nextcloudnews/NextNewsAPI.java index 37fad5f7..db073610 100644 --- a/readropslibrary/src/main/java/com/readrops/readropslibrary/services/nextcloudnews/NextNewsAPI.java +++ b/readropslibrary/src/main/java/com/readrops/readropslibrary/services/nextcloudnews/NextNewsAPI.java @@ -15,9 +15,7 @@ import com.readrops.readropslibrary.services.nextcloudnews.adapters.NextNewsFeed import com.readrops.readropslibrary.services.nextcloudnews.adapters.NextNewsFoldersAdapter; import com.readrops.readropslibrary.services.nextcloudnews.adapters.NextNewsItemsAdapter; import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsFeed; -import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsFeeds; import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsFolder; -import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsFolders; import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsItemIds; import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsRenameFeed; import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsUser; @@ -28,6 +26,7 @@ import com.squareup.moshi.Moshi; import com.squareup.moshi.Types; import java.io.IOException; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -61,10 +60,9 @@ public class NextNewsAPI extends API { return response.body(); } - public @Nullable - NextNewsFeeds createFeed(String url, int folderId) - throws IOException, UnknownFormatException { - Response response = api.createFeed(url, folderId).execute(); + @Nullable + public List createFeed(String url, int folderId) throws IOException, UnknownFormatException { + Response> response = api.createFeed(url, folderId).execute(); if (!response.isSuccessful()) { if (response.code() == LibUtils.HTTP_UNPROCESSABLE) @@ -158,9 +156,8 @@ public class NextNewsAPI extends API { syncResult.setError(true); } - public @Nullable - NextNewsFolders createFolder(NextNewsFolder folder) throws IOException, UnknownFormatException, ConflictException { - Response foldersResponse = api.createFolder(folder).execute(); + public List createFolder(NextNewsFolder folder) throws IOException, UnknownFormatException, ConflictException { + Response> foldersResponse = api.createFolder(folder).execute(); if (foldersResponse.isSuccessful()) return foldersResponse.body(); @@ -169,7 +166,7 @@ public class NextNewsAPI extends API { else if (foldersResponse.code() == LibUtils.HTTP_CONFLICT) throw new ConflictException(); else - return null; + return new ArrayList<>(); } public boolean deleteFolder(NextNewsFolder folder) throws IOException { diff --git a/readropslibrary/src/main/java/com/readrops/readropslibrary/services/nextcloudnews/NextNewsService.java b/readropslibrary/src/main/java/com/readrops/readropslibrary/services/nextcloudnews/NextNewsService.java index 6c491e51..04deeb2f 100644 --- a/readropslibrary/src/main/java/com/readrops/readropslibrary/services/nextcloudnews/NextNewsService.java +++ b/readropslibrary/src/main/java/com/readrops/readropslibrary/services/nextcloudnews/NextNewsService.java @@ -3,9 +3,7 @@ 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 com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsFeeds; import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsFolder; -import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsFolders; import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsItemIds; import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsRenameFeed; import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsUser; @@ -46,7 +44,7 @@ public interface NextNewsService { Call setArticlesState(@Path("stateType") String stateType, @Body NextNewsItemIds items); @POST("feeds") - Call createFeed(@Query("url") String url, @Query("folderId") int folderId); + Call> createFeed(@Query("url") String url, @Query("folderId") int folderId); @DELETE("feeds/{feedId}") Call deleteFeed(@Path("feedId") int feedId); @@ -58,7 +56,7 @@ public interface NextNewsService { Call renameFeed(@Path("feedId") int feedId, @Body NextNewsRenameFeed feed); @POST("folders") - Call createFolder(@Body NextNewsFolder folder); + Call> createFolder(@Body NextNewsFolder folder); @DELETE("folders/{folderId}") Call deleteFolder(@Path("folderId") int folderId);