Fix repeatedly sync articles and article time order bug and notification icons

This commit is contained in:
Ash 2022-04-10 22:53:13 +08:00
parent a74df49fb3
commit 2b2c5277eb
2 changed files with 67 additions and 6 deletions

View File

@ -439,6 +439,7 @@ interface ArticleDao {
SELECT * FROM article
WHERE feedId = :feedId
AND accountId = :accountId
ORDER BY date DESC
"""
)
fun queryArticleWithFeedByFeedIdWhenIsAll(
@ -453,6 +454,7 @@ interface ArticleDao {
WHERE feedId = :feedId
AND isStarred = :isStarred
AND accountId = :accountId
ORDER BY date DESC
"""
)
fun queryArticleWithFeedByFeedIdWhenIsStarred(
@ -468,6 +470,7 @@ interface ArticleDao {
WHERE feedId = :feedId
AND isUnread = :isUnread
AND accountId = :accountId
ORDER BY date DESC
"""
)
fun queryArticleWithFeedByFeedIdWhenIsUnread(
@ -511,4 +514,55 @@ interface ArticleDao {
@Delete
suspend fun delete(vararg article: Article)
@RewriteQueriesToDropUnusedColumns
@Transaction
@Query(
"""
INSERT INTO article
SELECT :id, :date, :title, :author, :rawDescription,
:shortDescription, :fullContent, :link, :feedId,
:accountId, :isUnread, :isStarred, :isReadLater
WHERE NOT EXISTS(SELECT 1 FROM article WHERE link = :link AND accountId = :accountId)
"""
)
suspend fun insertIfNotExist(
id: String,
date: Date,
title: String,
author: String? = null,
rawDescription: String,
shortDescription: String,
fullContent: String? = null,
link: String,
feedId: String,
accountId: Int,
isUnread: Boolean = true,
isStarred: Boolean = false,
isReadLater: Boolean = false,
): Long
@Transaction
suspend fun insertIfNotExist(article: Article): Long {
return insertIfNotExist(
article.id,
article.date,
article.title,
article.author,
article.rawDescription,
article.shortDescription,
article.fullContent,
article.link,
article.feedId,
article.accountId,
article.isUnread,
article.isStarred,
article.isReadLater,
)
}
@Transaction
suspend fun insertIfNotExist(articles: List<Article>): List<Article?> {
return articles.map { if (insertIfNotExist(it) > 0) it else null }
}
}

View File

@ -106,12 +106,13 @@ class LocalRssRepository @Inject constructor(
.awaitAll()
.forEach {
if (it.isNotify) {
notify(it.articles)
notify(articleDao.insertIfNotExist(it.articles))
} else {
articleDao.insertIfNotExist(it.articles)
}
articles.addAll(it.articles)
}
articleDao.insertList(articles)
// articleDao.insertList(articles)
Log.i("RlOG", "onCompletion: ${System.currentTimeMillis() - preTime}")
accountDao.queryById(accountId)?.let { account ->
accountDao.update(
@ -188,13 +189,19 @@ class LocalRssRepository @Inject constructor(
}
private fun notify(
articles: List<Article>,
articles: List<Article?>,
) {
articles.forEach { article ->
articles.filterNotNull().forEach { article ->
val builder = NotificationCompat.Builder(
context,
NotificationGroupName.ARTICLE_UPDATE
).setSmallIcon(R.drawable.ic_launcher_foreground)
).setSmallIcon(R.drawable.ic_notification)
// .setLargeIcon(
// BitmapFactory.decodeResource(
// context.resources,
// R.mipmap.ic_launcher_round,
// )
// )
.setGroup(NotificationGroupName.ARTICLE_UPDATE)
.setContentTitle(article.title)
.setContentText(article.shortDescription)