3159: Correctly refresh timestamps (#3456)

* 3159: Correctly refresh timestamp (of all elements) and refresh all on display options change

* Remove unnecessary import

* 3159: Remove unnecessary semicolon

* 3159: Remove todo question
This commit is contained in:
UlrichKu 2023-03-21 19:01:33 +01:00 committed by GitHub
parent 3d71b6e69a
commit 0c36b369dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 24 deletions

View File

@ -217,22 +217,14 @@ class NotificationsFragment :
}
})
/**
* Collect this flow to notify the adapter that the timestamps of the visible items have
* changed
*/
// update post timestamps
val updateTimestampFlow = flow {
while (true) { delay(60000); emit(Unit) }
}.onEach {
layoutManager.findFirstVisibleItemPosition().let { first ->
first == RecyclerView.NO_POSITION && return@let
val count = layoutManager.findLastVisibleItemPosition() - first
adapter.notifyItemRangeChanged(
first,
count,
listOf(StatusBaseViewHolder.Key.KEY_CREATED)
)
while (true) {
delay(60000)
emit(Unit)
}
}.onEach {
adapter.notifyItemRangeChanged(0, adapter.itemCount, listOf(StatusBaseViewHolder.Key.KEY_CREATED))
}
viewLifecycleOwner.lifecycleScope.launch {
@ -366,20 +358,14 @@ class NotificationsFragment :
}
// Update status display from statusDisplayOptions. If the new options request
// relative time display collect the flow to periodically re-bind the UI.
// relative time display collect the flow to periodically update the timestamp in the list gui elements.
launch {
viewModel.statusDisplayOptions
.collectLatest {
// NOTE this this also triggered (emitted?) on resume.
adapter.statusDisplayOptions = it
layoutManager.findFirstVisibleItemPosition().let { first ->
first == RecyclerView.NO_POSITION && return@let
val count = layoutManager.findLastVisibleItemPosition() - first
adapter.notifyItemRangeChanged(
first,
count,
null
)
}
adapter.notifyItemRangeChanged(0, adapter.itemCount, null)
if (!it.useAbsoluteTime) {
updateTimestampFlow.collect()