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

View file

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