Cleaned up unused resources

This commit is contained in:
Viktor De Pasquale 2020-02-11 19:12:30 +01:00 committed by John Wu
parent e9fc40d285
commit d7653e6e42
10 changed files with 1 additions and 434 deletions

View File

@ -1,45 +1,31 @@
package com.topjohnwu.magisk.utils package com.topjohnwu.magisk.utils
import android.animation.Animator
import android.animation.ValueAnimator import android.animation.ValueAnimator
import android.graphics.Paint import android.graphics.Paint
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.os.Build
import android.view.ContextThemeWrapper import android.view.ContextThemeWrapper
import android.view.View import android.view.View
import android.view.ViewAnimationUtils
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.PopupMenu import android.widget.PopupMenu
import android.widget.ProgressBar import android.widget.ProgressBar
import android.widget.TextView import android.widget.TextView
import androidx.annotation.ColorInt
import androidx.annotation.DrawableRes import androidx.annotation.DrawableRes
import androidx.appcompat.widget.AppCompatImageView import androidx.appcompat.widget.AppCompatImageView
import androidx.appcompat.widget.Toolbar import androidx.appcompat.widget.Toolbar
import androidx.core.animation.doOnEnd import androidx.core.view.updateLayoutParams
import androidx.core.view.*
import androidx.databinding.BindingAdapter import androidx.databinding.BindingAdapter
import androidx.databinding.InverseBindingAdapter
import androidx.databinding.InverseBindingListener
import androidx.drawerlayout.widget.DrawerLayout
import androidx.interpolator.view.animation.FastOutSlowInInterpolator import androidx.interpolator.view.animation.FastOutSlowInInterpolator
import androidx.recyclerview.widget.* import androidx.recyclerview.widget.*
import androidx.viewpager.widget.ViewPager
import com.google.android.material.button.MaterialButton import com.google.android.material.button.MaterialButton
import com.google.android.material.card.MaterialCardView import com.google.android.material.card.MaterialCardView
import com.google.android.material.chip.Chip import com.google.android.material.chip.Chip
import com.google.android.material.floatingactionbutton.FloatingActionButton
import com.google.android.material.navigation.NavigationView
import com.google.android.material.textfield.TextInputLayout import com.google.android.material.textfield.TextInputLayout
import com.topjohnwu.magisk.R import com.topjohnwu.magisk.R
import com.topjohnwu.magisk.extensions.drawableCompat
import com.topjohnwu.magisk.extensions.replaceRandomWithSpecial import com.topjohnwu.magisk.extensions.replaceRandomWithSpecial
import com.topjohnwu.magisk.extensions.subscribeK import com.topjohnwu.magisk.extensions.subscribeK
import com.topjohnwu.magisk.model.entity.state.IndeterminateState
import io.reactivex.Observable import io.reactivex.Observable
import io.reactivex.disposables.Disposable import io.reactivex.disposables.Disposable
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
import kotlin.math.hypot
import kotlin.math.roundToInt import kotlin.math.roundToInt
@ -48,77 +34,11 @@ fun setOnNavigationClickedListener(view: Toolbar, listener: View.OnClickListener
view.setNavigationOnClickListener(listener) view.setNavigationOnClickListener(listener)
} }
@BindingAdapter("onNavigationClick")
fun setOnNavigationClickedListener(
view: NavigationView,
listener: NavigationView.OnNavigationItemSelectedListener
) {
view.setNavigationItemSelectedListener {
(view.parent as? DrawerLayout)?.closeDrawers()
listener.onNavigationItemSelected(it)
}
}
@BindingAdapter("srcCompat") @BindingAdapter("srcCompat")
fun setImageResource(view: AppCompatImageView, @DrawableRes resId: Int) { fun setImageResource(view: AppCompatImageView, @DrawableRes resId: Int) {
view.setImageResource(resId) view.setImageResource(resId)
} }
@BindingAdapter("app:tint")
fun setTint(view: AppCompatImageView, @ColorInt tint: Int) {
view.setColorFilter(tint)
}
@BindingAdapter("isChecked")
fun setChecked(view: AppCompatImageView, isChecked: Boolean) {
val state = when (isChecked) {
true -> IndeterminateState.CHECKED
else -> IndeterminateState.UNCHECKED
}
setChecked(view, state)
}
@BindingAdapter("isChecked")
fun setChecked(view: AppCompatImageView, isChecked: IndeterminateState) {
view.setImageResource(
when (isChecked) {
IndeterminateState.INDETERMINATE -> R.drawable.ic_indeterminate
IndeterminateState.CHECKED -> R.drawable.ic_checked
IndeterminateState.UNCHECKED -> R.drawable.ic_unchecked
}
)
}
@BindingAdapter("position")
fun setPosition(view: ViewPager, position: Int) {
view.currentItem = position
}
@InverseBindingAdapter(attribute = "position", event = "positionChanged")
fun getPosition(view: ViewPager) = view.currentItem
@BindingAdapter("positionChanged")
fun setPositionChangedListener(view: ViewPager, listener: InverseBindingListener) {
view.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
override fun onPageSelected(position: Int) = listener.onChange()
override fun onPageScrollStateChanged(state: Int) = listener.onChange()
override fun onPageScrolled(
position: Int,
positionOffset: Float,
positionOffsetPixels: Int
) = listener.onChange()
})
}
@BindingAdapter("invisibleScale")
fun setInvisibleWithScale(view: View, isInvisible: Boolean) {
view.animate()
.scaleX(if (isInvisible) 0f else 1f)
.scaleY(if (isInvisible) 0f else 1f)
.setInterpolator(FastOutSlowInInterpolator())
.start()
}
@BindingAdapter("movieBehavior", "movieBehaviorText") @BindingAdapter("movieBehavior", "movieBehaviorText")
fun setMovieBehavior(view: TextView, isMovieBehavior: Boolean, text: String) { fun setMovieBehavior(view: TextView, isMovieBehavior: Boolean, text: String) {
(view.tag as? Disposable)?.dispose() (view.tag as? Disposable)?.dispose()
@ -134,30 +54,6 @@ fun setMovieBehavior(view: TextView, isMovieBehavior: Boolean, text: String) {
} }
} }
/*@BindingAdapter("selection"*//*, "selectionAttrChanged", "adapter"*//*)
fun setSelectedItemPosition(view: Spinner, position: Int) {
view.setSelection(position)
}
@InverseBindingAdapter(
attribute = "android:selectedItemPosition",
event = "android:selectedItemPositionAttrChanged"
)
fun getSelectedItemPosition(view: Spinner) = view.selectedItemPosition
@BindingAdapter("selectedItemPositionAttrChanged")
fun setSelectedItemPositionListener(view: Spinner, listener: InverseBindingListener) {
view.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onNothingSelected(p0: AdapterView<*>?) {
listener.onChange()
}
override fun onItemSelected(p0: AdapterView<*>?, p1: View?, p2: Int, p3: Long) {
listener.onChange()
}
}
}*/
@BindingAdapter("onTouch") @BindingAdapter("onTouch")
fun setOnTouchListener(view: View, listener: View.OnTouchListener) { fun setOnTouchListener(view: View, listener: View.OnTouchListener) {
view.setOnTouchListener(listener) view.setOnTouchListener(listener)
@ -199,42 +95,6 @@ fun setScrollToLast(view: RecyclerView, shouldScrollToLast: Boolean) {
} }
} }
@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) {
val adapterItemCount = view.adapter?.itemCount ?: -1
if (position !in 0 until adapterItemCount) {
// the position is not in adapter bounds, adapter will throw exception for invalid positions
return
}
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
@BindingAdapter("isEnabled") @BindingAdapter("isEnabled")
fun setEnabled(view: View, isEnabled: Boolean) { fun setEnabled(view: View, isEnabled: Boolean) {
view.isEnabled = isEnabled view.isEnabled = isEnabled
@ -249,42 +109,6 @@ fun TextInputLayout.setErrorString(error: String) {
// md2 // md2
@BindingAdapter("onSelectClick", "onSelectReset", requireAll = false)
fun View.setOnSelectClickListener(listener: View.OnClickListener, resetTime: Long) {
fun getHideTarget() = (parent as? ViewGroup)?.findViewWithTag<View>(R.id.hideWhenSelected)
fun animateVisibility(hide: Boolean, target: View? = getHideTarget()) {
target ?: return
val targetScale = if (hide) 0f else 1f
target.animate()
.scaleY(targetScale)
.scaleX(targetScale)
.start()
}
setOnClickListener {
when {
it.isSelected -> {
animateVisibility(false)
listener.onClick(it)
(it.tag as? Runnable)?.let { task ->
it.handler.removeCallbacks(task)
}
it.isSelected = false
}
else -> {
animateVisibility(true)
it.isSelected = true
it.tag = it.postDelayed(resetTime) {
animateVisibility(false)
it.tag = null
it.isSelected = false
}
}
}
}
}
@BindingAdapter( @BindingAdapter(
"android:layout_marginLeft", "android:layout_marginLeft",
"android:layout_marginTop", "android:layout_marginTop",
@ -320,55 +144,6 @@ fun View.isSelected(isSelected: Boolean) {
this.isSelected = isSelected this.isSelected = isSelected
} }
@BindingAdapter("reveal")
fun View.setRevealed(reveal: Boolean) {
val x = measuredWidth
val y = measuredHeight
val maxRadius = hypot(x.toDouble(), y.toDouble()).toFloat()
val start = if (reveal) 0f else maxRadius
val end = if (reveal) maxRadius else 0f
val anim = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
isInvisible = reveal
return
} else {
ViewAnimationUtils.createCircularReveal(this, x, 0, start, end).apply {
interpolator = FastOutSlowInInterpolator()
setTag(R.id.revealAnim, this)
doOnEnd { setTag(R.id.revealAnim, null) }
}
}
post {
isVisible = true
anim.start()
}
}
@BindingAdapter("revealFix")
fun View.setFixReveal(isRevealed: Boolean) {
(getTag(R.id.revealAnim) as? Animator)
?.doOnEnd { isInvisible = !isRevealed }
?.let { return }
isInvisible = !isRevealed
}
@BindingAdapter("dividerVertical", "dividerHorizontal", requireAll = false)
fun RecyclerView.setDividers(dividerVertical: Int, dividerHorizontal: Int) {
val horizontal = if (dividerHorizontal > 0) {
context.drawableCompat(dividerHorizontal)
} else {
null
}
val vertical = if (dividerVertical > 0) {
context.drawableCompat(dividerVertical)
} else {
null
}
setDividers(vertical, horizontal)
}
@BindingAdapter("dividerVertical", "dividerHorizontal", requireAll = false) @BindingAdapter("dividerVertical", "dividerHorizontal", requireAll = false)
fun RecyclerView.setDividers(dividerVertical: Drawable?, dividerHorizontal: Drawable?) { fun RecyclerView.setDividers(dividerVertical: Drawable?, dividerHorizontal: Drawable?) {
if (dividerHorizontal != null) { if (dividerHorizontal != null) {
@ -383,24 +158,11 @@ fun RecyclerView.setDividers(dividerVertical: Drawable?, dividerHorizontal: Draw
} }
} }
@BindingAdapter("rotationAnimated")
fun View.rotationTo(value: Int) {
animate()
.rotation(value.toFloat())
.setInterpolator(FastOutSlowInInterpolator())
.start()
}
@BindingAdapter("app:icon") @BindingAdapter("app:icon")
fun MaterialButton.setIconRes(res: Int) { fun MaterialButton.setIconRes(res: Int) {
setIconResource(res) setIconResource(res)
} }
@BindingAdapter("cardElevation")
fun MaterialCardView.setCardElevationBound(elevation: Float) {
cardElevation = elevation
}
@BindingAdapter("strokeWidth") @BindingAdapter("strokeWidth")
fun MaterialCardView.setCardStrokeWidthBound(stroke: Float) { fun MaterialCardView.setCardStrokeWidthBound(stroke: Float) {
strokeWidth = stroke.roundToInt() strokeWidth = stroke.roundToInt()
@ -411,11 +173,6 @@ fun Toolbar.setOnMenuClickListener(listener: Toolbar.OnMenuItemClickListener) {
setOnMenuItemClickListener(listener) setOnMenuItemClickListener(listener)
} }
@BindingAdapter("tooltipText")
fun View.setTooltipTextCompat(text: String) {
ViewCompat.setTooltipText(this, text)
}
@BindingAdapter("onCloseClicked") @BindingAdapter("onCloseClicked")
fun Chip.setOnCloseClickedListenerBinding(listener: View.OnClickListener) { fun Chip.setOnCloseClickedListenerBinding(listener: View.OnClickListener) {
setOnCloseIconClickListener(listener) setOnCloseIconClickListener(listener)
@ -433,13 +190,6 @@ fun ProgressBar.setProgressAnimated(newProgress: Int) {
}.start() }.start()
} }
@BindingAdapter("android:rotation")
fun View.setRotationNotAnimated(rotation: Int) {
if (animation != null) {
this.rotation = rotation.toFloat()
}
}
@BindingAdapter("android:text") @BindingAdapter("android:text")
fun TextView.setTextSafe(text: Int) { fun TextView.setTextSafe(text: Int) {
if (text == 0) this.text = null else setText(text) if (text == 0) this.text = null else setText(text)

View File

@ -1,11 +0,0 @@
<?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="M20,12A8,8 0 0,1 12,20A8,8 0 0,1 4,12A8,8 0 0,1 12,4C12.76,4 13.5,4.11 14.2,4.31L15.77,2.74C14.61,2.26 13.34,2 12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12M7.91,10.08L6.5,11.5L11,16L21,6L19.59,4.58L11,13.17L7.91,10.08Z" />
</vector>

View File

@ -1,10 +0,0 @@
<?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="M12,20C7.59,20 4,16.41 4,12C4,7.59 7.59,4 12,4C16.41,4 20,7.59 20,12C20,16.41 16.41,20 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2M7,13H17V11H7" />
</vector>

View File

@ -1,10 +0,0 @@
<?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="M12,20A8,8 0 0,1 4,12A8,8 0 0,1 12,4A8,8 0 0,1 20,12A8,8 0 0,1 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2Z" />
</vector>

View File

@ -1,35 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<!--new colors-->
<color name="colorPrimary">#009688</color>
<color name="colorPrimaryDark">#00796B</color>
<color name="colorSecondary">#D50000</color>
<color name="colorSecondaryDark">#6D1111</color>
<color name="colorText">#1D1D1D</color>
<color name="colorTextInactive">#6a6868</color>
<color name="colorTextInverse">#fff</color>
<color name="colorTextTinted">#FFFFFF</color>
<color name="colorCardStrokeInverse">#2A000000</color>
<color name="colorCorrect">@color/green500</color>
<color name="colorError">@color/red500</color>
<color name="colorUpdate">@color/blue500</color>
<!--new colors ^^-->
<color name="primary">#009688</color>
<color name="primary_dark">#00796B</color>
<color name="accentFallback">#FBC02D</color>
<color name="icon_grey">#757575</color>
<color name="red500">#F44336</color>
<color name="green500">#4CAF50</color>
<color name="blue500">#2196f3</color>
<color name="dark_secondary_text">#dedede</color>
<color name="su_request_background">#e0e0e0</color> <color name="su_request_background">#e0e0e0</color>
<!-- Card colors --> <!-- Card colors -->

View File

@ -1,8 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<item name="hideWhenSelected" type="id" />
<item name="recyclerScrollListener" type="id" /> <item name="recyclerScrollListener" type="id" />
<item name="revealAnim" type="id" />
</resources> </resources>

View File

@ -1,30 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="TextAppearance" parent="TextAppearance.AppCompat.Body1">
<item name="android:textColor">@color/colorText</item>
</style>
<style name="TextAppearance.Emphasize" parent="TextAppearance.AppCompat.Body1">
<item name="android:textColor">@color/colorText</item>
<item name="android:textSize">16sp</item>
<item name="android:textStyle">bold</item>
</style>
<style name="TextAppearance.Emphasize.Tinted">
<item name="android:textColor">@color/colorTextTinted</item>
</style>
<style name="TextAppearance.Title" parent="TextAppearance.AppCompat.Title">
<item name="android:textColor">@color/colorText</item>
</style>
<style name="TextAppearance.Caption" parent="TextAppearance.AppCompat.Caption">
<item name="android:textColor">@color/colorText</item>
</style>
<style name="TextAppearance.Caption.Inactive">
<item name="android:textColor">@color/colorTextInactive</item>
</style>
</resources>

View File

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Widget.Button.Text" parent="Widget.MaterialComponents.Button.TextButton">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textColor">@color/colorSecondary</item>
<item name="rippleColor">@color/colorSecondary</item>
</style>
</resources>

View File

@ -1,27 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Widget.Icon">
<item name="android:layout_width">36dp</item>
<item name="android:layout_height">36dp</item>
<item name="android:padding">6dp</item>
<item name="android:background">?attr/selectableItemBackgroundBorderless</item>
</style>
<style name="Widget.Icon.Large">
<item name="android:layout_width">48dp</item>
<item name="android:layout_height">48dp</item>
<item name="android:padding">6dp</item>
<item name="android:background">?attr/selectableItemBackgroundBorderless</item>
</style>
<style name="Widget.Icon.Accent">
<item name="tint">@color/colorSecondary</item>
</style>
<style name="Widget.Icon.DialogButton" parent="Widget.Icon.Accent">
<item name="android:layout_gravity">center</item>
<item name="android:background">@android:color/transparent</item>
</style>
</resources>

View File

@ -1,52 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Widget.BaseText">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
</style>
<style name="Widget.Text" parent="Widget.BaseText">
<item name="android:textAppearance">@style/TextAppearance</item>
<item name="android:ellipsize">end</item>
</style>
<style name="Widget.Text.Emphasize">
<item name="android:textAppearance">@style/TextAppearance.Emphasize</item>
</style>
<style name="Widget.Text.Emphasize.Tinted">
<item name="android:textAppearance">@style/TextAppearance.Emphasize.Tinted</item>
</style>
<style name="Widget.Text.Title">
<item name="android:textAppearance">@style/TextAppearance.Title</item>
</style>
<style name="Widget.Text.Caption">
<item name="android:textAppearance">@style/TextAppearance.Caption</item>
</style>
<style name="Widget.Text.Caption.Inactive">
<item name="android:textAppearance">@style/TextAppearance.Caption.Inactive</item>
</style>
<style name="Widget.Text.SectionTitle">
<item name="android:textStyle">bold</item>
<item name="android:paddingTop">@dimen/margin_generic_double</item>
<item name="android:paddingBottom">@dimen/margin_generic</item>
<item name="android:paddingLeft">@dimen/margin_generic</item>
<item name="android:paddingRight">@dimen/margin_generic</item>
<item name="android:textAppearance">@style/TextAppearance.Caption</item>
<item name="android:textColor">@color/colorSecondary</item>
</style>
<style name="Widget.Text.DialogButton">
<item name="android:padding">@dimen/margin_generic</item>
<item name="android:textColor">@color/colorSecondary</item>
<item name="android:textStyle">bold</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
</style>
</resources>