Fixed slow scrolling and list updates on hide screen

This commit is contained in:
Viktor De Pasquale 2019-11-12 17:23:27 +01:00
parent b2b81a5d0f
commit c5f2f63458
4 changed files with 126 additions and 133 deletions

View File

@ -2,6 +2,7 @@ package com.topjohnwu.magisk.redesign.hide
import android.content.Context import android.content.Context
import android.graphics.Insets import android.graphics.Insets
import android.os.Bundle
import android.view.Menu import android.view.Menu
import android.view.MenuInflater import android.view.MenuInflater
import android.view.MenuItem import android.view.MenuItem
@ -24,13 +25,21 @@ class HideFragment : CompatFragment<HideViewModel, FragmentHideMd2Binding>() {
setHasOptionsMenu(true) setHasOptionsMenu(true)
} }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val lama = binding.hideContent.layoutManager ?: return
lama.isAutoMeasureEnabled = false
}
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
inflater.inflate(R.menu.menu_hide_md2, menu) inflater.inflate(R.menu.menu_hide_md2, menu)
} }
override fun onOptionsItemSelected(item: MenuItem): Boolean { override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) { when (item.itemId) {
R.id.action_focus_up -> binding.hideScrollContainer.fullScroll(View.FOCUS_UP) R.id.action_focus_up -> binding.hideContent
.also { it.scrollToPosition(10) }
.also { it.smoothScrollToPosition(0) }
} }
return super.onOptionsItemSelected(item) return super.onOptionsItemSelected(item)
} }

View File

@ -3,7 +3,6 @@ package com.topjohnwu.magisk.redesign.module
import android.graphics.Insets import android.graphics.Insets
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import androidx.recyclerview.widget.StaggeredGridLayoutManager
import com.topjohnwu.magisk.R import com.topjohnwu.magisk.R
import com.topjohnwu.magisk.databinding.FragmentModuleMd2Binding import com.topjohnwu.magisk.databinding.FragmentModuleMd2Binding
import com.topjohnwu.magisk.redesign.compat.CompatFragment import com.topjohnwu.magisk.redesign.compat.CompatFragment
@ -37,7 +36,7 @@ class ModuleFragment : CompatFragment<ModuleViewModel, FragmentModuleMd2Binding>
} }
private fun setEndlessScroller() { private fun setEndlessScroller() {
val lama = binding.moduleRemote.layoutManager as? StaggeredGridLayoutManager ?: return val lama = binding.moduleRemote.layoutManager ?: return
lama.isAutoMeasureEnabled = false lama.isAutoMeasureEnabled = false
listener = EndlessRecyclerScrollListener(lama, viewModel::loadRemote) listener = EndlessRecyclerScrollListener(lama, viewModel::loadRemote)

View File

@ -17,28 +17,33 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<androidx.core.widget.NestedScrollView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/hide_scroll_container" android:id="@+id/hide_content"
onScrollStateChanged="@{() -> viewModel.hideFilter()}" dividerVertical="@{R.drawable.divider_l1}"
invisibleUnless="@{viewModel.loaded || !viewModel.items.empty}"
itemBinding="@{viewModel.itemBinding}"
items="@{viewModel.items}"
nestedScrollingEnabled="@{false}"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:fillViewport="true"
android:paddingTop="@{viewModel.insets.top + (int) @dimen/internal_action_bar_size + (int) @dimen/l1}" android:paddingTop="@{viewModel.insets.top + (int) @dimen/internal_action_bar_size + (int) @dimen/l1}"
android:paddingBottom="@{viewModel.insets.bottom}" android:paddingBottom="@{viewModel.insets.bottom}"
tools:paddingTop="40dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"> android:clipToPadding="false"
android:orientation="vertical"
android:paddingStart="@dimen/l1"
android:paddingEnd="@dimen/l1"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/item_hide_md2"
tools:paddingTop="40dp" />
<com.google.android.material.card.MaterialCardView <com.google.android.material.card.MaterialCardView
style="?styleCardVariant" style="?styleCardElevated"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginStart="@dimen/l1" android:layout_marginStart="@dimen/l1"
android:layout_marginEnd="@dimen/l1" android:layout_marginEnd="@dimen/l1"
android:layout_marginBottom="@{viewModel.insets.bottom + (int) @dimen/l1}"
app:cardCornerRadius="24dp"> app:cardCornerRadius="24dp">
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
@ -142,26 +147,6 @@
</com.google.android.material.card.MaterialCardView> </com.google.android.material.card.MaterialCardView>
<androidx.recyclerview.widget.RecyclerView
dividerVertical="@{R.drawable.divider_l1}"
invisibleUnless="@{viewModel.loaded || !viewModel.items.empty}"
itemBinding="@{viewModel.itemBinding}"
items="@{viewModel.items}"
nestedScrollingEnabled="@{false}"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="@dimen/l1"
android:clipToPadding="false"
android:orientation="vertical"
android:paddingStart="@dimen/l1"
android:paddingEnd="@dimen/l1"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/item_hide_md2" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
<LinearLayout <LinearLayout
goneUnless="@{viewModel.loading &amp;&amp; viewModel.items.empty}" goneUnless="@{viewModel.loading &amp;&amp; viewModel.items.empty}"
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@ -125,7 +125,7 @@
style="?styleProgressDeterminate" style="?styleProgressDeterminate"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_gravity="top" android:layout_gravity="top"
progressAnimated="@{item.itemsCheckedPercent}" /> android:progress="@{item.itemsCheckedPercent}" />
</com.google.android.material.card.MaterialCardView> </com.google.android.material.card.MaterialCardView>