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()) {
|
if (!syncResult.isError()) {
|
||||||
|
|
||||||
/*insertFolders(syncResult.getFolders());
|
insertFolders(syncResult.getFolders());
|
||||||
timings.addSplit("insert folders");*/
|
timings.addSplit("insert folders");
|
||||||
|
|
||||||
insertFeeds(syncResult.getFeeds());
|
insertFeeds(syncResult.getFeeds());
|
||||||
timings.addSplit("insert feeds");
|
timings.addSplit("insert feeds");
|
||||||
|
@ -284,18 +284,12 @@ public class NextNewsRepository extends ARepository<NextNewsAPI> {
|
||||||
return insertedFeeds;
|
return insertedFeeds;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void insertFolders(List<NextNewsFolder> nextNewsFolders) {
|
private void insertFolders(List<Folder> nextNewsFolders) {
|
||||||
List<Folder> folders = new ArrayList<>();
|
for (Folder folder : nextNewsFolders) {
|
||||||
|
|
||||||
for (NextNewsFolder nextNewsFolder : nextNewsFolders) {
|
|
||||||
Folder folder = new Folder(nextNewsFolder.getName());
|
|
||||||
folder.setAccountId(account.getId());
|
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) {
|
private void insertItems(List<NextNewsItem> items, boolean initialSync) {
|
||||||
|
|
|
@ -6,10 +6,12 @@ import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import com.readrops.readropsdb.entities.Feed;
|
import com.readrops.readropsdb.entities.Feed;
|
||||||
|
import com.readrops.readropsdb.entities.Folder;
|
||||||
import com.readrops.readropslibrary.services.API;
|
import com.readrops.readropslibrary.services.API;
|
||||||
import com.readrops.readropslibrary.services.Credentials;
|
import com.readrops.readropslibrary.services.Credentials;
|
||||||
import com.readrops.readropslibrary.services.SyncType;
|
import com.readrops.readropslibrary.services.SyncType;
|
||||||
import com.readrops.readropslibrary.services.nextcloudnews.adapters.NextNewsFeedsAdapter;
|
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.NextNewsFeed;
|
||||||
import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsFeeds;
|
import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsFeeds;
|
||||||
import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsFolder;
|
import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsFolder;
|
||||||
|
@ -42,6 +44,7 @@ public class NextNewsAPI extends API<NextNewsService> {
|
||||||
protected Moshi buildMoshi() {
|
protected Moshi buildMoshi() {
|
||||||
return new Moshi.Builder()
|
return new Moshi.Builder()
|
||||||
.add(new NextNewsFeedsAdapter())
|
.add(new NextNewsFeedsAdapter())
|
||||||
|
.add(new NextNewsFoldersAdapter())
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,14 +124,14 @@ public class NextNewsAPI extends API<NextNewsService> {
|
||||||
if (!feedResponse.isSuccessful())
|
if (!feedResponse.isSuccessful())
|
||||||
syncResult.setError(true);
|
syncResult.setError(true);
|
||||||
|
|
||||||
/*Response<NextNewsFolders> folderResponse = api.getFolders().execute();
|
Response<List<Folder>> folderResponse = api.getFolders().execute();
|
||||||
NextNewsFolders folderList = folderResponse.body();
|
List<Folder> folderList = folderResponse.body();
|
||||||
|
|
||||||
if (!folderResponse.isSuccessful())
|
if (!folderResponse.isSuccessful())
|
||||||
syncResult.setError(true);
|
syncResult.setError(true);
|
||||||
|
|
||||||
if (folderList != null)
|
if (folderList != null)
|
||||||
syncResult.setFolders(folderList.getFolders());*/
|
syncResult.setFolders(folderList);
|
||||||
|
|
||||||
if (feedList != null)
|
if (feedList != null)
|
||||||
syncResult.setFeeds(feedList);
|
syncResult.setFeeds(feedList);
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.readrops.readropslibrary.services.nextcloudnews;
|
package com.readrops.readropslibrary.services.nextcloudnews;
|
||||||
|
|
||||||
import com.readrops.readropsdb.entities.Feed;
|
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.NextNewsFeeds;
|
||||||
import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsFolder;
|
import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsFolder;
|
||||||
import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsFolders;
|
import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsFolders;
|
||||||
|
@ -30,7 +31,7 @@ public interface NextNewsService {
|
||||||
Call<NextNewsUser> getUser();
|
Call<NextNewsUser> getUser();
|
||||||
|
|
||||||
@GET("folders")
|
@GET("folders")
|
||||||
Call<NextNewsFolders> getFolders();
|
Call<List<Folder>> getFolders();
|
||||||
|
|
||||||
@GET("feeds")
|
@GET("feeds")
|
||||||
Call<List<Feed>> getFeeds();
|
Call<List<Feed>> getFeeds();
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
package com.readrops.readropslibrary.services.nextcloudnews;
|
package com.readrops.readropslibrary.services.nextcloudnews;
|
||||||
|
|
||||||
import com.readrops.readropsdb.entities.Feed;
|
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 com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsItem;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class NextNewsSyncResult {
|
public class NextNewsSyncResult {
|
||||||
|
|
||||||
private List<NextNewsFolder> folders;
|
private List<Folder> folders;
|
||||||
|
|
||||||
private List<Feed> feeds;
|
private List<Feed> feeds;
|
||||||
|
|
||||||
|
@ -20,11 +20,11 @@ public class NextNewsSyncResult {
|
||||||
// empty constructor
|
// empty constructor
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<NextNewsFolder> getFolders() {
|
public List<Folder> getFolders() {
|
||||||
return folders;
|
return folders;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFolders(List<NextNewsFolder> folders) {
|
public void setFolders(List<Folder> folders) {
|
||||||
this.folders = 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