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

View File

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

View File

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

View File

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

View File

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