Fix some NC News parsing bugs

This commit is contained in:
Shinokuni 2020-04-13 22:28:24 +02:00
parent ade8567258
commit a08796d20d
4 changed files with 24 additions and 12 deletions

View File

@ -100,18 +100,19 @@ public class NextNewsRepository extends ARepository<NextNewsAPI> {
}
TimingLogger timings = new TimingLogger(TAG, "nextcloud news " + syncType.name().toLowerCase());
SyncResult syncResult = api.sync(syncType, syncData);
SyncResult result = api.sync(syncType, syncData);
timings.addSplit("server queries");
if (!syncResult.isError()) {
if (!result.isError()) {
syncResult = new SyncResult();
insertFolders(syncResult.getFolders());
insertFolders(result.getFolders());
timings.addSplit("insert folders");
insertFeeds(syncResult.getFeeds(), false);
insertFeeds(result.getFeeds(), false);
timings.addSplit("insert feeds");
insertItems(syncResult.getItems(), syncType == SyncType.INITIAL_SYNC);
insertItems(result.getItems(), syncType == SyncType.INITIAL_SYNC);
timings.addSplit("insert items");
timings.dumpToLog();
@ -119,8 +120,6 @@ public class NextNewsRepository extends ARepository<NextNewsAPI> {
database.accountDao().updateLastModified(account.getId(), lastModified);
database.itemDao().resetReadChanges(account.getId());
this.syncResult = syncResult;
emitter.onComplete();
} else
emitter.onError(new Throwable());

View File

@ -2,6 +2,7 @@ package com.readrops.readropslibrary.services.nextcloudnews.adapters
import android.annotation.SuppressLint
import com.readrops.readropsdb.entities.Feed
import com.readrops.readropslibrary.utils.nextNullableString
import com.squareup.moshi.FromJson
import com.squareup.moshi.JsonReader
import com.squareup.moshi.ToJson
@ -41,8 +42,11 @@ class NextNewsFeedsAdapter {
1 -> url = reader.nextString()
2 -> name = reader.nextString()
3 -> iconUrl = reader.nextString()
4 -> remoteFolderId = reader.nextInt().toString()
5 -> siteUrl = if (reader.peek() != JsonReader.Token.NULL) reader.nextString() else reader.nextNull()
4 -> {
val nextInt = reader.nextInt()
remoteFolderId = if (nextInt > 0) nextInt.toString() else null
}
5 -> siteUrl = reader.nextNullableString()
else -> reader.skipValue()
}
}

View File

@ -1,7 +1,9 @@
package com.readrops.readropslibrary.services.nextcloudnews.adapters
import android.annotation.SuppressLint
import com.readrops.readropsdb.entities.Item
import com.readrops.readropslibrary.utils.LibUtils
import com.readrops.readropslibrary.utils.nextNullableString
import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.JsonReader
import com.squareup.moshi.JsonWriter
@ -14,6 +16,7 @@ class NextNewsItemsAdapter : JsonAdapter<List<Item>>() {
// no need of this
}
@SuppressLint("CheckResult")
@Override
override fun fromJson(reader: JsonReader): List<Item> {
val items = mutableListOf<Item>()
@ -33,13 +36,13 @@ class NextNewsItemsAdapter : JsonAdapter<List<Item>>() {
with(item) {
when (reader.selectName(NAMES)) {
0 -> remoteId = reader.nextInt().toString()
1 -> link = reader.nextString()
1 -> link = reader.nextNullableString()
2 -> title = reader.nextString()
3 -> author = reader.nextString()
4 -> pubDate = LocalDateTime(reader.nextLong() * 1000L, DateTimeZone.getDefault())
5 -> content = reader.nextString()
6 -> enclosureMime = if (reader.peek() != JsonReader.Token.NULL) reader.nextString() else reader.nextNull()
7 -> enclosureLink = if (reader.peek() != JsonReader.Token.NULL) reader.nextString() else reader.nextNull()
6 -> enclosureMime = reader.nextNullableString()
7 -> enclosureLink = reader.nextNullableString()
8 -> feedRemoteId = reader.nextInt().toString()
9 -> isRead = !reader.nextBoolean()
else -> reader.skipValue()

View File

@ -0,0 +1,6 @@
package com.readrops.readropslibrary.utils
import com.squareup.moshi.JsonReader
fun JsonReader.nextNullableString(): String? =
if (peek() != JsonReader.Token.NULL) nextString() else nextNull()