Delete model for Nextcloud News read state api calls and use a map instead

This commit is contained in:
Shinokuni 2020-01-15 19:00:28 +01:00
parent 188d2086dd
commit c5476199d8
3 changed files with 18 additions and 33 deletions

View File

@ -15,7 +15,6 @@ 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.NextNewsFolder;
import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsItemIds;
import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsUser;
import com.readrops.readropslibrary.utils.ConflictException;
import com.readrops.readropslibrary.utils.LibUtils;
@ -138,20 +137,27 @@ public class NextNewsAPI extends API<NextNewsService> {
}
private void putModifiedItems(NextNewsSyncData data, NextNewsSyncResult syncResult) throws IOException {
if (data.getReadItems().size() == 0 && data.getUnreadItems().size() == 0)
return;
if (!data.getReadItems().isEmpty()) {
Map<String, List<String>> itemIdsMap = new HashMap<>();
itemIdsMap.put("items", data.getReadItems());
Response readItemsResponse = api.setArticlesState(StateType.READ.name().toLowerCase(),
new NextNewsItemIds(data.getReadItems())).execute();
Response readItemsResponse = api.setArticlesState(StateType.READ.name().toLowerCase(),
itemIdsMap).execute();
Response unreadItemsResponse = api.setArticlesState(StateType.UNREAD.toString().toLowerCase(),
new NextNewsItemIds(data.getUnreadItems())).execute();
if (!readItemsResponse.isSuccessful())
syncResult.setError(true);
}
if (!readItemsResponse.isSuccessful())
syncResult.setError(true);
if (!data.getUnreadItems().isEmpty()) {
Map<String, List<String>> itemIdsMap = new HashMap<>();
itemIdsMap.put("items", data.getUnreadItems());
if (!unreadItemsResponse.isSuccessful())
syncResult.setError(true);
Response unreadItemsResponse = api.setArticlesState(StateType.UNREAD.toString().toLowerCase(),
itemIdsMap).execute();
if (!unreadItemsResponse.isSuccessful())
syncResult.setError(true);
}
}
public List<Folder> createFolder(NextNewsFolder folder) throws IOException, UnknownFormatException, ConflictException {

View File

@ -4,7 +4,6 @@ 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.NextNewsFolder;
import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsItemIds;
import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsUser;
import java.util.List;
@ -40,7 +39,7 @@ public interface NextNewsService {
Call<List<Item>> getNewItems(@Query("lastModified") long lastModified, @Query("type") int type);
@PUT("items/{stateType}/multiple")
Call<ResponseBody> setArticlesState(@Path("stateType") String stateType, @Body NextNewsItemIds items);
Call<ResponseBody> setArticlesState(@Path("stateType") String stateType, @Body Map<String, List<String>> itemIdsMap);
@POST("feeds")
Call<List<Feed>> createFeed(@Query("url") String url, @Query("folderId") int folderId);

View File

@ -1,20 +0,0 @@
package com.readrops.readropslibrary.services.nextcloudnews.json;
import java.util.List;
public class NextNewsItemIds {
private List<String> items;
public NextNewsItemIds(List<String> items) {
this.items = items;
}
public List<String> getItems() {
return items;
}
public void setItems(List<String> items) {
this.items = items;
}
}