Prepare the repository functions for DB implementation

This commit is contained in:
davidoskky 2022-08-20 12:37:11 +02:00
parent 3aa6934f86
commit ef0f326073

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
) )
if (fetchedItems != null) {
items = ArrayList(fetchedItems)
}
} else { } else {
// TODO: Get items from the database // TODO: Get items from the database
} }
if (fetchedItems != null) {
items = ArrayList(fetchedItems)
}
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
) )
if (fetchedItems != null) {
appendItems(fetchedItems)
}
} else { } else {
// TODO: Get items from the database // TODO: Get items from the database
} }
if (fetchedItems != null) {
appendItems(fetchedItems)
}
return items return items
} }