Added one-click scroll to the bottom
This commit is contained in:
parent
326eee8c83
commit
074b1f8c61
@ -43,6 +43,8 @@ class LogViewModel(
|
||||
private val logItem get() = items[0] as LogRvItem
|
||||
private val magiskLogItem get() = items[1] as MagiskLogRvItem
|
||||
|
||||
val scrollPosition = KObservableField(0)
|
||||
|
||||
init {
|
||||
currentPage.addOnPropertyChangedCallback {
|
||||
it ?: return@addOnPropertyChangedCallback
|
||||
@ -59,6 +61,10 @@ class LogViewModel(
|
||||
else -> ""
|
||||
}
|
||||
|
||||
fun scrollDownPressed() {
|
||||
scrollPosition.value = magiskLogItem.items.size - 1
|
||||
}
|
||||
|
||||
fun refresh() {
|
||||
fetchLogs().subscribeK { logItem.update(it) }
|
||||
fetchMagiskLog().subscribeK { magiskLogItem.update(it) }
|
||||
|
@ -11,8 +11,10 @@ import androidx.databinding.InverseBindingAdapter
|
||||
import androidx.databinding.InverseBindingListener
|
||||
import androidx.drawerlayout.widget.DrawerLayout
|
||||
import androidx.interpolator.view.animation.FastOutSlowInInterpolator
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.viewpager.widget.ViewPager
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
import com.google.android.material.navigation.NavigationView
|
||||
import com.skoumal.teanity.extensions.subscribeK
|
||||
import com.topjohnwu.magisk.R
|
||||
@ -177,3 +179,31 @@ fun setScrollToLast(view: RecyclerView, shouldScrollToLast: Boolean) {
|
||||
view.adapter?.removeListener()
|
||||
}
|
||||
}
|
||||
|
||||
@BindingAdapter("hide")
|
||||
fun setHidden(view: FloatingActionButton, hide: Boolean) {
|
||||
if (hide) view.hide() else view.show()
|
||||
}
|
||||
|
||||
@BindingAdapter("scrollPosition", "scrollPositionSmooth", requireAll = false)
|
||||
fun setScrollPosition(view: RecyclerView, position: Int, smoothScroll: Boolean) = when {
|
||||
smoothScroll -> view.smoothScrollToPosition(position)
|
||||
else -> view.scrollToPosition(position)
|
||||
}
|
||||
|
||||
@BindingAdapter("recyclerScrollEvent")
|
||||
fun setScrollListener(view: RecyclerView, listener: InverseBindingListener) {
|
||||
view.addOnScrollListener(object : RecyclerView.OnScrollListener() {
|
||||
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
|
||||
// don't change this or the recycler will stop at every line, effectively disabling smooth scroll
|
||||
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
|
||||
listener.onChange()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@InverseBindingAdapter(attribute = "scrollPosition", event = "recyclerScrollEvent")
|
||||
fun getScrollPosition(view: RecyclerView) = (view.layoutManager as? LinearLayoutManager)
|
||||
?.findLastCompletelyVisibleItemPosition()
|
||||
?: -1
|
10
app/src/main/res/drawable/ic_arrow_down.xml
Normal file
10
app/src/main/res/drawable/ic_arrow_down.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#000"
|
||||
android:pathData="M16.59,5.59L18,7L12,13L6,7L7.41,5.59L12,10.17L16.59,5.59M16.59,11.59L18,13L12,19L6,13L7.41,11.59L12,16.17L16.59,11.59Z" />
|
||||
</vector>
|
@ -15,6 +15,10 @@
|
||||
|
||||
</data>
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<HorizontalScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
@ -23,6 +27,8 @@
|
||||
adapter="@{viewModel.itemsAdapter}"
|
||||
itemBinding="@{viewModel.itemBinding}"
|
||||
items="@{item.items}"
|
||||
scrollPosition="@={viewModel.scrollPosition}"
|
||||
scrollPositionSmooth="@{true}"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
@ -31,4 +37,17 @@
|
||||
|
||||
</HorizontalScrollView>
|
||||
|
||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
hide="@{viewModel.scrollPosition == item.items.size - 1}"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:layout_margin="@dimen/margin_generic"
|
||||
android:onClick="@{() -> viewModel.scrollDownPressed()}"
|
||||
app:srcCompat="@drawable/ic_arrow_down"
|
||||
app:tint="@color/colorTextInverse" />
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
|
||||
</layout>
|
Loading…
Reference in New Issue
Block a user