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> { suspend fun getNewerItems(): ArrayList<SelfossModel.Item> {
// TODO: Use the updatedSince parameter // TODO: Use the updatedSince parameter
var fetchedItems: List<SelfossModel.Item>? = null
if (isNetworkAvailable()) { if (isNetworkAvailable()) {
val fetchedItems = api.getItems( fetchedItems = api.getItems(
displayedItems.type, displayedItems.type,
settings.getString("prefer_api_items_number", "200").toInt(), settings.getString("prefer_api_items_number", "200").toInt(),
offset = 0, offset = 0,
@ -72,20 +73,21 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
searchFilter, searchFilter,
null null
) )
} else {
// TODO: Get items from the database
}
if (fetchedItems != null) { if (fetchedItems != null) {
items = ArrayList(fetchedItems) items = ArrayList(fetchedItems)
} }
} else {
// TODO: Get items from the database
}
return items return items
} }
suspend fun getOlderItems(): ArrayList<SelfossModel.Item> { suspend fun getOlderItems(): ArrayList<SelfossModel.Item> {
var fetchedItems: List<SelfossModel.Item>? = null
if (isNetworkAvailable()) { if (isNetworkAvailable()) {
val offset = items.size val offset = items.size
val fetchedItems = api.getItems( fetchedItems = api.getItems(
displayedItems.type, displayedItems.type,
settings.getString("prefer_api_items_number", "200").toInt(), settings.getString("prefer_api_items_number", "200").toInt(),
offset, offset,
@ -94,13 +96,13 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
searchFilter, searchFilter,
null null
) )
} else {
// TODO: Get items from the database
}
if (fetchedItems != null) { if (fetchedItems != null) {
appendItems(fetchedItems) appendItems(fetchedItems)
} }
} else {
// TODO: Get items from the database
}
return items return items
} }