From 22fe77d5cf950953fbf5dbf108fd107f74951335 Mon Sep 17 00:00:00 2001 From: Shinokuni Date: Wed, 23 Sep 2020 22:29:47 +0200 Subject: [PATCH] Concatenate jsonfeed authors when they are several --- .../localfeed/json/json_items_other_cases.json | 14 +++++++++++++- .../api/localfeed/json/JSONItemsAdapterTest.kt | 2 +- .../api/localfeed/json/JSONItemsAdapter.kt | 13 +++++++------ 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/api/src/androidTest/assets/localfeed/json/json_items_other_cases.json b/api/src/androidTest/assets/localfeed/json/json_items_other_cases.json index e91ee941..8e54b640 100644 --- a/api/src/androidTest/assets/localfeed/json/json_items_other_cases.json +++ b/api/src/androidTest/assets/localfeed/json/json_items_other_cases.json @@ -16,11 +16,23 @@ }, { "url": "url 2", - "name": "Author 2" + "name": "" }, { "url": "url 3", "name": "Author 3" + }, + { + "url": "url 4", + "name": "Author 4" + }, + { + "url": "url 5", + "name": "Author 5" + }, + { + "url": "url 6", + "name": "Author 6" } ] } diff --git a/api/src/androidTest/java/com/readrops/api/localfeed/json/JSONItemsAdapterTest.kt b/api/src/androidTest/java/com/readrops/api/localfeed/json/JSONItemsAdapterTest.kt index c45e3e34..97411d8b 100644 --- a/api/src/androidTest/java/com/readrops/api/localfeed/json/JSONItemsAdapterTest.kt +++ b/api/src/androidTest/java/com/readrops/api/localfeed/json/JSONItemsAdapterTest.kt @@ -51,7 +51,7 @@ class JSONItemsAdapterTest { assertEquals(item.description, "This is a summary") assertEquals(item.content, "content_html") assertEquals(item.imageLink, "https://image.com") - assertEquals(item.author, "Author 1") + assertEquals(item.author, "Author 1, Author 3, Author 4, Author 5, ...") } @Test diff --git a/api/src/main/java/com/readrops/api/localfeed/json/JSONItemsAdapter.kt b/api/src/main/java/com/readrops/api/localfeed/json/JSONItemsAdapter.kt index b2fbb4f8..4a942b93 100644 --- a/api/src/main/java/com/readrops/api/localfeed/json/JSONItemsAdapter.kt +++ b/api/src/main/java/com/readrops/api/localfeed/json/JSONItemsAdapter.kt @@ -57,6 +57,7 @@ class JSONItemsAdapter : JsonAdapter>() { 7 -> pubDate = DateUtils.stringToLocalDateTime(reader.nextString()) 8 -> author = parseAuthor(reader) // jsonfeed 1.0 9 -> author = parseAuthors(reader) // jsonfeed 1.1 + else -> reader.skipValue() } } } @@ -86,9 +87,6 @@ class JSONItemsAdapter : JsonAdapter>() { return author } - /** - * Returns the first author of the array - */ private fun parseAuthors(reader: JsonReader): String? { val authors = arrayListOf() reader.beginArray() @@ -98,7 +96,10 @@ class JSONItemsAdapter : JsonAdapter>() { } reader.endArray() - return if (authors.filterNotNull().isNotEmpty()) authors.filterNotNull().first() else null + + // here, nextNullableString doesn't check if authors values are empty + return if (authors.filterNot { author -> author.isNullOrEmpty() }.isNotEmpty()) + authors.filterNot { author -> author.isNullOrEmpty() }.joinToString(limit = 4) else null } private fun validateItem(item: Item) { @@ -110,7 +111,7 @@ class JSONItemsAdapter : JsonAdapter>() { } companion object { - val names: JsonReader.Options = JsonReader.Options.of("id", "url", "title", "content_html", "content_text", - "summary", "image", "date_published", "author", "authors") + val names: JsonReader.Options = JsonReader.Options.of("id", "url", "title", + "content_html", "content_text", "summary", "image", "date_published", "author", "authors") } } \ No newline at end of file