Prepare the repository functions for DB implementation

This commit is contained in:
davidoskky 2022-08-20 12:37:11 +02:00
parent 1258ed3ad3
commit b9497ca939

View File

@ -62,8 +62,9 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
suspend fun getNewerItems(): ArrayList<SelfossModel.Item> {
// TODO: Use the updatedSince parameter
var fetchedItems: List<SelfossModel.Item>? = null
if (isNetworkAvailable()) {
val fetchedItems = api.getItems(
fetchedItems = api.getItems(
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
)
} else {
// TODO: Get items from the database
}
if (fetchedItems != null) {
items = ArrayList(fetchedItems)
}
} else {
// TODO: Get items from the database
}
return items
}
suspend fun getOlderItems(): ArrayList<SelfossModel.Item> {
var fetchedItems: List<SelfossModel.Item>? = null
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
)
} else {
// TODO: Get items from the database
}
if (fetchedItems != null) {
appendItems(fetchedItems)
}
} else {
// TODO: Get items from the database
}
return items
}