Use /sources/stats in the home #133
@ -1,6 +1,5 @@
|
||||
package bou.amine.apps.readerforselfossv2.model
|
||||
|
||||
import bou.amine.apps.readerforselfossv2.dao.SOURCE
|
||||
import bou.amine.apps.readerforselfossv2.utils.DateUtils
|
||||
import bou.amine.apps.readerforselfossv2.utils.getHtmlDecoded
|
||||
import kotlinx.serialization.KSerializer
|
||||
@ -70,26 +69,6 @@ class SelfossModel {
|
||||
var unread: Int?
|
||||
var error: String?
|
||||
var icon: String?
|
||||
|
||||
fun checkSameSource(source: Source): Boolean {
|
||||
return this.id != source.id
|
||||
}
|
||||
|
||||
fun update(source: Source) {
|
||||
if (source is SourceDetail) {
|
||||
this.update(source)
|
||||
} else if (source is SourceStats) {
|
||||
this.update(source)
|
||||
}
|
||||
}
|
||||
fun update(source: SourceStats)
|
||||
|
||||
fun update(source: SourceDetail)
|
||||
|
||||
fun toEntity(): SOURCE
|
||||
|
||||
operator fun component1(): Int { return id }
|
||||
operator fun component2(): String { return title }
|
||||
}
|
||||
|
||||
@Serializable
|
||||
AmineB marked this conversation as resolved
|
||||
@ -99,36 +78,7 @@ class SelfossModel {
|
||||
override var unread: Int?,
|
||||
AmineB marked this conversation as resolved
AmineB
commented
This should be an "abstract" method. This should be an "abstract" method.
|
||||
override var error: String? = null,
|
||||
override var icon: String? = null
|
||||
) : Source {
|
||||
override fun update(source: SourceStats) {
|
||||
if (checkSameSource(source)) {
|
||||
throw Exception()
|
||||
}
|
||||
this.title = source.title
|
||||
this.unread = source.unread
|
||||
}
|
||||
|
||||
override fun update(source: SourceDetail) {
|
||||
if (checkSameSource(source)) {
|
||||
throw Exception()
|
||||
}
|
||||
this.title = source.title
|
||||
this.error = source.error
|
||||
this.icon = source.icon
|
||||
}
|
||||
|
||||
override fun toEntity(): SOURCE {
|
||||
return SOURCE(
|
||||
this.id.toString(),
|
||||
this.title.getHtmlDecoded(),
|
||||
null,
|
||||
null,
|
||||
this.error,
|
||||
this.icon,
|
||||
null
|
||||
)
|
||||
}
|
||||
}
|
||||
) : Source
|
||||
|
||||
@Serializable
|
||||
data class SourceDetail(
|
||||
@ -141,39 +91,7 @@ class SelfossModel {
|
||||
override var error: String?,
|
||||
AmineB marked this conversation as resolved
AmineB
commented
What are these two methods ? What are these two methods ?
|
||||
override var icon: String?,
|
||||
var params: SourceParams?
|
||||
) : Source {
|
||||
override fun update(source: SourceStats) {
|
||||
if (checkSameSource(source)) {
|
||||
throw Exception()
|
||||
}
|
||||
this.title = source.title
|
||||
this.unread = source.unread
|
||||
}
|
||||
|
||||
override fun update(source: SourceDetail) {
|
||||
if (checkSameSource(source)) {
|
||||
throw Exception()
|
||||
}
|
||||
this.title = source.title
|
||||
this.tags = source.tags
|
||||
this.spout = source.spout
|
||||
this.error = source.error
|
||||
this.icon = source.icon
|
||||
this.params = source.params
|
||||
}
|
||||
|
||||
override fun toEntity(): SOURCE {
|
||||
return SOURCE(
|
||||
this.id.toString(),
|
||||
this.title.getHtmlDecoded(),
|
||||
this.tags?.joinToString(","),
|
||||
this.spout,
|
||||
this.error,
|
||||
this.icon.orEmpty(),
|
||||
this.params?.url
|
||||
)
|
||||
}
|
||||
}
|
||||
) : Source
|
||||
|
||||
@Serializable
|
||||
data class SourceParams(
|
||||
|
@ -180,27 +180,6 @@ class Repository(
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateSources(newSources: List<SelfossModel.Source>): List<SelfossModel.Source> {
|
||||
AmineB marked this conversation as resolved
AmineB
commented
There should be two methods:
There should be two methods:
```
suspend fun getSourceDetailsOrStats(): ArrayList<SelfossModel.Source> {
if (IS PUBLIC MODE) {
return api.sourcesStats()
} else {
copy/past the content of the old `getSources()` method
}
}
suspend fun getSourcesDetails(): List<SelfossModel.SourceDetail> { // This will be called in the sources activity
if (isNetworkAvailable()) {
return api.sourcesDetailed().data.orEmpty()
}
return emptyList<>()
}
```
davidoskky
commented
I'm not sure about this. Doing so is fine only as long as we don't care about the unread count. That is only available in the stats. I'm not sure about this. Doing so is fine only as long as we don't care about the unread count. That is only available in the stats.
If we don't plan on displaying the unread count, this is fine; otherwise the amount of unread articles should be available in the home activity.
AmineB
commented
Unread count was complicated code-wise. We have no idea if the feature was used/useful, so for now, let's not add it back. Unread count was complicated code-wise. We have no idea if the feature was used/useful, so for now, let's not add it back.
davidoskky
commented
I did find the tags unread count useful. I will not add this here; we can always implement it later. I did find the tags unread count useful. I will not add this here; we can always implement it later.
|
||||
val isDatabaseEnabled =
|
||||
appSettingsService.isItemCachingEnabled() || !appSettingsService.isUpdateSourcesEnabled()
|
||||
return if (isDatabaseEnabled) {
|
||||
var sources = getDBSources().map { it.toView() }
|
||||
for (source in sources) {
|
||||
val newSource = newSources.find { it.id == source.id }
|
||||
if (newSource != null) {
|
||||
source.update(newSource)
|
||||
}
|
||||
}
|
||||
|
||||
sources = (sources + newSources).distinctBy { it.id }
|
||||
|
||||
resetDBSourcesWithData(sources)
|
||||
sources
|
||||
} else {
|
||||
newSources
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun getSourcesDetailsOrStats(): ArrayList<SelfossModel.Source> {
|
||||
var sources = ArrayList<SelfossModel.Source>()
|
||||
val isDatabaseEnabled =
|
||||
@ -211,7 +190,7 @@ class Repository(
|
||||
val apiSources = api.sourcesStats()
|
||||
if (apiSources.success && apiSources.data != null) {
|
||||
fetchedSources = true
|
||||
sources = updateSources(apiSources.data) as ArrayList<SelfossModel.Source>
|
||||
sources = apiSources.data as ArrayList<SelfossModel.Source>
|
||||
}
|
||||
} else {
|
||||
sources = getSourcesDetails() as ArrayList<SelfossModel.Source>
|
||||
@ -232,7 +211,10 @@ class Repository(
|
||||
val apiSources = api.sourcesDetailed()
|
||||
if (apiSources.success && apiSources.data != null) {
|
||||
fetchedSources = true
|
||||
sources = updateSources(apiSources.data) as ArrayList<SelfossModel.SourceDetail>
|
||||
sources = apiSources.data
|
||||
AmineB marked this conversation as resolved
AmineB
commented
We only update the DB from We only update the DB from `getSourcesDetails`
|
||||
if (isDatabaseEnabled) {
|
||||
resetDBSourcesWithData(sources)
|
||||
}
|
||||
}
|
||||
} else if (isDatabaseEnabled) {
|
||||
sources = getDBSources().map { it.toView() } as ArrayList<SelfossModel.SourceDetail>
|
||||
@ -523,7 +505,7 @@ class Repository(
|
||||
}
|
||||
}
|
||||
|
||||
private fun resetDBSourcesWithData(sources: List<SelfossModel.Source>) {
|
||||
private fun resetDBSourcesWithData(sources: List<SelfossModel.SourceDetail>) {
|
||||
db.sourcesQueries.deleteAllSources()
|
||||
|
||||
db.sourcesQueries.transaction {
|
||||
|
@ -12,7 +12,7 @@ fun TAG.toView(): SelfossModel.Tag =
|
||||
this.unread.toInt()
|
||||
)
|
||||
|
||||
fun SOURCE.toView(): SelfossModel.Source =
|
||||
fun SOURCE.toView(): SelfossModel.SourceDetail =
|
||||
SelfossModel.SourceDetail(
|
||||
this.id.toInt(),
|
||||
this.title,
|
||||
@ -24,6 +24,17 @@ fun SOURCE.toView(): SelfossModel.Source =
|
||||
if (this.url != null) SelfossModel.SourceParams(this.url) else null
|
||||
)
|
||||
|
||||
fun SelfossModel.SourceDetail.toEntity(): SOURCE =
|
||||
SOURCE(
|
||||
this.id.toString(),
|
||||
this.title.getHtmlDecoded(),
|
||||
this.tags?.joinToString(",").orEmpty(),
|
||||
this.spout.orEmpty(),
|
||||
this.error.orEmpty(),
|
||||
this.icon.orEmpty(),
|
||||
this.params?.url
|
||||
)
|
||||
|
||||
fun SelfossModel.Tag.toEntity(): TAG =
|
||||
TAG(
|
||||
this.tag,
|
||||
|
@ -1,10 +1,10 @@
|
||||
CREATE TABLE SOURCE (
|
||||
`id` TEXT NOT NULL,
|
||||
`title` TEXT NOT NULL,
|
||||
`tags` TEXT,
|
||||
`spout` TEXT,
|
||||
`error` TEXT,
|
||||
`icon` TEXT,
|
||||
`tags` TEXT NOT NULL,
|
||||
AmineB marked this conversation as resolved
AmineB
commented
As As `unread` is only in the public mode, let's not change this.
|
||||
`spout` TEXT NOT NULL,
|
||||
`error` TEXT NOT NULL,
|
||||
`icon` TEXT NOT NULL,
|
||||
AmineB marked this conversation as resolved
AmineB
commented
Why was everything changed to nullable ? Why was everything changed to nullable ?
|
||||
`url` TEXT,
|
||||
PRIMARY KEY(`id`)
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user
I don't understand why this is needed ?