Add scroll-to-top control for logs
This commit is contained in:
@@ -29,6 +29,12 @@ class ViewLogsFragment : Fragment(R.layout.fragment_view_logs) {
|
|||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
binding = FragmentViewLogsBinding.bind(view)
|
binding = FragmentViewLogsBinding.bind(view)
|
||||||
binding!!.logsRefresh.setOnRefreshListener(::loadLogs)
|
binding!!.logsRefresh.setOnRefreshListener(::loadLogs)
|
||||||
|
binding!!.logScroll.setOnScrollChangeListener { _, _, scrollY, _, _ ->
|
||||||
|
binding?.scrollToTop?.visibility = if (scrollY > dp(SCROLL_TO_TOP_THRESHOLD_DP)) View.VISIBLE else View.GONE
|
||||||
|
}
|
||||||
|
binding!!.scrollToTop.setOnClickListener {
|
||||||
|
binding?.logScroll?.smoothScrollTo(0, 0)
|
||||||
|
}
|
||||||
loadLogs()
|
loadLogs()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -236,5 +242,6 @@ class ViewLogsFragment : Fragment(R.layout.fragment_view_logs) {
|
|||||||
private companion object {
|
private companion object {
|
||||||
const val LEFT_PILL_WEIGHT = 0.42f
|
const val LEFT_PILL_WEIGHT = 0.42f
|
||||||
const val RIGHT_PILL_WEIGHT = 0.58f
|
const val RIGHT_PILL_WEIGHT = 0.58f
|
||||||
|
const val SCROLL_TO_TOP_THRESHOLD_DP = 120
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,15 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||||
android:id="@+id/logs_refresh"
|
android:id="@+id/logs_refresh"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
<ScrollView
|
<ScrollView
|
||||||
|
android:id="@+id/log_scroll"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
@@ -29,3 +34,14 @@
|
|||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||||
|
|
||||||
|
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||||
|
android:id="@+id/scroll_to_top"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="end|bottom"
|
||||||
|
android:layout_margin="16dp"
|
||||||
|
android:contentDescription="Scroll to top"
|
||||||
|
android:visibility="gone"
|
||||||
|
android:src="@android:drawable/arrow_up_float" />
|
||||||
|
</FrameLayout>
|
||||||
|
|||||||
Reference in New Issue
Block a user