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.graphics.Insets
import android.os.Bundle
import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
@ -24,13 +25,21 @@ class HideFragment : CompatFragment<HideViewModel, FragmentHideMd2Binding>() {
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) {
inflater.inflate(R.menu.menu_hide_md2, menu)
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
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)
}

View File

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

View File

@ -17,150 +17,135 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.core.widget.NestedScrollView
android:id="@+id/hide_scroll_container"
onScrollStateChanged="@{() -> viewModel.hideFilter()}"
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/hide_content"
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:clipToPadding="false"
android:fillViewport="true"
android:paddingTop="@{viewModel.insets.top + (int) @dimen/internal_action_bar_size + (int) @dimen/l1}"
android:paddingBottom="@{viewModel.insets.bottom}"
tools:paddingTop="40dp">
android:layout_height="match_parent"
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" />
<LinearLayout
<com.google.android.material.card.MaterialCardView
style="?styleCardElevated"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginStart="@dimen/l1"
android:layout_marginEnd="@dimen/l1"
android:layout_marginBottom="@{viewModel.insets.bottom + (int) @dimen/l1}"
app:cardCornerRadius="24dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:layout_height="wrap_content">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/hide_filter_icon"
style="?styleIconNormal"
android:onClick="@{() -> viewModel.toggle(viewModel.isFilterExpanded)}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_filter" />
<com.google.android.material.chip.ChipGroup
android:id="@+id/hide_filter_chip_group"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:paddingStart="@dimen/l_50"
android:paddingEnd="0dp"
app:chipSpacing="2dp"
app:layout_constraintBottom_toBottomOf="@+id/hide_filter_barrier"
app:layout_constraintEnd_toStartOf="@+id/hide_filter_icon"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.chip.Chip
style="@style/Widget.MaterialComponents.Chip.Filter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="@={viewModel.showSystem}"
android:text="@string/show_system_app"
android:textAppearance="?appearanceTextCaptionNormal"
app:checkedIcon="@drawable/ic_check_md2"
app:chipBackgroundColor="?colorSurfaceVariant"
tools:checked="true" />
<com.google.android.material.chip.Chip
style="@style/Widget.MaterialComponents.Chip.Entry"
gone="@{viewModel.query.empty}"
onCloseClicked="@{() -> viewModel.resetQuery()}"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checkable="false"
android:text="@{viewModel.query}"
android:textAppearance="?appearanceTextCaptionNormal"
app:chipBackgroundColor="?colorSurfaceVariant" />
</com.google.android.material.chip.ChipGroup>
<androidx.constraintlayout.widget.Barrier
android:id="@+id/hide_filter_barrier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="bottom"
app:constraint_referenced_ids="hide_filter_icon,hide_filter_chip_group" />
<com.google.android.material.card.MaterialCardView
style="?styleCardVariant"
android:id="@+id/hide_filter_search"
style="?styleCardNormal"
goneUnless="@{viewModel.isFilterExpanded}"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/l1"
android:layout_marginEnd="@dimen/l1"
app:cardCornerRadius="24dp">
android:layout_marginStart="@dimen/l_50"
android:layout_marginEnd="@dimen/l_50"
android:layout_marginBottom="@dimen/l_50"
android:visibility="gone"
app:cardCornerRadius="18dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/hide_filter_barrier"
tools:visibility="visible">
<androidx.constraintlayout.widget.ConstraintLayout
<androidx.appcompat.widget.AppCompatImageView
style="?styleIconNormal"
android:layout_width="48dp"
android:layout_height="36dp"
android:layout_gravity="center_vertical|start"
android:padding="6dp"
app:srcCompat="@drawable/ic_search_md2"
app:tint="?colorDisabled" />
<androidx.appcompat.widget.AppCompatEditText
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/hide_filter_icon"
style="?styleIconNormal"
android:onClick="@{() -> viewModel.toggle(viewModel.isFilterExpanded)}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_filter" />
<com.google.android.material.chip.ChipGroup
android:id="@+id/hide_filter_chip_group"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:paddingStart="@dimen/l_50"
android:paddingEnd="0dp"
app:chipSpacing="2dp"
app:layout_constraintBottom_toBottomOf="@+id/hide_filter_barrier"
app:layout_constraintEnd_toStartOf="@+id/hide_filter_icon"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.chip.Chip
style="@style/Widget.MaterialComponents.Chip.Filter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="@={viewModel.showSystem}"
android:text="@string/show_system_app"
android:textAppearance="?appearanceTextCaptionNormal"
app:checkedIcon="@drawable/ic_check_md2"
app:chipBackgroundColor="?colorSurfaceVariant"
tools:checked="true" />
<com.google.android.material.chip.Chip
style="@style/Widget.MaterialComponents.Chip.Entry"
gone="@{viewModel.query.empty}"
onCloseClicked="@{() -> viewModel.resetQuery()}"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checkable="false"
android:text="@{viewModel.query}"
android:textAppearance="?appearanceTextCaptionNormal"
app:chipBackgroundColor="?colorSurfaceVariant" />
</com.google.android.material.chip.ChipGroup>
<androidx.constraintlayout.widget.Barrier
android:id="@+id/hide_filter_barrier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="bottom"
app:constraint_referenced_ids="hide_filter_icon,hide_filter_chip_group" />
<com.google.android.material.card.MaterialCardView
android:id="@+id/hide_filter_search"
style="?styleCardNormal"
goneUnless="@{viewModel.isFilterExpanded}"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/l_50"
android:layout_marginEnd="@dimen/l_50"
android:layout_marginBottom="@dimen/l_50"
android:visibility="gone"
app:cardCornerRadius="18dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/hide_filter_barrier"
tools:visibility="visible">
<androidx.appcompat.widget.AppCompatImageView
style="?styleIconNormal"
android:layout_width="48dp"
android:layout_height="36dp"
android:layout_gravity="center_vertical|start"
android:padding="6dp"
app:srcCompat="@drawable/ic_search_md2"
app:tint="?colorDisabled" />
<androidx.appcompat.widget.AppCompatEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="48dp"
android:background="@null"
android:hint="@string/hide_filter_hint"
android:inputType="textUri"
android:minHeight="36dp"
android:paddingStart="0dp"
android:paddingEnd="@dimen/l1"
android:singleLine="true"
android:text="@={viewModel.query}"
android:textAppearance="?appearanceTextBodyNormal"
android:textColor="?colorTextTransient"
android:textColorHint="?colorOnSurfaceVariant" />
</com.google.android.material.card.MaterialCardView>
</androidx.constraintlayout.widget.ConstraintLayout>
android:layout_height="wrap_content"
android:layout_marginStart="48dp"
android:background="@null"
android:hint="@string/hide_filter_hint"
android:inputType="textUri"
android:minHeight="36dp"
android:paddingStart="0dp"
android:paddingEnd="@dimen/l1"
android:singleLine="true"
android:text="@={viewModel.query}"
android:textAppearance="?appearanceTextBodyNormal"
android:textColor="?colorTextTransient"
android:textColorHint="?colorOnSurfaceVariant" />
</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" />
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</com.google.android.material.card.MaterialCardView>
<LinearLayout
goneUnless="@{viewModel.loading &amp;&amp; viewModel.items.empty}"

View File

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