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:
parent
3d71b6e69a
commit
0c36b369dd
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue