mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-25 10:47:38 +00:00
Added new filter for hide section
Parts of which will be reused in modules down the line
This commit is contained in:
parent
54930024f5
commit
e1bda4ee8b
@ -1,5 +1,8 @@
|
||||
package com.topjohnwu.magisk.redesign.hide
|
||||
|
||||
import android.animation.Animator
|
||||
import android.animation.AnimatorSet
|
||||
import android.animation.ObjectAnimator
|
||||
import android.content.Context
|
||||
import android.graphics.Insets
|
||||
import android.os.Bundle
|
||||
@ -7,10 +10,20 @@ import android.view.Menu
|
||||
import android.view.MenuInflater
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import androidx.core.animation.addListener
|
||||
import androidx.core.view.isInvisible
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.core.view.marginBottom
|
||||
import androidx.core.view.marginEnd
|
||||
import androidx.interpolator.view.animation.FastOutSlowInInterpolator
|
||||
import com.google.android.material.circularreveal.CircularRevealCompat
|
||||
import com.google.android.material.circularreveal.CircularRevealWidget
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
import com.topjohnwu.magisk.R
|
||||
import com.topjohnwu.magisk.databinding.FragmentHideMd2Binding
|
||||
import com.topjohnwu.magisk.redesign.compat.CompatFragment
|
||||
import org.koin.androidx.viewmodel.ext.android.viewModel
|
||||
import kotlin.math.hypot
|
||||
|
||||
class HideFragment : CompatFragment<HideViewModel, FragmentHideMd2Binding>() {
|
||||
|
||||
@ -27,6 +40,14 @@ class HideFragment : CompatFragment<HideViewModel, FragmentHideMd2Binding>() {
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
binding.hideFilterToggle.setOnClickListener {
|
||||
MotionRevealHelper.withViews(binding.hideFilter, binding.hideFilterToggle, true)
|
||||
}
|
||||
binding.hideFilterInclude.hideFilterDone.setOnClickListener {
|
||||
MotionRevealHelper.withViews(binding.hideFilter, binding.hideFilterToggle, false)
|
||||
}
|
||||
|
||||
val lama = binding.hideContent.layoutManager ?: return
|
||||
lama.isAutoMeasureEnabled = false
|
||||
}
|
||||
@ -45,3 +66,70 @@ class HideFragment : CompatFragment<HideViewModel, FragmentHideMd2Binding>() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
object MotionRevealHelper {
|
||||
|
||||
fun <CV> withViews(
|
||||
revealable: CV,
|
||||
fab: FloatingActionButton,
|
||||
expanded: Boolean
|
||||
) where CV : CircularRevealWidget, CV : View {
|
||||
revealable.revealInfo = revealable.createRevealInfo(!expanded)
|
||||
|
||||
val revealInfo = revealable.createRevealInfo(expanded)
|
||||
val revealAnim = revealable.createRevealAnim(revealInfo)
|
||||
val moveAnim = fab.createMoveAnim(revealInfo)
|
||||
|
||||
AnimatorSet().also {
|
||||
if (expanded) {
|
||||
it.play(revealAnim).after(moveAnim)
|
||||
} else {
|
||||
it.play(moveAnim).after(revealAnim)
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
|
||||
private fun <CV> CV.createRevealAnim(
|
||||
revealInfo: CircularRevealWidget.RevealInfo
|
||||
): Animator where CV : CircularRevealWidget, CV : View =
|
||||
CircularRevealCompat.createCircularReveal(
|
||||
this,
|
||||
revealInfo.centerX,
|
||||
revealInfo.centerY,
|
||||
revealInfo.radius
|
||||
).apply {
|
||||
addListener(onStart = {
|
||||
isVisible = true
|
||||
}, onEnd = {
|
||||
if (revealInfo.radius == 0f) {
|
||||
isInvisible = true
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun FloatingActionButton.createMoveAnim(
|
||||
revealInfo: CircularRevealWidget.RevealInfo
|
||||
): Animator = AnimatorSet().also {
|
||||
it.interpolator = FastOutSlowInInterpolator()
|
||||
it.addListener(onStart = { show() }, onEnd = { if (revealInfo.radius != 0f) hide() })
|
||||
|
||||
val maxX = revealInfo.centerX - marginEnd - measuredWidth / 2f
|
||||
val targetX = if (revealInfo.radius == 0f) 0f else -maxX
|
||||
val moveX = ObjectAnimator.ofFloat(this, View.TRANSLATION_X, targetX)
|
||||
|
||||
val maxY = revealInfo.centerY - marginBottom - measuredHeight / 2f
|
||||
val targetY = if (revealInfo.radius == 0f) 0f else -maxY
|
||||
val moveY = ObjectAnimator.ofFloat(this, View.TRANSLATION_Y, targetY)
|
||||
|
||||
it.playTogether(moveX, moveY)
|
||||
}
|
||||
|
||||
private fun View.createRevealInfo(expanded: Boolean): CircularRevealWidget.RevealInfo {
|
||||
val cX = measuredWidth / 2f
|
||||
val cY = measuredHeight / 2f - paddingBottom
|
||||
return CircularRevealWidget.RevealInfo(cX, cY, if (expanded) hypot(cX, cY) else 0f)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -23,129 +23,48 @@
|
||||
invisibleUnless="@{viewModel.loaded || !viewModel.items.empty}"
|
||||
itemBinding="@{viewModel.itemBinding}"
|
||||
items="@{viewModel.items}"
|
||||
nestedScrollingEnabled="@{false}"
|
||||
android:layout_width="match_parent"
|
||||
android:paddingTop="@{viewModel.insets.top + (int) @dimen/internal_action_bar_size + (int) @dimen/l1}"
|
||||
android:paddingBottom="@{viewModel.insets.bottom}"
|
||||
android:layout_height="match_parent"
|
||||
android:clipToPadding="false"
|
||||
android:orientation="vertical"
|
||||
android:paddingStart="@dimen/l1"
|
||||
android:paddingTop="@{viewModel.insets.top + (int) @dimen/internal_action_bar_size + (int) @dimen/l1}"
|
||||
android:paddingEnd="@dimen/l1"
|
||||
android:paddingBottom="@{viewModel.insets.bottom}"
|
||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
||||
tools:listitem="@layout/item_hide_md2"
|
||||
tools:paddingTop="40dp" />
|
||||
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
style="?styleCardElevated"
|
||||
android:layout_width="match_parent"
|
||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/hide_filter_toggle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:layout_marginStart="@dimen/l1"
|
||||
android:layout_marginEnd="@dimen/l1"
|
||||
android:layout_marginBottom="@{viewModel.insets.bottom + (int) @dimen/l1}"
|
||||
app:cardCornerRadius="24dp">
|
||||
app:backgroundTint="?colorSurface"
|
||||
app:srcCompat="@drawable/ic_filter"
|
||||
app:tint="?colorPrimary"
|
||||
tools:layout_marginBottom="64dp" />
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
<com.google.android.material.circularreveal.cardview.CircularRevealCardView
|
||||
android:id="@+id/hide_filter"
|
||||
style="?styleCardVariant"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom"
|
||||
android:visibility="invisible"
|
||||
app:cardCornerRadius="0dp">
|
||||
|
||||
<include
|
||||
android:id="@+id/hide_filter_include"
|
||||
layout="@layout/include_hide_filter"
|
||||
viewModel="@{viewModel}"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
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>
|
||||
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
</com.google.android.material.circularreveal.cardview.CircularRevealCardView>
|
||||
|
||||
<LinearLayout
|
||||
goneUnless="@{viewModel.loading && viewModel.items.empty}"
|
||||
|
140
app/src/main/res/layout/include_hide_filter.xml
Normal file
140
app/src/main/res/layout/include_hide_filter.xml
Normal file
@ -0,0 +1,140 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<data>
|
||||
|
||||
<import type="com.topjohnwu.magisk.R" />
|
||||
|
||||
<variable
|
||||
name="viewModel"
|
||||
type="com.topjohnwu.magisk.redesign.hide.HideViewModel" />
|
||||
|
||||
</data>
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:clipToPadding="false"
|
||||
android:orientation="vertical"
|
||||
android:paddingStart="@dimen/l1"
|
||||
android:paddingTop="@dimen/l1"
|
||||
android:paddingEnd="@dimen/l1"
|
||||
android:paddingBottom="@{viewModel.insets.bottom + (int) @dimen/l1}"
|
||||
tools:layout_gravity="bottom"
|
||||
tools:paddingBottom="64dp">
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
android:id="@+id/hide_filter_title_filter"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/hide_filters"
|
||||
android:textAllCaps="true"
|
||||
android:textAppearance="?appearanceTextCaptionNormal"
|
||||
android:textColor="?colorPrimary"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<com.google.android.material.chip.ChipGroup
|
||||
android:id="@+id/hide_filter_chip_group"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/l1"
|
||||
app:chipSpacing="2dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/hide_filter_title_filter">
|
||||
|
||||
<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.appcompat.widget.AppCompatTextView
|
||||
android:id="@+id/hide_filter_title_search"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/l1"
|
||||
android:text="@string/hide_search"
|
||||
android:textAllCaps="true"
|
||||
android:textAppearance="?appearanceTextCaptionNormal"
|
||||
android:textColor="?colorPrimary"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintTop_toBottomOf="@+id/hide_filter_chip_group" />
|
||||
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
android:id="@+id/hide_filter_search"
|
||||
style="?styleCardNormal"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/l1"
|
||||
android:layout_marginEnd="@dimen/l1"
|
||||
android:layout_marginBottom="@dimen/l_50"
|
||||
app:cardCornerRadius="18dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@+id/hide_filter_done"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/hide_filter_title_search">
|
||||
|
||||
<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>
|
||||
|
||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/hide_filter_done"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:backgroundTint="?colorPrimary"
|
||||
app:elevation="0dp"
|
||||
app:fabSize="mini"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/hide_filter_search"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@+id/hide_filter_search"
|
||||
app:srcCompat="@drawable/ic_check_md2" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</layout>
|
@ -87,5 +87,7 @@
|
||||
|
||||
<string name="hide_filter_hint">Filter by name</string>
|
||||
<string name="hide_scroll_up">Scroll up</string>
|
||||
<string name="hide_filters">Filters</string>
|
||||
<string name="hide_search">Search</string>
|
||||
|
||||
</resources>
|
Loading…
x
Reference in New Issue
Block a user