diff --git a/app/src/main/java/me/ash/reader/data/dao/ArticleDao.kt b/app/src/main/java/me/ash/reader/data/dao/ArticleDao.kt index 0075784..2e50cbc 100644 --- a/app/src/main/java/me/ash/reader/data/dao/ArticleDao.kt +++ b/app/src/main/java/me/ash/reader/data/dao/ArticleDao.kt @@ -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
): List { + return articles.map { if (insertIfNotExist(it) > 0) it else null } + } } \ No newline at end of file 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 4197ef4..7db8cc6 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 @@ -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
, + articles: List, ) { - 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)