Fix the synchronization bug when importing OPML files after version 0.8.0 (#92)
This commit is contained in:
parent
999fc40a7c
commit
1be4779df2
|
@ -494,6 +494,20 @@ interface ArticleDao {
|
|||
)
|
||||
suspend fun queryLatestByFeedId(accountId: Int, feedId: String): Article?
|
||||
|
||||
@Query(
|
||||
"""
|
||||
SELECT * from article
|
||||
WHERE link = :link
|
||||
AND feedId = :feedId
|
||||
AND accountId = :accountId
|
||||
"""
|
||||
)
|
||||
suspend fun queryArticleByLink(
|
||||
link: String,
|
||||
feedId: String,
|
||||
accountId: Int,
|
||||
): Article?
|
||||
|
||||
@Transaction
|
||||
@Query(
|
||||
"""
|
||||
|
@ -509,56 +523,17 @@ interface ArticleDao {
|
|||
@Update
|
||||
suspend fun update(vararg article: Article)
|
||||
|
||||
@RewriteQueriesToDropUnusedColumns
|
||||
@Transaction
|
||||
@Query(
|
||||
"""
|
||||
INSERT INTO article
|
||||
SELECT :id, :date, :title, :author, :rawDescription,
|
||||
:shortDescription, :fullContent, :link, :feedId,
|
||||
:accountId, :isUnread, :isStarred, :isReadLater, :img
|
||||
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,
|
||||
img: 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.img,
|
||||
article.link,
|
||||
article.feedId,
|
||||
article.accountId,
|
||||
article.isUnread,
|
||||
article.isStarred,
|
||||
article.isReadLater,
|
||||
)
|
||||
}
|
||||
|
||||
@Transaction
|
||||
suspend fun insertIfNotExist(articles: List<Article>): List<Article> {
|
||||
return articles.mapNotNull { if (insertIfNotExist(it) > 0) it else null }
|
||||
suspend fun insertListIfNotExist(articles: List<Article>): List<Article> {
|
||||
return articles.mapNotNull {
|
||||
if (queryArticleByLink(
|
||||
link = it.link,
|
||||
feedId = it.feedId,
|
||||
accountId = it.accountId
|
||||
) == null
|
||||
) it else null
|
||||
}.also {
|
||||
insertList(it)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -83,11 +83,11 @@ class LocalRssRepository @Inject constructor(
|
|||
notificationHelper.notify(
|
||||
FeedWithArticle(
|
||||
it.feedWithArticle.feed,
|
||||
articleDao.insertIfNotExist(it.feedWithArticle.articles)
|
||||
articleDao.insertListIfNotExist(it.feedWithArticle.articles)
|
||||
)
|
||||
)
|
||||
} else {
|
||||
articleDao.insertIfNotExist(it.feedWithArticle.articles)
|
||||
articleDao.insertListIfNotExist(it.feedWithArticle.articles)
|
||||
}
|
||||
}
|
||||
Log.i("RlOG", "onCompletion: ${System.currentTimeMillis() - preTime}")
|
||||
|
|
|
@ -33,7 +33,7 @@ fun FeedItem(
|
|||
feed: Feed,
|
||||
alpha: Float = 1f,
|
||||
badgeAlpha: Float = 1f,
|
||||
isEnded: Boolean = false,
|
||||
isEnded: () -> Boolean,
|
||||
isExpanded: () -> Boolean,
|
||||
feedOptionViewModel: FeedOptionViewModel = hiltViewModel(),
|
||||
onClick: () -> Unit = {},
|
||||
|
@ -48,7 +48,7 @@ fun FeedItem(
|
|||
.padding(horizontal = 16.dp)
|
||||
.background(
|
||||
color = MaterialTheme.colorScheme.secondary.copy(alpha = alpha),
|
||||
shape = if (isEnded) ShapeBottom32 else RectangleShape,
|
||||
shape = if (isEnded()) ShapeBottom32 else RectangleShape,
|
||||
)
|
||||
.combinedClickable(
|
||||
onClick = {
|
||||
|
@ -60,7 +60,7 @@ fun FeedItem(
|
|||
}
|
||||
)
|
||||
.padding(horizontal = 14.dp)
|
||||
.padding(top = 14.dp, bottom = if (isEnded) 22.dp else 14.dp),
|
||||
.padding(top = 14.dp, bottom = if (isEnded()) 22.dp else 14.dp),
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
|
|
|
@ -218,6 +218,7 @@ fun FeedsPage(
|
|||
group = groupWithFeed.group,
|
||||
alpha = groupAlpha,
|
||||
indicatorAlpha = groupIndicatorAlpha,
|
||||
isEnded = { index == feedsUiState.groupWithFeedList.lastIndex },
|
||||
onExpanded = {
|
||||
groupsVisible[groupWithFeed.group.id] =
|
||||
!(groupsVisible[groupWithFeed.group.id] ?: false)
|
||||
|
@ -238,7 +239,7 @@ fun FeedsPage(
|
|||
feed = groupWithFeed.feed,
|
||||
alpha = groupAlpha,
|
||||
badgeAlpha = feedBadgeAlpha,
|
||||
isEnded = index != feedsUiState.groupWithFeedList.lastIndex && feedsUiState.groupWithFeedList[index + 1] is GroupFeedsView.Group,
|
||||
isEnded = { index == feedsUiState.groupWithFeedList.lastIndex || feedsUiState.groupWithFeedList[index + 1] is GroupFeedsView.Group },
|
||||
isExpanded = { groupsVisible[groupWithFeed.feed.groupId] ?: false },
|
||||
) {
|
||||
filterChange(
|
||||
|
|
|
@ -35,6 +35,7 @@ fun GroupItem(
|
|||
group: Group,
|
||||
alpha: Float = 1f,
|
||||
indicatorAlpha: Float = 1f,
|
||||
isEnded: () -> Boolean,
|
||||
isExpanded: () -> Boolean,
|
||||
groupOptionViewModel: GroupOptionViewModel = hiltViewModel(),
|
||||
onExpanded: () -> Unit = {},
|
||||
|
@ -48,7 +49,7 @@ fun GroupItem(
|
|||
.animateContentSize()
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 16.dp)
|
||||
.clip(if (isExpanded()) ShapeTop32 else Shape32)
|
||||
.clip(if (isExpanded() && !isEnded()) ShapeTop32 else Shape32)
|
||||
.background(
|
||||
MaterialTheme.colorScheme.secondary.copy(alpha = alpha)
|
||||
)
|
||||
|
|
|
@ -45,7 +45,7 @@ fun SubscribeDialog(
|
|||
val groupsState = subscribeUiState.groups.collectAsState(initial = emptyList())
|
||||
val launcher = rememberLauncherForActivityResult(ActivityResultContracts.GetContent()) {
|
||||
it?.let { uri ->
|
||||
context.contentResolver.openInputStream(uri)?.use { inputStream ->
|
||||
context.contentResolver.openInputStream(uri)?.let { inputStream ->
|
||||
subscribeViewModel.importFromInputStream(inputStream)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -94,6 +94,7 @@ fun FeedsPagePreview(
|
|||
)
|
||||
Spacer(modifier = Modifier.height(12.dp))
|
||||
GroupItem(
|
||||
isEnded = { false },
|
||||
isExpanded = { groupListExpand.value },
|
||||
group = generateGroupPreview(),
|
||||
alpha = groupAlpha,
|
||||
|
@ -103,7 +104,7 @@ fun FeedsPagePreview(
|
|||
feed = generateFeedPreview(),
|
||||
alpha = groupAlpha,
|
||||
badgeAlpha = feedBadgeAlpha,
|
||||
isEnded = true,
|
||||
isEnded = { true },
|
||||
isExpanded = { true },
|
||||
)
|
||||
Spacer(modifier = Modifier.height(12.dp))
|
||||
|
|
Loading…
Reference in New Issue
Block a user