Remove redundant functions to fetch items

This commit is contained in:
davide 2022-08-15 15:22:32 +02:00
parent d47cca2f5a
commit bb5c521387

View File

@ -886,10 +886,10 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
fun doGetAccordingToTab() { fun doGetAccordingToTab() {
when (elementsShown) { when (elementsShown) {
// TODO: These three functions are not required, one is enough // TODO: These three functions are not required, one is enough
UNREAD_SHOWN -> getUnRead(appendResults) UNREAD_SHOWN -> getItems(appendResults, ItemType.UNREAD)
READ_SHOWN -> getRead(appendResults) READ_SHOWN -> getItems(appendResults, ItemType.ALL)
FAV_SHOWN -> getStarred(appendResults) FAV_SHOWN -> getItems(appendResults, ItemType.STARRED)
else -> getUnRead(appendResults) else -> getItems(appendResults, ItemType.UNREAD)
} }
} }
@ -903,38 +903,10 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
doGetAccordingToTab() doGetAccordingToTab()
} }
private fun getUnRead(appendResults: Boolean = false) { private fun getItems(appendResults: Boolean, itemType: ItemType) {
CoroutineScope(Dispatchers.Main).launch { CoroutineScope(Dispatchers.Main).launch {
binding.swipeRefreshLayout.isRefreshing = true binding.swipeRefreshLayout.isRefreshing = true
repository.displayedItems = ItemType.UNREAD repository.displayedItems = itemType
items = if (appendResults) {
repository.getNewerItems()
} else {
repository.getOlderItems()
}
binding.swipeRefreshLayout.isRefreshing = false
handleListResult()
}
}
private fun getRead(appendResults: Boolean = false) {
CoroutineScope(Dispatchers.Main).launch {
binding.swipeRefreshLayout.isRefreshing = true
repository.displayedItems = ItemType.ALL
items = if (appendResults) {
repository.getNewerItems()
} else {
repository.getOlderItems()
}
binding.swipeRefreshLayout.isRefreshing = false
handleListResult()
}
}
private fun getStarred(appendResults: Boolean = false) {
CoroutineScope(Dispatchers.Main).launch {
binding.swipeRefreshLayout.isRefreshing = true
repository.displayedItems = ItemType.STARRED
items = if (appendResults) { items = if (appendResults) {
repository.getNewerItems() repository.getNewerItems()
} else { } else {