Fix repeatedly sync articles and article time order bug and notification icons
This commit is contained in:
parent
a74df49fb3
commit
2b2c5277eb
|
@ -439,6 +439,7 @@ interface ArticleDao {
|
||||||
SELECT * FROM article
|
SELECT * FROM article
|
||||||
WHERE feedId = :feedId
|
WHERE feedId = :feedId
|
||||||
AND accountId = :accountId
|
AND accountId = :accountId
|
||||||
|
ORDER BY date DESC
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
fun queryArticleWithFeedByFeedIdWhenIsAll(
|
fun queryArticleWithFeedByFeedIdWhenIsAll(
|
||||||
|
@ -453,6 +454,7 @@ interface ArticleDao {
|
||||||
WHERE feedId = :feedId
|
WHERE feedId = :feedId
|
||||||
AND isStarred = :isStarred
|
AND isStarred = :isStarred
|
||||||
AND accountId = :accountId
|
AND accountId = :accountId
|
||||||
|
ORDER BY date DESC
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
fun queryArticleWithFeedByFeedIdWhenIsStarred(
|
fun queryArticleWithFeedByFeedIdWhenIsStarred(
|
||||||
|
@ -468,6 +470,7 @@ interface ArticleDao {
|
||||||
WHERE feedId = :feedId
|
WHERE feedId = :feedId
|
||||||
AND isUnread = :isUnread
|
AND isUnread = :isUnread
|
||||||
AND accountId = :accountId
|
AND accountId = :accountId
|
||||||
|
ORDER BY date DESC
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
fun queryArticleWithFeedByFeedIdWhenIsUnread(
|
fun queryArticleWithFeedByFeedIdWhenIsUnread(
|
||||||
|
@ -511,4 +514,55 @@ interface ArticleDao {
|
||||||
|
|
||||||
@Delete
|
@Delete
|
||||||
suspend fun delete(vararg article: Article)
|
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 }
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -106,12 +106,13 @@ class LocalRssRepository @Inject constructor(
|
||||||
.awaitAll()
|
.awaitAll()
|
||||||
.forEach {
|
.forEach {
|
||||||
if (it.isNotify) {
|
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}")
|
Log.i("RlOG", "onCompletion: ${System.currentTimeMillis() - preTime}")
|
||||||
accountDao.queryById(accountId)?.let { account ->
|
accountDao.queryById(accountId)?.let { account ->
|
||||||
accountDao.update(
|
accountDao.update(
|
||||||
|
@ -188,13 +189,19 @@ class LocalRssRepository @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun notify(
|
private fun notify(
|
||||||
articles: List<Article>,
|
articles: List<Article?>,
|
||||||
) {
|
) {
|
||||||
articles.forEach { article ->
|
articles.filterNotNull().forEach { article ->
|
||||||
val builder = NotificationCompat.Builder(
|
val builder = NotificationCompat.Builder(
|
||||||
context,
|
context,
|
||||||
NotificationGroupName.ARTICLE_UPDATE
|
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)
|
.setGroup(NotificationGroupName.ARTICLE_UPDATE)
|
||||||
.setContentTitle(article.title)
|
.setContentTitle(article.title)
|
||||||
.setContentText(article.shortDescription)
|
.setContentText(article.shortDescription)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user