Inserting items in the DB.
This commit is contained in:
parent
2547ce824a
commit
3b8f4991e9
@ -168,14 +168,10 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
|
|||||||
getElementsAccordingToTab()
|
getElementsAccordingToTab()
|
||||||
|
|
||||||
|
|
||||||
|
CoroutineScope(Dispatchers.Main).launch {
|
||||||
|
repository.tryToCacheItemsAndGetNewOnes()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// TODO: items caching should be done in the background when starting the app, like background.kt does
|
|
||||||
// fetchedItems?.let {
|
|
||||||
// CoroutineScope(Dispatchers.Main).launch {
|
|
||||||
// insertDBItems(it)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleSwipeRefreshLayout() {
|
private fun handleSwipeRefreshLayout() {
|
||||||
|
@ -81,12 +81,7 @@ override fun doWork(): Result {
|
|||||||
}
|
}
|
||||||
|
|
||||||
launch {
|
launch {
|
||||||
try {
|
handleNewItemsNotification(repository.tryToCacheItemsAndGetNewOnes(), notifyNewItems, notificationManager)
|
||||||
val newItems = repository.getMaxItemsForBackground(ItemType.UNREAD)
|
|
||||||
handleNewItemsNotification(newItems, notifyNewItems, notificationManager)
|
|
||||||
repository.getMaxItemsForBackground(ItemType.ALL)
|
|
||||||
repository.getMaxItemsForBackground(ItemType.STARRED)
|
|
||||||
} catch (e: Throwable) {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -413,4 +413,16 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
|
|||||||
|
|
||||||
private fun updateDBItem(item: SelfossModel.Item) =
|
private fun updateDBItem(item: SelfossModel.Item) =
|
||||||
db.itemsQueries.updateItem(item.datetime, item.getTitleDecoded(), item.content, item.unread, item.starred, item.thumbnail, item.icon, item.link, item.sourcetitle, item.tags.joinToString(","), item.id.toString())
|
db.itemsQueries.updateItem(item.datetime, item.getTitleDecoded(), item.content, item.unread, item.starred, item.thumbnail, item.icon, item.link, item.sourcetitle, item.tags.joinToString(","), item.id.toString())
|
||||||
|
|
||||||
|
|
||||||
|
suspend fun tryToCacheItemsAndGetNewOnes(): List<SelfossModel.Item>? {
|
||||||
|
try {
|
||||||
|
val newItems = getMaxItemsForBackground(ItemType.UNREAD)
|
||||||
|
val allItems = getMaxItemsForBackground(ItemType.ALL)
|
||||||
|
val starredItems = getMaxItemsForBackground(ItemType.STARRED)
|
||||||
|
insertDBItems(newItems.orEmpty() + allItems.orEmpty() + starredItems.orEmpty())
|
||||||
|
return newItems
|
||||||
|
} catch (e: Throwable) {}
|
||||||
|
return emptyList()
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user