diff --git a/app/src/main/java/me/ash/reader/data/repository/LocalRssRepository.kt b/app/src/main/java/me/ash/reader/data/repository/LocalRssRepository.kt index f91b7fe..8a9834d 100644 --- a/app/src/main/java/me/ash/reader/data/repository/LocalRssRepository.kt +++ b/app/src/main/java/me/ash/reader/data/repository/LocalRssRepository.kt @@ -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)) diff --git a/app/src/main/java/me/ash/reader/data/repository/RssHelper.kt b/app/src/main/java/me/ash/reader/data/repository/RssHelper.kt index fcd0f76..561343b 100644 --- a/app/src/main/java/me/ash/reader/data/repository/RssHelper.kt +++ b/app/src/main/java/me/ash/reader/data/repository/RssHelper.kt @@ -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 = 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 diff --git a/app/src/main/java/me/ash/reader/ui/component/WebView.kt b/app/src/main/java/me/ash/reader/ui/component/WebView.kt index acdb97b..921cf60 100644 --- a/app/src/main/java/me/ash/reader/ui/component/WebView.kt +++ b/app/src/main/java/me/ash/reader/ui/component/WebView.kt @@ -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 } diff --git a/app/src/main/java/me/ash/reader/ui/page/home/read/Header.kt b/app/src/main/java/me/ash/reader/ui/page/home/read/Header.kt index 6a92cd7..90e6dd0 100644 --- a/app/src/main/java/me/ash/reader/ui/page/home/read/Header.kt +++ b/app/src/main/java/me/ash/reader/ui/page/home/read/Header.kt @@ -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) ) { diff --git a/build.gradle b/build.gradle index 75f7b0f..e4148b3 100644 --- a/build.gradle +++ b/build.gradle @@ -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'