Handle the absence of some tags in RSS2 and ATOM feeds

This commit is contained in:
Shinokuni 2020-09-17 22:11:05 +02:00
parent 4b999e9fd6
commit 838768800a
1 changed files with 13 additions and 0 deletions

View File

@ -102,6 +102,8 @@ class LocalRSSDataSource(private val httpClient: OkHttpClient) {
adapter.fromJson(Buffer().readFrom(stream))!!
}
handleSpecialCases(feed, type, response)
feed.etag = response.header(LibUtils.ETAG_HEADER)
feed.lastModified = response.header(LibUtils.LAST_MODIFIED_HEADER)
@ -122,4 +124,15 @@ class LocalRSSDataSource(private val httpClient: OkHttpClient) {
adapter.fromJson(Buffer().readFrom(stream))!!
}
}
private fun handleSpecialCases(feed: Feed, type: LocalRSSHelper.RSSType, response: Response) {
with(feed) {
if (type == LocalRSSHelper.RSSType.RSS_2) {
if (url == null) url = response.request.url.toString()
} else if (type == LocalRSSHelper.RSSType.ATOM) {
if (url == null) url = response.request.url.toString()
if (siteUrl == null) siteUrl = response.request.url.scheme + "://" + response.request.url.host
}
}
}
}