WIP: HomeActivity cleanup #40

Closed
davidoskky wants to merge 3 commits from davidoskky/ReaderForSelfoss-multiplatform:dispatchers into master
Showing only changes of commit 8c817b5938 - Show all commits

View File

@ -46,7 +46,12 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
// TODO: Dispatchers.IO not available in KMM, an alternative solution should be found
CoroutineScope(Dispatchers.Main).launch {
updateApiVersion()
Review

updateApiVersion() and reloadBadges() both check the network availability. This change isn't needed.

`updateApiVersion()` and `reloadBadges()` both check the network availability. This change isn't needed.
Review

When init is run the connectivity check always fails.
This allows retrieving the badges every time connectivity gets back.
We could include here all operations that should be run as soon as network connectivity is available, such as fetching sources and tags.

When init is run the connectivity check always fails. This allows retrieving the badges every time connectivity gets back. We could include here all operations that should be run as soon as network connectivity is available, such as fetching sources and tags.
Review

When init is run the connectivity check always fails.

So this is a bug that should be fixed instead of having this workaround.

This allows retrieving the badges every time connectivity gets back.

This isn't a good thing, since items arn't refreshed on connectivity change. We would have a difference in the items count and the badge count.

We could include here all operations that should be run as soon as network connectivity is available, such as fetching sources and tags.

Fetching sources and tags can be limited via a update_sources. It's also something that shouldn't be done as much as items fetching.

> When init is run the connectivity check always fails. So this is a bug that should be fixed instead of having this workaround. > This allows retrieving the badges every time connectivity gets back. This isn't a good thing, since items arn't refreshed on connectivity change. We would have a difference in the items count and the badge count. > We could include here all operations that should be run as soon as network connectivity is available, *such as fetching sources and tags.* Fetching sources and tags can be limited via a `update_sources`. It's also something that shouldn't be done as much as items fetching.
reloadBadges()
isConnectionAvailable.collect { connectionAvailable ->
if (connectionAvailable) {
updateApiVersion()
reloadBadges()
}
}
}
}
@ -132,12 +137,12 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
_badgeStarred.value = response.starred
success = true
}
} else {
} else if (itemsCaching) {
// TODO: do this differently, because it's not efficient
val dbItems = getDBItems()
_badgeUnread.value = dbItems.filter { item -> item.unread }.size
_badgeStarred.value = dbItems.filter { item -> item.starred }.size
_badgeAll.value = items.size
_badgeAll.value = dbItems.size
}
return success
}
@ -437,13 +442,16 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
suspend fun tryToCacheItemsAndGetNewOnes(): List<SelfossModel.Item>? {
try {
val newItems = getMaxItemsForBackground(ItemType.UNREAD)
val allItems = getMaxItemsForBackground(ItemType.ALL)
val starredItems = getMaxItemsForBackground(ItemType.STARRED)
insertDBItems(newItems.orEmpty() + allItems.orEmpty() + starredItems.orEmpty())
return newItems
} catch (e: Throwable) {}
if (itemsCaching) {
try {
val newItems = getMaxItemsForBackground(ItemType.UNREAD)
val allItems = getMaxItemsForBackground(ItemType.ALL)
val starredItems = getMaxItemsForBackground(ItemType.STARRED)
insertDBItems(newItems.orEmpty() + allItems.orEmpty() + starredItems.orEmpty())
return newItems
} catch (e: Throwable) {
}
}
return emptyList()
}