From 627fda6bf89e65ef29f544737419a011788e3cac Mon Sep 17 00:00:00 2001 From: ajp_anton Date: Mon, 27 Jul 2026 21:26:09 +0000 Subject: [PATCH] Restore log position after collapse layout --- .../se/ajpanton/notificationlog/ViewLogsFragment.kt | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/se/ajpanton/notificationlog/ViewLogsFragment.kt b/app/src/main/java/se/ajpanton/notificationlog/ViewLogsFragment.kt index dfea157..6894af0 100644 --- a/app/src/main/java/se/ajpanton/notificationlog/ViewLogsFragment.kt +++ b/app/src/main/java/se/ajpanton/notificationlog/ViewLogsFragment.kt @@ -25,6 +25,7 @@ import java.text.DateFormat import java.util.Date import androidx.fragment.app.Fragment import androidx.core.view.children +import androidx.core.view.doOnPreDraw class ViewLogsFragment : Fragment(R.layout.fragment_view_logs) { private var binding: FragmentViewLogsBinding? = null @@ -309,8 +310,8 @@ class ViewLogsFragment : Fragment(R.layout.fragment_view_logs) { } } - private fun captureCollapseAnchor(collapsingRow: View): CollapseAnchor { - val currentBinding = binding ?: return CollapseAnchor.NONE + private fun captureCollapseAnchor(collapsingRow: View): CollapseAnchor? { + val currentBinding = binding ?: return null val scroll = currentBinding.logScroll val rowsTop = currentBinding.logRows.top val topEdge = scroll.scrollY - rowsTop @@ -323,7 +324,7 @@ class ViewLogsFragment : Fragment(R.layout.fragment_view_logs) { CollapseAnchor.KEEP_BOTTOM_EDGE(bottomRow, bottomRow.bottom - bottomEdge) bottomRow === collapsingRow && topRow != null -> CollapseAnchor.KEEP_TOP_EDGE(topRow, topEdge - topRow.top) - else -> CollapseAnchor.NONE + else -> null } } @@ -331,10 +332,9 @@ class ViewLogsFragment : Fragment(R.layout.fragment_view_logs) { val currentBinding = binding ?: return val scroll = currentBinding.logScroll val rows = currentBinding.logRows - rows.post { - if (binding !== currentBinding) return@post + rows.doOnPreDraw { + if (binding !== currentBinding) return@doOnPreDraw val target = when (anchor) { - CollapseAnchor.NONE -> return@post is CollapseAnchor.CENTER_COLLAPSED_ROW -> rows.top + anchor.row.top + anchor.row.height / 2 - scroll.height / 2 is CollapseAnchor.KEEP_TOP_EDGE -> rows.top + anchor.row.top + anchor.offset is CollapseAnchor.KEEP_BOTTOM_EDGE -> rows.top + anchor.row.bottom - anchor.offset - scroll.height @@ -360,7 +360,6 @@ class ViewLogsFragment : Fragment(R.layout.fragment_view_logs) { ) private sealed interface CollapseAnchor { - data object NONE : CollapseAnchor data class CENTER_COLLAPSED_ROW(val row: View) : CollapseAnchor data class KEEP_TOP_EDGE(val row: View, val offset: Int) : CollapseAnchor data class KEEP_BOTTOM_EDGE(val row: View, val offset: Int) : CollapseAnchor