Modified the database structure and Updated version name

This commit is contained in:
Ash 2022-04-06 18:14:22 +08:00
parent 1ba149368b
commit aca2e9c41b
9 changed files with 58 additions and 48 deletions

View File

@ -14,7 +14,7 @@ android {
minSdk 26
targetSdk 32
versionCode 1
versionName "1.0"
versionName "0.6.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {

View File

@ -12,7 +12,7 @@
"filters": [],
"attributes": [],
"versionCode": 1,
"versionName": "1.0",
"versionName": "0.6.1",
"outputFile": "app-release.apk"
}
],

View File

@ -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

View File

@ -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,
)

View File

@ -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

View File

@ -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("""<link(.+?)rel="shortcut icon"(.+?)href="(.+?)"""")
var iconLink = regex
@ -135,30 +136,29 @@ class RssHelper @Inject constructor(
iconLink = "http:$iconLink"
}
if (iconLink.startsWith("/")) {
val domainRegex =
Regex("""http(s)?://(([\w-]+\.)+\w+(:\d{1,5})?)""")
iconLink =
"http://${domainRegex.find(articleLink)?.groups?.get(2)?.value}$iconLink"
iconLink = "${domainRegex.find(articleLink)?.value}$iconLink"
}
saveRssIcon(feedDao, feed, iconLink)
} else {
// saveRssIcon(feedDao, feed, "")
domainRegex.find(articleLink)?.value?.let {
Log.i("RLog", "favicon: ${it}")
val request = OkHttpClient()
.newCall(Request.Builder().url("$it/favicon.ico").build())
.execute()
if (request.isSuccessful) {
saveRssIcon(feedDao, feed, it)
}
}
}
}
}
@Throws(Exception::class)
suspend fun saveRssIcon(feedDao: FeedDao, feed: Feed, iconLink: String) {
withContext(dispatcherIO) {
val response = OkHttpClient()
.newCall(Request.Builder().url(iconLink).build())
.execute()
feedDao.update(
feed.apply {
icon = response.body!!.bytes()
}
)
}
private suspend fun saveRssIcon(feedDao: FeedDao, feed: Feed, iconLink: String) {
feedDao.update(
feed.apply {
icon = iconLink
}
)
}
private fun parseDate(

View File

@ -10,6 +10,7 @@ import me.ash.reader.data.entity.Group
import me.ash.reader.data.entity.GroupWithFeed
import me.ash.reader.data.module.DispatcherIO
import me.ash.reader.ui.ext.currentAccountId
import me.ash.reader.ui.ext.spacerDollar
import java.io.InputStream
import java.util.*
import javax.inject.Inject
@ -40,7 +41,9 @@ class OpmlLocalDataSource @Inject constructor(
if (!it.attributes["isDefault"].toBoolean()) {
groupWithFeedList.addGroup(
Group(
id = UUID.randomUUID().toString(),
id = context.currentAccountId.spacerDollar(
UUID.randomUUID().toString()
),
name = it.attributes["title"] ?: it.text!!,
accountId = accountId,
)
@ -49,7 +52,9 @@ class OpmlLocalDataSource @Inject constructor(
} else {
groupWithFeedList.addFeedToDefault(
Feed(
id = UUID.randomUUID().toString(),
id = context.currentAccountId.spacerDollar(
UUID.randomUUID().toString()
),
name = it.attributes["title"] ?: it.text!!,
url = it.attributes["xmlUrl"]!!,
groupId = defaultGroup.id,
@ -62,7 +67,8 @@ class OpmlLocalDataSource @Inject constructor(
} else {
var groupId = defaultGroup.id
if (!it.attributes["isDefault"].toBoolean()) {
groupId = UUID.randomUUID().toString()
groupId =
context.currentAccountId.spacerDollar(UUID.randomUUID().toString())
groupWithFeedList.addGroup(
Group(
id = groupId,
@ -74,7 +80,9 @@ class OpmlLocalDataSource @Inject constructor(
it.subElements.forEach { outline ->
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,

View File

@ -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(

View File

@ -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)
}
}
}