From 412ec3f1b8659273fb12b3ea530e8f5aa046311a Mon Sep 17 00:00:00 2001 From: Shinokuni Date: Fri, 23 Oct 2020 21:33:27 +0200 Subject: [PATCH] Rename LibUtils to ApiUtils --- .../api/localfeed/LocalRSSDataSourceTest.kt | 20 ++++++++--------- .../api/localfeed/LocalRSSDataSource.kt | 14 ++++++------ .../api/localfeed/rss2/RSS2ItemsAdapter.kt | 8 +++---- .../nextcloudnews/NextNewsDataSource.java | 22 +++++++++---------- .../adapters/NextNewsItemsAdapter.kt | 4 ++-- .../utils/{LibUtils.java => ApiUtils.java} | 2 +- .../{LibUtilsTest.kt => ApiUtilsTest.kt} | 8 +++---- .../app/repositories/LocalFeedRepository.java | 6 ++--- .../com/readrops/app/utils/HtmlParser.java | 4 ++-- 9 files changed, 44 insertions(+), 44 deletions(-) rename api/src/main/java/com/readrops/api/utils/{LibUtils.java => ApiUtils.java} (98%) rename api/src/test/java/com/readrops/api/utils/{LibUtilsTest.kt => ApiUtilsTest.kt} (66%) diff --git a/api/src/androidTest/java/com/readrops/api/localfeed/LocalRSSDataSourceTest.kt b/api/src/androidTest/java/com/readrops/api/localfeed/LocalRSSDataSourceTest.kt index 5259109a..34fa8826 100644 --- a/api/src/androidTest/java/com/readrops/api/localfeed/LocalRSSDataSourceTest.kt +++ b/api/src/androidTest/java/com/readrops/api/localfeed/LocalRSSDataSourceTest.kt @@ -4,7 +4,7 @@ import android.accounts.NetworkErrorException import android.content.Context import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.platform.app.InstrumentationRegistry -import com.readrops.api.utils.LibUtils +import com.readrops.api.utils.ApiUtils import com.readrops.api.utils.exceptions.ParseException import com.readrops.api.utils.exceptions.UnknownFormatException import junit.framework.TestCase.* @@ -46,9 +46,9 @@ class LocalRSSDataSourceTest { val stream = context.resources.assets.open("localfeed/rss_feed.xml") mockServer.enqueue(MockResponse().setResponseCode(HttpURLConnection.HTTP_OK) - .addHeader(LibUtils.CONTENT_TYPE_HEADER, "application/xml; charset=UTF-8") - .addHeader(LibUtils.ETAG_HEADER, "ETag-value") - .addHeader(LibUtils.LAST_MODIFIED_HEADER, "Last-Modified") + .addHeader(ApiUtils.CONTENT_TYPE_HEADER, "application/xml; charset=UTF-8") + .addHeader(ApiUtils.ETAG_HEADER, "ETag-value") + .addHeader(ApiUtils.LAST_MODIFIED_HEADER, "Last-Modified") .setBody(Buffer().readFrom(stream))) val pair = localRSSDataSource.queryRSSResource(url.toString(), null) @@ -73,13 +73,13 @@ class LocalRSSDataSourceTest { .addHeader("Content-Type", "application/rss+xml; charset=UTF-8") .setBody(Buffer().readFrom(stream))) - val headers = Headers.headersOf(LibUtils.ETAG_HEADER, "ETag", LibUtils.LAST_MODIFIED_HEADER, "Last-Modified") + val headers = Headers.headersOf(ApiUtils.ETAG_HEADER, "ETag", ApiUtils.LAST_MODIFIED_HEADER, "Last-Modified") localRSSDataSource.queryRSSResource(url.toString(), headers) val request = mockServer.takeRequest() - assertEquals(request.headers[LibUtils.ETAG_HEADER], "ETag") - assertEquals(request.headers[LibUtils.LAST_MODIFIED_HEADER], "Last-Modified") + assertEquals(request.headers[ApiUtils.ETAG_HEADER], "ETag") + assertEquals(request.headers[ApiUtils.LAST_MODIFIED_HEADER], "Last-Modified") } @Test @@ -87,7 +87,7 @@ class LocalRSSDataSourceTest { val stream = context.resources.assets.open("localfeed/json/json_feed.json") mockServer.enqueue(MockResponse().setResponseCode(HttpURLConnection.HTTP_OK) - .addHeader(LibUtils.CONTENT_TYPE_HEADER, "application/feed+json") + .addHeader(ApiUtils.CONTENT_TYPE_HEADER, "application/feed+json") .setBody(Buffer().readFrom(stream))) val pair = localRSSDataSource.queryRSSResource(url.toString(), null)!! @@ -101,7 +101,7 @@ class LocalRSSDataSourceTest { val stream = context.resources.assets.open("localfeed/atom/atom_feed_no_url_siteurl.xml") mockServer.enqueue(MockResponse().setResponseCode(HttpURLConnection.HTTP_OK) - .addHeader(LibUtils.CONTENT_TYPE_HEADER, "application/atom+xml") + .addHeader(ApiUtils.CONTENT_TYPE_HEADER, "application/atom+xml") .setBody(Buffer().readFrom(stream))) val pair = localRSSDataSource.queryRSSResource(url.toString(), null)!! @@ -115,7 +115,7 @@ class LocalRSSDataSourceTest { val stream = context.resources.assets.open("localfeed/rss1/rss1_feed_no_url_siteurl.xml") mockServer.enqueue(MockResponse().setResponseCode(HttpURLConnection.HTTP_OK) - .addHeader(LibUtils.CONTENT_TYPE_HEADER, "application/rdf+xml") + .addHeader(ApiUtils.CONTENT_TYPE_HEADER, "application/rdf+xml") .setBody(Buffer().readFrom(stream))) val pair = localRSSDataSource.queryRSSResource(url.toString(), null)!! diff --git a/api/src/main/java/com/readrops/api/localfeed/LocalRSSDataSource.kt b/api/src/main/java/com/readrops/api/localfeed/LocalRSSDataSource.kt index f682e808..4a7cfd46 100644 --- a/api/src/main/java/com/readrops/api/localfeed/LocalRSSDataSource.kt +++ b/api/src/main/java/com/readrops/api/localfeed/LocalRSSDataSource.kt @@ -4,7 +4,7 @@ import android.accounts.NetworkErrorException import androidx.annotation.WorkerThread import com.readrops.api.localfeed.json.JSONFeedAdapter import com.readrops.api.localfeed.json.JSONItemsAdapter -import com.readrops.api.utils.LibUtils +import com.readrops.api.utils.ApiUtils import com.readrops.api.utils.exceptions.ParseException import com.readrops.api.utils.exceptions.UnknownFormatException import com.readrops.db.entities.Feed @@ -36,10 +36,10 @@ class LocalRSSDataSource(private val httpClient: OkHttpClient) { return when { response.isSuccessful -> { - val header = response.header(LibUtils.CONTENT_TYPE_HEADER) + val header = response.header(ApiUtils.CONTENT_TYPE_HEADER) ?: throw UnknownFormatException("Unable to get $url content-type") - val contentType = LibUtils.parseContentType(header) + val contentType = ApiUtils.parseContentType(header) ?: throw ParseException("Unable to parse $url content-type") var type = LocalRSSHelper.getRSSType(contentType) @@ -73,10 +73,10 @@ class LocalRSSDataSource(private val httpClient: OkHttpClient) { val response = queryUrl(url, null) return if (response.isSuccessful) { - val header = response.header(LibUtils.CONTENT_TYPE_HEADER) + val header = response.header(ApiUtils.CONTENT_TYPE_HEADER) ?: return false - val contentType = LibUtils.parseContentType(header) + val contentType = ApiUtils.parseContentType(header) ?: return false var type = LocalRSSHelper.getRSSType(contentType) @@ -112,8 +112,8 @@ class LocalRSSDataSource(private val httpClient: OkHttpClient) { handleSpecialCases(feed, type, response) - feed.etag = response.header(LibUtils.ETAG_HEADER) - feed.lastModified = response.header(LibUtils.LAST_MODIFIED_HEADER) + feed.etag = response.header(ApiUtils.ETAG_HEADER) + feed.lastModified = response.header(ApiUtils.LAST_MODIFIED_HEADER) return feed } diff --git a/api/src/main/java/com/readrops/api/localfeed/rss2/RSS2ItemsAdapter.kt b/api/src/main/java/com/readrops/api/localfeed/rss2/RSS2ItemsAdapter.kt index 2a367efa..3d37adbe 100644 --- a/api/src/main/java/com/readrops/api/localfeed/rss2/RSS2ItemsAdapter.kt +++ b/api/src/main/java/com/readrops/api/localfeed/rss2/RSS2ItemsAdapter.kt @@ -27,7 +27,7 @@ class RSS2ItemsAdapter : XmlAdapter> { val item = Item().apply { allChildrenAutoIgnore(names) { when (tagName) { - "title" -> title = LibUtils.cleanText(nonNullText()) + "title" -> title = ApiUtils.cleanText(nonNullText()) "link" -> link = nonNullText() "author" -> author = nullableText() "dc:creator" -> creators += nullableText() @@ -60,16 +60,16 @@ class RSS2ItemsAdapter : XmlAdapter> { private fun parseEnclosure(konsumer: Konsumer, item: Item) { if (konsumer.attributes.getValueOpt("type") != null - && LibUtils.isMimeImage(konsumer.attributes["type"]) && item.imageLink == null) + && ApiUtils.isMimeImage(konsumer.attributes["type"]) && item.imageLink == null) item.imageLink = konsumer.attributes.getValueOpt("url") } private fun isMediumImage(konsumer: Konsumer) = with(konsumer) { - attributes.getValueOpt("medium") != null && LibUtils.isMimeImage(attributes["medium"]) + attributes.getValueOpt("medium") != null && ApiUtils.isMimeImage(attributes["medium"]) } private fun isTypeImage(konsumer: Konsumer) = with(konsumer) { - attributes.getValueOpt("type") != null && LibUtils.isMimeImage(attributes["type"]) + attributes.getValueOpt("type") != null && ApiUtils.isMimeImage(attributes["type"]) } private fun parseMediaContent(konsumer: Konsumer, item: Item) { diff --git a/api/src/main/java/com/readrops/api/services/nextcloudnews/NextNewsDataSource.java b/api/src/main/java/com/readrops/api/services/nextcloudnews/NextNewsDataSource.java index bfe3ae96..eaa6d30c 100644 --- a/api/src/main/java/com/readrops/api/services/nextcloudnews/NextNewsDataSource.java +++ b/api/src/main/java/com/readrops/api/services/nextcloudnews/NextNewsDataSource.java @@ -9,7 +9,7 @@ import com.readrops.api.services.SyncResult; import com.readrops.api.services.SyncType; import com.readrops.api.services.nextcloudnews.json.NextNewsUser; import com.readrops.api.utils.exceptions.ConflictException; -import com.readrops.api.utils.LibUtils; +import com.readrops.api.utils.ApiUtils; import com.readrops.api.utils.exceptions.UnknownFormatException; import com.readrops.db.entities.Feed; import com.readrops.db.entities.Folder; @@ -50,7 +50,7 @@ public class NextNewsDataSource { Response> response = api.createFeed(url, folderId).execute(); if (!response.isSuccessful()) { - if (response.code() == LibUtils.HTTP_UNPROCESSABLE) + if (response.code() == ApiUtils.HTTP_UNPROCESSABLE) throw new UnknownFormatException(); else return null; @@ -156,9 +156,9 @@ public class NextNewsDataSource { if (foldersResponse.isSuccessful()) return foldersResponse.body(); - else if (foldersResponse.code() == LibUtils.HTTP_UNPROCESSABLE) + else if (foldersResponse.code() == ApiUtils.HTTP_UNPROCESSABLE) throw new UnknownFormatException(); - else if (foldersResponse.code() == LibUtils.HTTP_CONFLICT) + else if (foldersResponse.code() == ApiUtils.HTTP_CONFLICT) throw new ConflictException(); else return new ArrayList<>(); @@ -169,7 +169,7 @@ public class NextNewsDataSource { if (response.isSuccessful()) return true; - else if (response.code() == LibUtils.HTTP_NOT_FOUND) + else if (response.code() == ApiUtils.HTTP_NOT_FOUND) throw new Resources.NotFoundException(); else return false; @@ -185,11 +185,11 @@ public class NextNewsDataSource { return true; else { switch (response.code()) { - case LibUtils.HTTP_NOT_FOUND: + case ApiUtils.HTTP_NOT_FOUND: throw new Resources.NotFoundException(); - case LibUtils.HTTP_UNPROCESSABLE: + case ApiUtils.HTTP_UNPROCESSABLE: throw new UnknownFormatException(); - case LibUtils.HTTP_CONFLICT: + case ApiUtils.HTTP_CONFLICT: throw new ConflictException(); default: return false; @@ -202,7 +202,7 @@ public class NextNewsDataSource { if (response.isSuccessful()) return true; - else if (response.code() == LibUtils.HTTP_NOT_FOUND) + else if (response.code() == ApiUtils.HTTP_NOT_FOUND) throw new Resources.NotFoundException(); else return false; @@ -216,7 +216,7 @@ public class NextNewsDataSource { if (response.isSuccessful()) return true; - else if (response.code() == LibUtils.HTTP_NOT_FOUND) + else if (response.code() == ApiUtils.HTTP_NOT_FOUND) throw new Resources.NotFoundException(); else return false; @@ -230,7 +230,7 @@ public class NextNewsDataSource { if (response.isSuccessful()) return true; - else if (response.code() == LibUtils.HTTP_NOT_FOUND) + else if (response.code() == ApiUtils.HTTP_NOT_FOUND) throw new Resources.NotFoundException(); else return false; diff --git a/api/src/main/java/com/readrops/api/services/nextcloudnews/adapters/NextNewsItemsAdapter.kt b/api/src/main/java/com/readrops/api/services/nextcloudnews/adapters/NextNewsItemsAdapter.kt index 1d4f145a..9599e2c3 100644 --- a/api/src/main/java/com/readrops/api/services/nextcloudnews/adapters/NextNewsItemsAdapter.kt +++ b/api/src/main/java/com/readrops/api/services/nextcloudnews/adapters/NextNewsItemsAdapter.kt @@ -2,7 +2,7 @@ package com.readrops.api.services.nextcloudnews.adapters import android.annotation.SuppressLint import com.readrops.db.entities.Item -import com.readrops.api.utils.LibUtils +import com.readrops.api.utils.ApiUtils import com.readrops.api.utils.extensions.nextNullableString import com.squareup.moshi.JsonAdapter import com.squareup.moshi.JsonReader @@ -50,7 +50,7 @@ class NextNewsItemsAdapter : JsonAdapter>() { } } - if (enclosureMime != null && LibUtils.isMimeImage(enclosureMime!!)) + if (enclosureMime != null && ApiUtils.isMimeImage(enclosureMime!!)) item.imageLink = enclosureLink items += item diff --git a/api/src/main/java/com/readrops/api/utils/LibUtils.java b/api/src/main/java/com/readrops/api/utils/ApiUtils.java similarity index 98% rename from api/src/main/java/com/readrops/api/utils/LibUtils.java rename to api/src/main/java/com/readrops/api/utils/ApiUtils.java index 7e914a2d..65209555 100644 --- a/api/src/main/java/com/readrops/api/utils/LibUtils.java +++ b/api/src/main/java/com/readrops/api/utils/ApiUtils.java @@ -8,7 +8,7 @@ import org.jsoup.Jsoup; import java.util.regex.Matcher; import java.util.regex.Pattern; -public final class LibUtils { +public final class ApiUtils { public static final String HTML_CONTENT_TYPE = "text/html"; diff --git a/api/src/test/java/com/readrops/api/utils/LibUtilsTest.kt b/api/src/test/java/com/readrops/api/utils/ApiUtilsTest.kt similarity index 66% rename from api/src/test/java/com/readrops/api/utils/LibUtilsTest.kt rename to api/src/test/java/com/readrops/api/utils/ApiUtilsTest.kt index ba6b8bc4..8a8bcae4 100644 --- a/api/src/test/java/com/readrops/api/utils/LibUtilsTest.kt +++ b/api/src/test/java/com/readrops/api/utils/ApiUtilsTest.kt @@ -3,23 +3,23 @@ package com.readrops.api.utils import junit.framework.TestCase.assertEquals import org.junit.Test -class LibUtilsTest { +class ApiUtilsTest { @Test fun contentTypeWithCharsetTest() { - assertEquals(LibUtils.parseContentType("application/rss+xml; charset=UTF-8"), + assertEquals(ApiUtils.parseContentType("application/rss+xml; charset=UTF-8"), "application/rss+xml") } @Test fun contentTypeWithoutCharsetText() { - assertEquals(LibUtils.parseContentType("text/xml"), + assertEquals(ApiUtils.parseContentType("text/xml"), "text/xml") } @Test fun cleanTextTest() { val text = "

This is a text
to

clean " - assertEquals("This is a text to clean", LibUtils.cleanText(text)) + assertEquals("This is a text to clean", ApiUtils.cleanText(text)) } } \ No newline at end of file diff --git a/app/src/main/java/com/readrops/app/repositories/LocalFeedRepository.java b/app/src/main/java/com/readrops/app/repositories/LocalFeedRepository.java index 98cced76..874644fe 100644 --- a/app/src/main/java/com/readrops/app/repositories/LocalFeedRepository.java +++ b/app/src/main/java/com/readrops/app/repositories/LocalFeedRepository.java @@ -9,7 +9,7 @@ import androidx.annotation.Nullable; import com.readrops.api.localfeed.LocalRSSDataSource; import com.readrops.api.services.SyncResult; -import com.readrops.api.utils.LibUtils; +import com.readrops.api.utils.ApiUtils; import com.readrops.api.utils.exceptions.ParseException; import com.readrops.api.utils.exceptions.UnknownFormatException; import com.readrops.app.utils.FeedInsertionResult; @@ -69,10 +69,10 @@ public class LocalFeedRepository extends ARepository { try { Headers.Builder headers = new Headers.Builder(); if (feed.getEtag() != null) { - headers.add(LibUtils.IF_NONE_MATCH_HEADER, feed.getEtag()); + headers.add(ApiUtils.IF_NONE_MATCH_HEADER, feed.getEtag()); } if (feed.getLastModified() != null) { - headers.add(LibUtils.IF_MODIFIED_HEADER, feed.getLastModified()); + headers.add(ApiUtils.IF_MODIFIED_HEADER, feed.getLastModified()); } Pair> pair = dataSource.queryRSSResource(feed.getUrl(), headers.build()); diff --git a/app/src/main/java/com/readrops/app/utils/HtmlParser.java b/app/src/main/java/com/readrops/app/utils/HtmlParser.java index daebc212..180ff2bd 100644 --- a/app/src/main/java/com/readrops/app/utils/HtmlParser.java +++ b/app/src/main/java/com/readrops/app/utils/HtmlParser.java @@ -6,7 +6,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.readrops.api.localfeed.LocalRSSHelper; -import com.readrops.api.utils.LibUtils; +import com.readrops.api.utils.ApiUtils; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; @@ -87,7 +87,7 @@ public final class HtmlParser { Response response = KoinJavaComponent.get(OkHttpClient.class) .newCall(new Request.Builder().url(url).build()).execute(); - if (response.header("Content-Type").contains(LibUtils.HTML_CONTENT_TYPE)) { + if (response.header("Content-Type").contains(ApiUtils.HTML_CONTENT_TYPE)) { String body = response.body().string(); String head = body.substring(body.indexOf(""));