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 986d1866..48245219 100644 --- a/app/src/main/java/com/readrops/app/repositories/LocalFeedRepository.java +++ b/app/src/main/java/com/readrops/app/repositories/LocalFeedRepository.java @@ -6,16 +6,16 @@ import android.app.Application; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import com.readrops.readropsdb.entities.Feed; -import com.readrops.readropsdb.entities.Item; -import com.readrops.readropsdb.entities.account.Account; import com.readrops.app.utils.FeedInsertionResult; -import com.readrops.app.utils.matchers.FeedMatcher; import com.readrops.app.utils.HtmlParser; -import com.readrops.app.utils.matchers.ItemMatcher; import com.readrops.app.utils.ParsingResult; import com.readrops.app.utils.SharedPreferencesManager; import com.readrops.app.utils.Utils; +import com.readrops.app.utils.matchers.FeedMatcher; +import com.readrops.app.utils.matchers.ItemMatcher; +import com.readrops.readropsdb.entities.Feed; +import com.readrops.readropsdb.entities.Item; +import com.readrops.readropsdb.entities.account.Account; import com.readrops.readropslibrary.localfeed.AFeed; import com.readrops.readropslibrary.localfeed.RSSQuery; import com.readrops.readropslibrary.localfeed.RSSQueryResult; diff --git a/readropslibrary/build.gradle b/readropslibrary/build.gradle index 1375d569..7c25c284 100644 --- a/readropslibrary/build.gradle +++ b/readropslibrary/build.gradle @@ -43,7 +43,6 @@ dependencies { androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' implementation 'com.squareup.retrofit2:retrofit:2.7.1' - implementation 'com.squareup.retrofit2:converter-gson:2.7.1' implementation('com.squareup.retrofit2:converter-moshi:2.7.1') { exclude group: 'moshi', module: 'moshi' // moshi converter uses moshi 1.8.0 which breaks codegen 1.9.2 } diff --git a/readropslibrary/src/main/java/com/readrops/readropslibrary/localfeed/AFeed.java b/readropslibrary/src/main/java/com/readrops/readropslibrary/localfeed/AFeed.java deleted file mode 100644 index e84102fa..00000000 --- a/readropslibrary/src/main/java/com/readrops/readropslibrary/localfeed/AFeed.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.readrops.readropslibrary.localfeed; - -/* - A simple class to give an abstract level to rss/atom/json feed classes - */ -public abstract class AFeed { - - protected String etag; - - protected String lastModified; - - public String getEtag() { - return etag; - } - - public void setEtag(String etag) { - this.etag = etag; - } - - public String getLastModified() { - return lastModified; - } - - public void setLastModified(String lastModified) { - this.lastModified = lastModified; - } -} diff --git a/readropslibrary/src/main/java/com/readrops/readropslibrary/localfeed/AFeed.kt b/readropslibrary/src/main/java/com/readrops/readropslibrary/localfeed/AFeed.kt new file mode 100644 index 00000000..7775c3d1 --- /dev/null +++ b/readropslibrary/src/main/java/com/readrops/readropslibrary/localfeed/AFeed.kt @@ -0,0 +1,9 @@ +package com.readrops.readropslibrary.localfeed + +/* + A simple class to give an abstract level to rss/atom/json feed classes + */ +abstract class AFeed { + var etag: String? = null + var lastModified: String? = null +} \ No newline at end of file diff --git a/readropslibrary/src/main/java/com/readrops/readropslibrary/localfeed/RSSQuery.java b/readropslibrary/src/main/java/com/readrops/readropslibrary/localfeed/RSSQuery.java index ab961924..3619de15 100644 --- a/readropslibrary/src/main/java/com/readrops/readropslibrary/localfeed/RSSQuery.java +++ b/readropslibrary/src/main/java/com/readrops/readropslibrary/localfeed/RSSQuery.java @@ -3,14 +3,15 @@ package com.readrops.readropslibrary.localfeed; import android.accounts.NetworkErrorException; import android.util.Log; -import com.google.gson.Gson; -import com.readrops.readropslibrary.utils.HttpBuilder; -import com.readrops.readropslibrary.utils.LibUtils; -import com.readrops.readropslibrary.utils.UnknownFormatException; import com.readrops.readropslibrary.localfeed.atom.ATOMFeed; import com.readrops.readropslibrary.localfeed.json.JSONFeed; import com.readrops.readropslibrary.localfeed.rss.RSSFeed; import com.readrops.readropslibrary.localfeed.rss.RSSLink; +import com.readrops.readropslibrary.utils.HttpBuilder; +import com.readrops.readropslibrary.utils.LibUtils; +import com.readrops.readropslibrary.utils.UnknownFormatException; +import com.squareup.moshi.JsonAdapter; +import com.squareup.moshi.Moshi; import org.simpleframework.xml.Serializer; import org.simpleframework.xml.core.Persister; @@ -153,8 +154,11 @@ public class RSSQuery { ((ATOMFeed) feed).setUrl(response.request().url().toString()); break; case RSS_JSON: - Gson gson = new Gson(); - feed = gson.fromJson(xml, JSONFeed.class); + Moshi moshi = new Moshi.Builder() + .build(); + + JsonAdapter jsonFeedAdapter = moshi.adapter(JSONFeed.class); + feed = jsonFeedAdapter.fromJson(xml); break; } diff --git a/readropslibrary/src/main/java/com/readrops/readropslibrary/localfeed/json/JSONAuthor.java b/readropslibrary/src/main/java/com/readrops/readropslibrary/localfeed/json/JSONAuthor.java deleted file mode 100644 index 059f432c..00000000 --- a/readropslibrary/src/main/java/com/readrops/readropslibrary/localfeed/json/JSONAuthor.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.readrops.readropslibrary.localfeed.json; - -import com.google.gson.annotations.SerializedName; - -public class JSONAuthor { - - private String name; - - private String url; - - @SerializedName("avatar") - private String avatarUrl; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getUrl() { - return url; - } - - public void setUrl(String url) { - this.url = url; - } - - public String getAvatarUrl() { - return avatarUrl; - } - - public void setAvatarUrl(String avatarUrl) { - this.avatarUrl = avatarUrl; - } - - -} diff --git a/readropslibrary/src/main/java/com/readrops/readropslibrary/localfeed/json/JSONAuthor.kt b/readropslibrary/src/main/java/com/readrops/readropslibrary/localfeed/json/JSONAuthor.kt new file mode 100644 index 00000000..02c4ed1a --- /dev/null +++ b/readropslibrary/src/main/java/com/readrops/readropslibrary/localfeed/json/JSONAuthor.kt @@ -0,0 +1,9 @@ +package com.readrops.readropslibrary.localfeed.json + +import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass + +@JsonClass(generateAdapter = true) +data class JSONAuthor(val name: String, + val url: String, + @Json(name = "avatar") val avatarUrl: String?) \ No newline at end of file diff --git a/readropslibrary/src/main/java/com/readrops/readropslibrary/localfeed/json/JSONFeed.java b/readropslibrary/src/main/java/com/readrops/readropslibrary/localfeed/json/JSONFeed.java deleted file mode 100644 index bc1347f6..00000000 --- a/readropslibrary/src/main/java/com/readrops/readropslibrary/localfeed/json/JSONFeed.java +++ /dev/null @@ -1,83 +0,0 @@ -package com.readrops.readropslibrary.localfeed.json; - -import com.google.gson.annotations.SerializedName; -import com.readrops.readropslibrary.localfeed.AFeed; - -import java.util.List; - -public class JSONFeed extends AFeed { - - private String title; - - @SerializedName("home_page_url") - private String homePageUrl; - - @SerializedName("feed_url") - private String feedUrl; - - private String description; - - @SerializedName("icon") - private String iconUrl; - - @SerializedName("favicon") - private String faviconUrl; - - private List items; - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getHomePageUrl() { - return homePageUrl; - } - - public void setHomePageUrl(String homePageUrl) { - this.homePageUrl = homePageUrl; - } - - public String getFeedUrl() { - return feedUrl; - } - - public void setFeedUrl(String feedUrl) { - this.feedUrl = feedUrl; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getIconUrl() { - return iconUrl; - } - - public void setIconUrl(String iconUrl) { - this.iconUrl = iconUrl; - } - - public String getFaviconUrl() { - return faviconUrl; - } - - public void setFaviconUrl(String faviconUrl) { - this.faviconUrl = faviconUrl; - } - - public List getItems() { - return items; - } - - public void setItems(List items) { - this.items = items; - } -} diff --git a/readropslibrary/src/main/java/com/readrops/readropslibrary/localfeed/json/JSONFeed.kt b/readropslibrary/src/main/java/com/readrops/readropslibrary/localfeed/json/JSONFeed.kt new file mode 100644 index 00000000..b4233082 --- /dev/null +++ b/readropslibrary/src/main/java/com/readrops/readropslibrary/localfeed/json/JSONFeed.kt @@ -0,0 +1,15 @@ +package com.readrops.readropslibrary.localfeed.json + +import com.readrops.readropslibrary.localfeed.AFeed +import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass + +@JsonClass(generateAdapter = true) +data class JSONFeed(val version: String, + val title: String, + @Json(name = "home_page_url") val homePageUrl: String?, + @Json(name = "feed_url") val feedUrl: String?, + val description: String?, + @Json(name = "icon") val iconUrl: String?, + @Json(name = "favicon") val faviconUrl: String?, + val items: List) : AFeed() \ No newline at end of file diff --git a/readropslibrary/src/main/java/com/readrops/readropslibrary/localfeed/json/JSONItem.java b/readropslibrary/src/main/java/com/readrops/readropslibrary/localfeed/json/JSONItem.java deleted file mode 100644 index b549b017..00000000 --- a/readropslibrary/src/main/java/com/readrops/readropslibrary/localfeed/json/JSONItem.java +++ /dev/null @@ -1,119 +0,0 @@ -package com.readrops.readropslibrary.localfeed.json; - -import com.google.gson.annotations.SerializedName; - -public class JSONItem { - - private String id; - - private String title; - - private String summary; - - @SerializedName("content_text") - private String contentText; - - @SerializedName("content_html") - private String contentHtml; - - private String url; - - @SerializedName("image") - private String imageUrl; - - @SerializedName("date_published") - private String pubDate; - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getSummary() { - return summary; - } - - public void setSummary(String summary) { - this.summary = summary; - } - - public String getContentText() { - return contentText; - } - - public void setContentText(String contentText) { - this.contentText = contentText; - } - - public String getContentHtml() { - return contentHtml; - } - - public void setContentHtml(String contentHtml) { - this.contentHtml = contentHtml; - } - - public String getUrl() { - return url; - } - - public void setUrl(String url) { - this.url = url; - } - - public String getImageUrl() { - return imageUrl; - } - - public void setImageUrl(String imageUrl) { - this.imageUrl = imageUrl; - } - - public String getPubDate() { - return pubDate; - } - - public void setPubDate(String pubDate) { - this.pubDate = pubDate; - } - - public String getModDate() { - return modDate; - } - - public void setModDate(String modDate) { - this.modDate = modDate; - } - - public JSONAuthor getAuthor() { - return author; - } - - public void setAuthor(JSONAuthor author) { - this.author = author; - } - - public String getContent() { - if (contentHtml == null) - return contentText; - else - return contentHtml; - - } - - @SerializedName("date_modified") - private String modDate; - - private JSONAuthor author; -} diff --git a/readropslibrary/src/main/java/com/readrops/readropslibrary/localfeed/json/JSONItem.kt b/readropslibrary/src/main/java/com/readrops/readropslibrary/localfeed/json/JSONItem.kt new file mode 100644 index 00000000..b6ea2c01 --- /dev/null +++ b/readropslibrary/src/main/java/com/readrops/readropslibrary/localfeed/json/JSONItem.kt @@ -0,0 +1,21 @@ +package com.readrops.readropslibrary.localfeed.json + +import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass + +@JsonClass(generateAdapter = true) +data class JSONItem(val id: String, + val title: String?, + val summary: String?, + @Json(name = "content_text") val contentText: String?, + @Json(name = "content_html") val contentHtml: String?, + val url: String?, + @Json(name = "image") val imageUrl: String?, + @Json(name = "date_published") val pubDate: String, + @Json(name = "date_modified") val modDate: String?, + val author: JSONAuthor?) { + + fun getContent(): String? { + return contentHtml ?: contentText + } +} \ No newline at end of file