network #28
@ -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
|
||||
// TODO: Use the updatedSince parameter
|
||||
AmineB marked this conversation as resolved
Outdated
AmineB
commented
This should be moved after the 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
AmineB
commented
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
AmineB
commented
This should be moved after the 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
AmineB
commented
This should be a todo This should be a todo
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user
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.
The
else
block would have the BD fetching that'll assign the DB items tofetchedItems
.