mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-25 21:47:37 +00:00
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 logItem get() = items[0] as LogRvItem
|
||||||
private val magiskLogItem get() = items[1] as MagiskLogRvItem
|
private val magiskLogItem get() = items[1] as MagiskLogRvItem
|
||||||
|
|
||||||
|
val scrollPosition = KObservableField(0)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
currentPage.addOnPropertyChangedCallback {
|
currentPage.addOnPropertyChangedCallback {
|
||||||
it ?: return@addOnPropertyChangedCallback
|
it ?: return@addOnPropertyChangedCallback
|
||||||
@ -59,6 +61,10 @@ class LogViewModel(
|
|||||||
else -> ""
|
else -> ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun scrollDownPressed() {
|
||||||
|
scrollPosition.value = magiskLogItem.items.size - 1
|
||||||
|
}
|
||||||
|
|
||||||
fun refresh() {
|
fun refresh() {
|
||||||
fetchLogs().subscribeK { logItem.update(it) }
|
fetchLogs().subscribeK { logItem.update(it) }
|
||||||
fetchMagiskLog().subscribeK { magiskLogItem.update(it) }
|
fetchMagiskLog().subscribeK { magiskLogItem.update(it) }
|
||||||
|
@ -11,8 +11,10 @@ import androidx.databinding.InverseBindingAdapter
|
|||||||
import androidx.databinding.InverseBindingListener
|
import androidx.databinding.InverseBindingListener
|
||||||
import androidx.drawerlayout.widget.DrawerLayout
|
import androidx.drawerlayout.widget.DrawerLayout
|
||||||
import androidx.interpolator.view.animation.FastOutSlowInInterpolator
|
import androidx.interpolator.view.animation.FastOutSlowInInterpolator
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import androidx.viewpager.widget.ViewPager
|
import androidx.viewpager.widget.ViewPager
|
||||||
|
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||||
import com.google.android.material.navigation.NavigationView
|
import com.google.android.material.navigation.NavigationView
|
||||||
import com.skoumal.teanity.extensions.subscribeK
|
import com.skoumal.teanity.extensions.subscribeK
|
||||||
import com.topjohnwu.magisk.R
|
import com.topjohnwu.magisk.R
|
||||||
@ -177,3 +179,31 @@ fun setScrollToLast(view: RecyclerView, shouldScrollToLast: Boolean) {
|
|||||||
view.adapter?.removeListener()
|
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,20 +15,39 @@
|
|||||||
|
|
||||||
</data>
|
</data>
|
||||||
|
|
||||||
<HorizontalScrollView
|
<FrameLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
<HorizontalScrollView
|
||||||
adapter="@{viewModel.itemsAdapter}"
|
android:layout_width="match_parent"
|
||||||
itemBinding="@{viewModel.itemBinding}"
|
android:layout_height="match_parent">
|
||||||
items="@{item.items}"
|
|
||||||
android:layout_width="wrap_content"
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
android:layout_height="match_parent"
|
adapter="@{viewModel.itemsAdapter}"
|
||||||
android:orientation="vertical"
|
itemBinding="@{viewModel.itemBinding}"
|
||||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
items="@{item.items}"
|
||||||
tools:listitem="@layout/item_console" />
|
scrollPosition="@={viewModel.scrollPosition}"
|
||||||
|
scrollPositionSmooth="@{true}"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical"
|
||||||
|
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
||||||
|
tools:listitem="@layout/item_console" />
|
||||||
|
|
||||||
|
</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>
|
||||||
|
|
||||||
</HorizontalScrollView>
|
|
||||||
|
|
||||||
</layout>
|
</layout>
|
Loading…
x
Reference in New Issue
Block a user