Restore log position after collapse layout

This commit is contained in:
ajp_anton
2026-07-27 21:26:09 +00:00
parent 2584aa77be
commit 627fda6bf8
@@ -25,6 +25,7 @@ import java.text.DateFormat
import java.util.Date import java.util.Date
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.core.view.children import androidx.core.view.children
import androidx.core.view.doOnPreDraw
class ViewLogsFragment : Fragment(R.layout.fragment_view_logs) { class ViewLogsFragment : Fragment(R.layout.fragment_view_logs) {
private var binding: FragmentViewLogsBinding? = null private var binding: FragmentViewLogsBinding? = null
@@ -309,8 +310,8 @@ class ViewLogsFragment : Fragment(R.layout.fragment_view_logs) {
} }
} }
private fun captureCollapseAnchor(collapsingRow: View): CollapseAnchor { private fun captureCollapseAnchor(collapsingRow: View): CollapseAnchor? {
val currentBinding = binding ?: return CollapseAnchor.NONE val currentBinding = binding ?: return null
val scroll = currentBinding.logScroll val scroll = currentBinding.logScroll
val rowsTop = currentBinding.logRows.top val rowsTop = currentBinding.logRows.top
val topEdge = scroll.scrollY - rowsTop 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) CollapseAnchor.KEEP_BOTTOM_EDGE(bottomRow, bottomRow.bottom - bottomEdge)
bottomRow === collapsingRow && topRow != null -> bottomRow === collapsingRow && topRow != null ->
CollapseAnchor.KEEP_TOP_EDGE(topRow, topEdge - topRow.top) 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 currentBinding = binding ?: return
val scroll = currentBinding.logScroll val scroll = currentBinding.logScroll
val rows = currentBinding.logRows val rows = currentBinding.logRows
rows.post { rows.doOnPreDraw {
if (binding !== currentBinding) return@post if (binding !== currentBinding) return@doOnPreDraw
val target = when (anchor) { 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.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_TOP_EDGE -> rows.top + anchor.row.top + anchor.offset
is CollapseAnchor.KEEP_BOTTOM_EDGE -> rows.top + anchor.row.bottom - anchor.offset - scroll.height 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 { private sealed interface CollapseAnchor {
data object NONE : CollapseAnchor
data class CENTER_COLLAPSED_ROW(val row: View) : 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_TOP_EDGE(val row: View, val offset: Int) : CollapseAnchor
data class KEEP_BOTTOM_EDGE(val row: View, val offset: Int) : CollapseAnchor data class KEEP_BOTTOM_EDGE(val row: View, val offset: Int) : CollapseAnchor