fix: do not reload items on resume.
This commit is contained in:
parent
ceae91206d
commit
bdf2bb8b31
@ -120,6 +120,7 @@ class HomeActivity :
|
|||||||
binding.swipeRefreshLayout.setOnRefreshListener {
|
binding.swipeRefreshLayout.setOnRefreshListener {
|
||||||
repository.offlineOverride = false
|
repository.offlineOverride = false
|
||||||
lastFetchDone = false
|
lastFetchDone = false
|
||||||
|
items.clear()
|
||||||
getElementsAccordingToTab()
|
getElementsAccordingToTab()
|
||||||
binding.swipeRefreshLayout.isRefreshing = false
|
binding.swipeRefreshLayout.isRefreshing = false
|
||||||
}
|
}
|
||||||
@ -458,23 +459,27 @@ class HomeActivity :
|
|||||||
appendResults: Boolean,
|
appendResults: Boolean,
|
||||||
itemType: ItemType,
|
itemType: ItemType,
|
||||||
) {
|
) {
|
||||||
CountingIdlingResourceSingleton.increment()
|
if ((appendResults && items.size > 0) || (!appendResults && items.size == 0)) {
|
||||||
binding.swipeRefreshLayout.isRefreshing = true
|
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
|
||||||
repository.displayedItems = itemType
|
|
||||||
items =
|
|
||||||
if (appendResults) {
|
|
||||||
repository.getOlderItems()
|
|
||||||
} else {
|
|
||||||
repository.getNewerItems()
|
|
||||||
}
|
|
||||||
CountingIdlingResourceSingleton.increment()
|
CountingIdlingResourceSingleton.increment()
|
||||||
launch(Dispatchers.Main) {
|
binding.swipeRefreshLayout.isRefreshing = true
|
||||||
binding.swipeRefreshLayout.isRefreshing = false
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
handleListResult()
|
repository.displayedItems = itemType
|
||||||
|
items =
|
||||||
|
if (appendResults) {
|
||||||
|
repository.getOlderItems()
|
||||||
|
} else {
|
||||||
|
repository.getNewerItems()
|
||||||
|
}
|
||||||
|
CountingIdlingResourceSingleton.increment()
|
||||||
|
launch(Dispatchers.Main) {
|
||||||
|
binding.swipeRefreshLayout.isRefreshing = false
|
||||||
|
handleListResult()
|
||||||
|
CountingIdlingResourceSingleton.decrement()
|
||||||
|
}
|
||||||
CountingIdlingResourceSingleton.decrement()
|
CountingIdlingResourceSingleton.decrement()
|
||||||
}
|
}
|
||||||
CountingIdlingResourceSingleton.decrement()
|
} else {
|
||||||
|
handleListResult()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ import org.kodein.di.instance
|
|||||||
|
|
||||||
class ItemCardAdapter(
|
class ItemCardAdapter(
|
||||||
override val app: Activity,
|
override val app: Activity,
|
||||||
override val items: ArrayList<SelfossModel.Item>,
|
override var items: ArrayList<SelfossModel.Item>,
|
||||||
override val updateHomeItems: (ArrayList<SelfossModel.Item>) -> Unit,
|
override val updateHomeItems: (ArrayList<SelfossModel.Item>) -> Unit,
|
||||||
) : ItemsAdapter<ItemCardAdapter.ViewHolder>() {
|
) : ItemsAdapter<ItemCardAdapter.ViewHolder>() {
|
||||||
override lateinit var binding: CardItemBinding
|
override lateinit var binding: CardItemBinding
|
||||||
|
@ -21,7 +21,7 @@ import org.kodein.di.instance
|
|||||||
|
|
||||||
class ItemListAdapter(
|
class ItemListAdapter(
|
||||||
override val app: Activity,
|
override val app: Activity,
|
||||||
override val items: ArrayList<SelfossModel.Item>,
|
override var items: ArrayList<SelfossModel.Item>,
|
||||||
override val updateHomeItems: (ArrayList<SelfossModel.Item>) -> Unit,
|
override val updateHomeItems: (ArrayList<SelfossModel.Item>) -> Unit,
|
||||||
) : ItemsAdapter<ItemListAdapter.ViewHolder>() {
|
) : ItemsAdapter<ItemListAdapter.ViewHolder>() {
|
||||||
override lateinit var binding: ListItemBinding
|
override lateinit var binding: ListItemBinding
|
||||||
|
@ -21,7 +21,7 @@ import org.kodein.di.DIAware
|
|||||||
abstract class ItemsAdapter<VH : RecyclerView.ViewHolder?> :
|
abstract class ItemsAdapter<VH : RecyclerView.ViewHolder?> :
|
||||||
RecyclerView.Adapter<VH>(),
|
RecyclerView.Adapter<VH>(),
|
||||||
DIAware {
|
DIAware {
|
||||||
abstract val items: ArrayList<SelfossModel.Item>
|
abstract var items: ArrayList<SelfossModel.Item>
|
||||||
abstract val repository: Repository
|
abstract val repository: Repository
|
||||||
abstract val binding: ViewBinding
|
abstract val binding: ViewBinding
|
||||||
abstract val appSettingsService: AppSettingsService
|
abstract val appSettingsService: AppSettingsService
|
||||||
@ -31,8 +31,7 @@ abstract class ItemsAdapter<VH : RecyclerView.ViewHolder?> :
|
|||||||
protected val c: Context get() = app.baseContext
|
protected val c: Context get() = app.baseContext
|
||||||
|
|
||||||
fun updateAllItems(items: ArrayList<SelfossModel.Item>) {
|
fun updateAllItems(items: ArrayList<SelfossModel.Item>) {
|
||||||
this.items.clear()
|
this.items = items
|
||||||
this.items.addAll(items)
|
|
||||||
updateHomeItems(items)
|
updateHomeItems(items)
|
||||||
notifyDataSetChanged()
|
notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user