mirror of https://github.com/readrops/Readrops.git
Add adapter for Nextcloud News folders api call
This commit is contained in:
parent
fca4b7f513
commit
a179a18432
|
@ -112,8 +112,8 @@ public class NextNewsRepository extends ARepository<NextNewsAPI> {
|
|||
|
||||
if (!syncResult.isError()) {
|
||||
|
||||
/*insertFolders(syncResult.getFolders());
|
||||
timings.addSplit("insert folders");*/
|
||||
insertFolders(syncResult.getFolders());
|
||||
timings.addSplit("insert folders");
|
||||
|
||||
insertFeeds(syncResult.getFeeds());
|
||||
timings.addSplit("insert feeds");
|
||||
|
@ -284,18 +284,12 @@ public class NextNewsRepository extends ARepository<NextNewsAPI> {
|
|||
return insertedFeeds;
|
||||
}
|
||||
|
||||
private void insertFolders(List<NextNewsFolder> nextNewsFolders) {
|
||||
List<Folder> folders = new ArrayList<>();
|
||||
|
||||
for (NextNewsFolder nextNewsFolder : nextNewsFolders) {
|
||||
Folder folder = new Folder(nextNewsFolder.getName());
|
||||
private void insertFolders(List<Folder> nextNewsFolders) {
|
||||
for (Folder folder : nextNewsFolders) {
|
||||
folder.setAccountId(account.getId());
|
||||
folder.setRemoteId(String.valueOf(nextNewsFolder.getId()));
|
||||
|
||||
folders.add(folder);
|
||||
}
|
||||
|
||||
database.folderDao().foldersUpsert(folders, account);
|
||||
database.folderDao().foldersUpsert(nextNewsFolders, account);
|
||||
}
|
||||
|
||||
private void insertItems(List<NextNewsItem> items, boolean initialSync) {
|
||||
|
|
|
@ -6,10 +6,12 @@ import androidx.annotation.NonNull;
|
|||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.readrops.readropsdb.entities.Feed;
|
||||
import com.readrops.readropsdb.entities.Folder;
|
||||
import com.readrops.readropslibrary.services.API;
|
||||
import com.readrops.readropslibrary.services.Credentials;
|
||||
import com.readrops.readropslibrary.services.SyncType;
|
||||
import com.readrops.readropslibrary.services.nextcloudnews.adapters.NextNewsFeedsAdapter;
|
||||
import com.readrops.readropslibrary.services.nextcloudnews.adapters.NextNewsFoldersAdapter;
|
||||
import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsFeed;
|
||||
import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsFeeds;
|
||||
import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsFolder;
|
||||
|
@ -42,6 +44,7 @@ public class NextNewsAPI extends API<NextNewsService> {
|
|||
protected Moshi buildMoshi() {
|
||||
return new Moshi.Builder()
|
||||
.add(new NextNewsFeedsAdapter())
|
||||
.add(new NextNewsFoldersAdapter())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
@ -121,14 +124,14 @@ public class NextNewsAPI extends API<NextNewsService> {
|
|||
if (!feedResponse.isSuccessful())
|
||||
syncResult.setError(true);
|
||||
|
||||
/*Response<NextNewsFolders> folderResponse = api.getFolders().execute();
|
||||
NextNewsFolders folderList = folderResponse.body();
|
||||
Response<List<Folder>> folderResponse = api.getFolders().execute();
|
||||
List<Folder> folderList = folderResponse.body();
|
||||
|
||||
if (!folderResponse.isSuccessful())
|
||||
syncResult.setError(true);
|
||||
|
||||
if (folderList != null)
|
||||
syncResult.setFolders(folderList.getFolders());*/
|
||||
syncResult.setFolders(folderList);
|
||||
|
||||
if (feedList != null)
|
||||
syncResult.setFeeds(feedList);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.readrops.readropslibrary.services.nextcloudnews;
|
||||
|
||||
import com.readrops.readropsdb.entities.Feed;
|
||||
import com.readrops.readropsdb.entities.Folder;
|
||||
import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsFeeds;
|
||||
import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsFolder;
|
||||
import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsFolders;
|
||||
|
@ -30,7 +31,7 @@ public interface NextNewsService {
|
|||
Call<NextNewsUser> getUser();
|
||||
|
||||
@GET("folders")
|
||||
Call<NextNewsFolders> getFolders();
|
||||
Call<List<Folder>> getFolders();
|
||||
|
||||
@GET("feeds")
|
||||
Call<List<Feed>> getFeeds();
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
package com.readrops.readropslibrary.services.nextcloudnews;
|
||||
|
||||
import com.readrops.readropsdb.entities.Feed;
|
||||
import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsFolder;
|
||||
import com.readrops.readropsdb.entities.Folder;
|
||||
import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsItem;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class NextNewsSyncResult {
|
||||
|
||||
private List<NextNewsFolder> folders;
|
||||
private List<Folder> folders;
|
||||
|
||||
private List<Feed> feeds;
|
||||
|
||||
|
@ -20,11 +20,11 @@ public class NextNewsSyncResult {
|
|||
// empty constructor
|
||||
}
|
||||
|
||||
public List<NextNewsFolder> getFolders() {
|
||||
public List<Folder> getFolders() {
|
||||
return folders;
|
||||
}
|
||||
|
||||
public void setFolders(List<NextNewsFolder> folders) {
|
||||
public void setFolders(List<Folder> folders) {
|
||||
this.folders = folders;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
package com.readrops.readropslibrary.services.nextcloudnews.adapters
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import com.readrops.readropsdb.entities.Folder
|
||||
import com.squareup.moshi.FromJson
|
||||
import com.squareup.moshi.JsonReader
|
||||
import com.squareup.moshi.ToJson
|
||||
|
||||
class NextNewsFoldersAdapter {
|
||||
|
||||
@ToJson
|
||||
fun toJson(folder: Folder): String = ""
|
||||
|
||||
@SuppressLint("CheckResult")
|
||||
@FromJson
|
||||
fun fromJson(reader: JsonReader): List<Folder> {
|
||||
val folders = mutableListOf<Folder>()
|
||||
|
||||
reader.beginObject()
|
||||
reader.nextName() // "folders", beginning of folders array
|
||||
reader.beginArray()
|
||||
|
||||
while (reader.hasNext()) {
|
||||
val folder = Folder()
|
||||
reader.beginObject()
|
||||
|
||||
while (reader.hasNext()) {
|
||||
with(folder) {
|
||||
when (reader.selectName(NAMES)) {
|
||||
0 -> remoteId = reader.nextInt().toString()
|
||||
1 -> name = reader.nextString()
|
||||
else -> reader.skipValue()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
folders += folder
|
||||
reader.endObject()
|
||||
}
|
||||
|
||||
reader.endArray()
|
||||
reader.endObject()
|
||||
|
||||
return folders
|
||||
}
|
||||
|
||||
companion object {
|
||||
val NAMES: JsonReader.Options = JsonReader.Options.of("id", "name")
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue