Support RSS Atom

This commit is contained in:
Ash 2022-04-26 01:37:33 +08:00
parent 840970bfe2
commit 2d7ef057f3
5 changed files with 22 additions and 17 deletions

View File

@ -14,6 +14,8 @@ import androidx.work.ListenableWorker
import androidx.work.WorkManager
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.withContext
import me.ash.reader.MainActivity
import me.ash.reader.R
@ -99,10 +101,8 @@ class LocalRssRepository @Inject constructor(
val accountId = context.currentAccountId
feedDao.queryAll(accountId)
.also { coroutineWorker.setProgress(setIsSyncing(true)) }
// For ParseRSS v0.5.0 only
.map { feed -> syncFeed(feed) }
//.map { feed -> async { syncFeed(feed) } }
//.awaitAll()
.map { feed -> async { syncFeed(feed) } }
.awaitAll()
.forEach {
if (it.isNotify) {
notify(articleDao.insertIfNotExist(it.articles))

View File

@ -86,13 +86,13 @@ class RssHelper @Inject constructor(
val parseRss = rssNetworkDataSource.parseRss(feed.url)
parseRss.items.forEach {
if (latestLink != null && latestLink == it.link) return@withContext a
Log.i("RLog", "request rss:\n${feed.name},${feed.url}\n${it.title}")
Log.i("RLog", "request rss:\n${feed.name},${feed.url}\n${it.title}\n${it.link}\n")
a.add(
Article(
id = accountId.spacerDollar(UUID.randomUUID().toString()),
accountId = accountId,
feedId = feed.id,
date = it.publishDate.toString().let {
date = (it.publishDate ?: it.lastUpdated).toString().let {
try {
Date(it)
} catch (e: IllegalArgumentException) {
@ -100,9 +100,10 @@ class RssHelper @Inject constructor(
}
},
title = Html.fromHtml(it.title.toString()).toString(),
author = it.author,
rawDescription = it.description.toString(),
shortDescription = (Readability4JExtended("", it.description.toString())
author = it.author?.name,
rawDescription = it.description ?: it.summary ?: "",
shortDescription =
(Readability4JExtended("", it.description ?: it.summary ?: "")
.parse().textContent ?: "").take(100).trim(),
link = it.link ?: "",
)
@ -163,15 +164,17 @@ class RssHelper @Inject constructor(
private fun parseDate(
inputDate: String, patterns: Array<String?> = arrayOf(
"yyyy-MM-dd'T'HH:mm:ss'Z'",
"yyyy-MM-dd",
"yyyy-MM-dd HH:mm:ss",
"yyyyMMdd",
"yyyy/MM/dd",
"yyyy年MM月dd日",
"yyyy MM dd"
"yyyy MM dd",
)
): Date? {
val df = SimpleDateFormat()
df.timeZone = TimeZone.getDefault()
for (pattern in patterns) {
df.applyPattern(pattern)
df.isLenient = false

View File

@ -70,9 +70,7 @@ fun WebView(
): Boolean {
if (null == request?.url) return false
val url = request.url.toString()
context.startActivity(
Intent(Intent.ACTION_VIEW, Uri.parse(url))
)
if (url.isNotEmpty()) context.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)))
return true
}

View File

@ -23,9 +23,13 @@ fun Header(
modifier = Modifier
.fillMaxWidth()
.roundClick {
context.startActivity(
Intent(Intent.ACTION_VIEW, Uri.parse(articleWithFeed.article.link))
)
articleWithFeed.article.link .let {
if (it.isNotEmpty()) {
context.startActivity(
Intent(Intent.ACTION_VIEW, Uri.parse(articleWithFeed.article.link))
)
}
}
}
.padding(12.dp)
) {

View File

@ -12,7 +12,7 @@ buildscript {
profileinstaller = '1.2.0-alpha02'
retrofit2 = '2.9.0'
coil = '2.0.0-rc03'
parseRSS = '0.5.0'
parseRSS = '0.6.0'
readability4j = '1.0.8'
opmlParser = '2.2.0'
androidSVG = '1.4'