network #28

Merged
AmineB merged 28 commits from davidoskky/ReaderForSelfoss-multiplatform:network into master 2022-08-22 19:01:16 +00:00
Showing only changes of commit b9497ca939 - Show all commits

View File

@ -62,8 +62,9 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
suspend fun getNewerItems(): ArrayList<SelfossModel.Item> {
AmineB marked this conversation as resolved Outdated

This block should be after the else, since the db will work as a fallback and we'll get the items from there.

Same for the other block later.

This block should be after the else, since the db will work as a fallback and we'll get the items from there. Same for the other block later.

I'm not sure how the database will handle this.
This is correct as of now, moving this block after the else will generate errors if the else block is encountered since the fetchedItems variables is only defined within the if block.

I'm not sure how the database will handle this. This is correct as of now, moving this block after the else will generate errors if the else block is encountered since the fetchedItems variables is only defined within the if block.

The else block would have the BD fetching that'll assign the DB items to fetchedItems.

The `else` block would have the BD fetching that'll assign the DB items to `fetchedItems`.
// TODO: Use the updatedSince parameter
AmineB marked this conversation as resolved Outdated

This should be moved after the else block

This should be moved after the `else` block
var fetchedItems: List<SelfossModel.Item>? = null
if (isNetworkAvailable()) {
val fetchedItems = api.getItems(
fetchedItems = api.getItems(
AmineB marked this conversation as resolved Outdated

The error message should be displayed when the network status change, not after every api call.

Same for every comment like this one.

The error message should be displayed when the network status change, not after every api call. Same for every comment like this one.
displayedItems.type,
settings.getString("prefer_api_items_number", "200").toInt(),
offset = 0,
@ -72,20 +73,21 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
searchFilter,
null
)
if (fetchedItems != null) {
items = ArrayList(fetchedItems)
}
} else {
// TODO: Get items from the database
}
if (fetchedItems != null) {
items = ArrayList(fetchedItems)
}
return items
}
suspend fun getOlderItems(): ArrayList<SelfossModel.Item> {
var fetchedItems: List<SelfossModel.Item>? = null
AmineB marked this conversation as resolved Outdated

This should be moved after the else block

This should be moved after the `else` block
if (isNetworkAvailable()) {
val offset = items.size
val fetchedItems = api.getItems(
fetchedItems = api.getItems(
displayedItems.type,
settings.getString("prefer_api_items_number", "200").toInt(),
offset,
@ -94,13 +96,13 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
searchFilter,
null
)
if (fetchedItems != null) {
appendItems(fetchedItems)
}
} else {
// TODO: Get items from the database
}
if (fetchedItems != null) {
appendItems(fetchedItems)
}
return items
}
AmineB marked this conversation as resolved Outdated

This should be a todo

This should be a todo