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
1 changed files with 10 additions and 24 deletions
|
@ -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()
|
||||||
|
|
Loading…
Reference in a new issue