mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-16 02:05:06 +08:00
Timeline: get off main thread when waiting for positionOrReadMarker
This commit is contained in:
parent
014da84ba6
commit
7fa4bf182a
@ -184,11 +184,13 @@ import im.vector.app.features.widgets.WidgetActivity
|
|||||||
import im.vector.app.features.widgets.WidgetArgs
|
import im.vector.app.features.widgets.WidgetArgs
|
||||||
import im.vector.app.features.widgets.WidgetKind
|
import im.vector.app.features.widgets.WidgetKind
|
||||||
import im.vector.app.features.widgets.permissions.RoomWidgetPermissionBottomSheet
|
import im.vector.app.features.widgets.permissions.RoomWidgetPermissionBottomSheet
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.flow.debounce
|
import kotlinx.coroutines.flow.debounce
|
||||||
import kotlinx.coroutines.flow.launchIn
|
import kotlinx.coroutines.flow.launchIn
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import kotlinx.parcelize.Parcelize
|
import kotlinx.parcelize.Parcelize
|
||||||
import nl.dionsegijn.konfetti.models.Shape
|
import nl.dionsegijn.konfetti.models.Shape
|
||||||
import nl.dionsegijn.konfetti.models.Size
|
import nl.dionsegijn.konfetti.models.Size
|
||||||
@ -1298,27 +1300,28 @@ class RoomDetailFragment @Inject constructor(
|
|||||||
|
|
||||||
private fun updateJumpToReadMarkerViewVisibility() {
|
private fun updateJumpToReadMarkerViewVisibility() {
|
||||||
viewLifecycleOwner.lifecycleScope.launchWhenResumed {
|
viewLifecycleOwner.lifecycleScope.launchWhenResumed {
|
||||||
withState(roomDetailViewModel) {
|
val state = roomDetailViewModel.awaitState()
|
||||||
val showJumpToUnreadBanner = when (it.unreadState) {
|
val showJumpToUnreadBanner = when (state.unreadState) {
|
||||||
UnreadState.Unknown,
|
UnreadState.Unknown,
|
||||||
UnreadState.HasNoUnread -> false
|
UnreadState.HasNoUnread -> false
|
||||||
is UnreadState.ReadMarkerNotLoaded -> true
|
is UnreadState.ReadMarkerNotLoaded -> true
|
||||||
is UnreadState.HasUnread -> {
|
is UnreadState.HasUnread -> {
|
||||||
if (it.canShowJumpToReadMarker) {
|
if (state.canShowJumpToReadMarker) {
|
||||||
val lastVisibleItem = layoutManager.findLastCompletelyVisibleItemPosition()
|
val lastVisibleItem = layoutManager.findLastCompletelyVisibleItemPosition()
|
||||||
val positionOfReadMarker = timelineEventController.getPositionOfReadMarker()
|
val positionOfReadMarker = withContext(Dispatchers.Default) {
|
||||||
if (positionOfReadMarker == null) {
|
timelineEventController.getPositionOfReadMarker()
|
||||||
false
|
|
||||||
} else {
|
|
||||||
positionOfReadMarker > lastVisibleItem
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
}
|
||||||
|
if (positionOfReadMarker == null) {
|
||||||
|
false
|
||||||
|
} else {
|
||||||
|
positionOfReadMarker > lastVisibleItem
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
views.jumpToReadMarkerView.isVisible = showJumpToUnreadBanner
|
|
||||||
}
|
}
|
||||||
|
views.jumpToReadMarkerView.isVisible = showJumpToUnreadBanner
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user