Restore log position after collapse layout
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user