From aca2e9c41ba78c80cfe2b30d78f259ab2104fcdb Mon Sep 17 00:00:00 2001 From: Ash Date: Wed, 6 Apr 2022 18:14:22 +0800 Subject: [PATCH] Modified the database structure and Updated version name --- app/build.gradle | 2 +- app/release/output-metadata.json | 2 +- .../java/me/ash/reader/data/dao/ArticleDao.kt | 8 ++-- .../java/me/ash/reader/data/entity/Article.kt | 2 + .../java/me/ash/reader/data/entity/Feed.kt | 10 ++--- .../ash/reader/data/repository/RssHelper.kt | 38 +++++++++---------- .../reader/data/source/OpmlLocalDataSource.kt | 16 ++++++-- .../reader/ui/page/home/feeds/FeedsPage.kt | 10 +++-- .../ash/reader/ui/page/home/read/ReadPage.kt | 18 ++++----- 9 files changed, 58 insertions(+), 48 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 5503ec2..cc131fb 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -14,7 +14,7 @@ android { minSdk 26 targetSdk 32 versionCode 1 - versionName "1.0" + versionName "0.6.1" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables { diff --git a/app/release/output-metadata.json b/app/release/output-metadata.json index fa964f4..ec869aa 100644 --- a/app/release/output-metadata.json +++ b/app/release/output-metadata.json @@ -12,7 +12,7 @@ "filters": [], "attributes": [], "versionCode": 1, - "versionName": "1.0", + "versionName": "0.6.1", "outputFile": "app-release.apk" } ], 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 571f9e7..4509c3a 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 @@ -219,7 +219,7 @@ interface ArticleDao { """ SELECT a.id, a.date, a.title, a.author, a.rawDescription, a.shortDescription, a.fullContent, a.link, a.feedId, - a.accountId, a.isUnread, a.isStarred + a.accountId, a.isUnread, a.isStarred, a.isReadLater FROM article AS a LEFT JOIN feed AS b ON b.id = a.feedId LEFT JOIN `group` AS c ON c.id = b.groupId @@ -239,7 +239,7 @@ interface ArticleDao { """ SELECT a.id, a.date, a.title, a.author, a.rawDescription, a.shortDescription, a.fullContent, a.link, a.feedId, - a.accountId, a.isUnread, a.isStarred + a.accountId, a.isUnread, a.isStarred, a.isReadLater FROM article AS a LEFT JOIN feed AS b ON b.id = a.feedId LEFT JOIN `group` AS c ON c.id = b.groupId @@ -261,7 +261,7 @@ interface ArticleDao { """ SELECT a.id, a.date, a.title, a.author, a.rawDescription, a.shortDescription, a.fullContent, a.link, a.feedId, - a.accountId, a.isUnread, a.isStarred + a.accountId, a.isUnread, a.isStarred, a.isReadLater FROM article AS a LEFT JOIN feed AS b ON b.id = a.feedId LEFT JOIN `group` AS c ON c.id = b.groupId @@ -325,7 +325,7 @@ interface ArticleDao { """ SELECT a.id, a.date, a.title, a.author, a.rawDescription, a.shortDescription, a.fullContent, a.link, a.feedId, - a.accountId, a.isUnread, a.isStarred + a.accountId, a.isUnread, a.isStarred, a.isReadLater FROM article AS a LEFT JOIN feed AS b ON a.feedId = b.id WHERE a.feedId = :feedId diff --git a/app/src/main/java/me/ash/reader/data/entity/Article.kt b/app/src/main/java/me/ash/reader/data/entity/Article.kt index 2c0cdd5..e80cff0 100644 --- a/app/src/main/java/me/ash/reader/data/entity/Article.kt +++ b/app/src/main/java/me/ash/reader/data/entity/Article.kt @@ -41,4 +41,6 @@ data class Article( var isUnread: Boolean = true, @ColumnInfo(defaultValue = "false") var isStarred: Boolean = false, + @ColumnInfo(defaultValue = "false") + var isReadLater: Boolean = false, ) \ No newline at end of file diff --git a/app/src/main/java/me/ash/reader/data/entity/Feed.kt b/app/src/main/java/me/ash/reader/data/entity/Feed.kt index e251150..6c8f0c1 100644 --- a/app/src/main/java/me/ash/reader/data/entity/Feed.kt +++ b/app/src/main/java/me/ash/reader/data/entity/Feed.kt @@ -18,7 +18,7 @@ data class Feed( @ColumnInfo val name: String, @ColumnInfo - var icon: ByteArray? = null, + var icon: String? = null, @ColumnInfo val url: String, @ColumnInfo(index = true) @@ -32,6 +32,7 @@ data class Feed( ) { @Ignore var important: Int? = 0 + override fun equals(other: Any?): Boolean { if (this === other) return true if (javaClass != other?.javaClass) return false @@ -40,10 +41,7 @@ data class Feed( if (id != other.id) return false if (name != other.name) return false - if (icon != null) { - if (other.icon == null) return false - if (!icon.contentEquals(other.icon)) return false - } else if (other.icon != null) return false + if (icon != other.icon) return false if (url != other.url) return false if (groupId != other.groupId) return false if (accountId != other.accountId) return false @@ -57,7 +55,7 @@ data class Feed( override fun hashCode(): Int { var result = id.hashCode() result = 31 * result + name.hashCode() - result = 31 * result + (icon?.contentHashCode() ?: 0) + result = 31 * result + (icon?.hashCode() ?: 0) result = 31 * result + url.hashCode() result = 31 * result + groupId.hashCode() result = 31 * result + accountId 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 da0459e..f38997a 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 @@ -119,10 +119,11 @@ class RssHelper @Inject constructor( articleLink: String, ) { withContext(dispatcherIO) { - val execute = OkHttpClient() + val domainRegex = Regex("(http|https)://(www.)?(\\w+(\\.)?)+") + val request = OkHttpClient() .newCall(Request.Builder().url(articleLink).build()) .execute() - val content = execute.body!!.string() + val content = request.body!!.string() val regex = Regex(""" groupWithFeedList.addFeed( Feed( - id = UUID.randomUUID().toString(), + id = context.currentAccountId.spacerDollar( + UUID.randomUUID().toString() + ), name = outline.attributes["title"] ?: outline.text!!, url = outline.attributes["xmlUrl"]!!, groupId = groupId, diff --git a/app/src/main/java/me/ash/reader/ui/page/home/feeds/FeedsPage.kt b/app/src/main/java/me/ash/reader/ui/page/home/feeds/FeedsPage.kt index 083bc5f..1fa24c4 100644 --- a/app/src/main/java/me/ash/reader/ui/page/home/feeds/FeedsPage.kt +++ b/app/src/main/java/me/ash/reader/ui/page/home/feeds/FeedsPage.kt @@ -93,9 +93,13 @@ fun FeedsPage( } LaunchedEffect(filterState) { - feedsViewModel.dispatch( - FeedsViewAction.FetchData(filterState) - ) + feedsViewModel.dispatch(FeedsViewAction.FetchData(filterState)) + } + + LaunchedEffect(isSyncing) { + if (!isSyncing) { + feedsViewModel.dispatch(FeedsViewAction.FetchData(filterState)) + } } Scaffold( diff --git a/app/src/main/java/me/ash/reader/ui/page/home/read/ReadPage.kt b/app/src/main/java/me/ash/reader/ui/page/home/read/ReadPage.kt index 36040d7..9578dab 100644 --- a/app/src/main/java/me/ash/reader/ui/page/home/read/ReadPage.kt +++ b/app/src/main/java/me/ash/reader/ui/page/home/read/ReadPage.kt @@ -60,16 +60,14 @@ fun ReadPage( } } - LaunchedEffect(readViewModel.viewState) { - readViewModel.viewState.collect { - isScrollDown = false - if (it.articleWithFeed != null) { - if (it.articleWithFeed.article.isUnread) { - readViewModel.dispatch(ReadViewAction.MarkUnread(false)) - } - if (it.articleWithFeed.feed.isFullContent) { - readViewModel.dispatch(ReadViewAction.RenderFullContent) - } + LaunchedEffect(viewState.articleWithFeed?.article?.id) { + isScrollDown = false + viewState.articleWithFeed?.let { + if (it.article.isUnread) { + readViewModel.dispatch(ReadViewAction.MarkUnread(false)) + } + if (it.feed.isFullContent) { + readViewModel.dispatch(ReadViewAction.RenderFullContent) } } }