diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/DataBindingAdapters.kt b/app/src/main/java/com/topjohnwu/magisk/utils/DataBindingAdapters.kt index cea33543c..34ecc9969 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/DataBindingAdapters.kt +++ b/app/src/main/java/com/topjohnwu/magisk/utils/DataBindingAdapters.kt @@ -1,45 +1,31 @@ package com.topjohnwu.magisk.utils -import android.animation.Animator import android.animation.ValueAnimator import android.graphics.Paint import android.graphics.drawable.Drawable -import android.os.Build import android.view.ContextThemeWrapper import android.view.View -import android.view.ViewAnimationUtils import android.view.ViewGroup import android.widget.PopupMenu import android.widget.ProgressBar import android.widget.TextView -import androidx.annotation.ColorInt import androidx.annotation.DrawableRes import androidx.appcompat.widget.AppCompatImageView import androidx.appcompat.widget.Toolbar -import androidx.core.animation.doOnEnd -import androidx.core.view.* +import androidx.core.view.updateLayoutParams 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.recyclerview.widget.* -import androidx.viewpager.widget.ViewPager import com.google.android.material.button.MaterialButton import com.google.android.material.card.MaterialCardView 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.topjohnwu.magisk.R -import com.topjohnwu.magisk.extensions.drawableCompat import com.topjohnwu.magisk.extensions.replaceRandomWithSpecial import com.topjohnwu.magisk.extensions.subscribeK -import com.topjohnwu.magisk.model.entity.state.IndeterminateState import io.reactivex.Observable import io.reactivex.disposables.Disposable import java.util.concurrent.TimeUnit -import kotlin.math.hypot import kotlin.math.roundToInt @@ -48,77 +34,11 @@ fun setOnNavigationClickedListener(view: Toolbar, listener: View.OnClickListener view.setNavigationOnClickListener(listener) } -@BindingAdapter("onNavigationClick") -fun setOnNavigationClickedListener( - view: NavigationView, - listener: NavigationView.OnNavigationItemSelectedListener -) { - view.setNavigationItemSelectedListener { - (view.parent as? DrawerLayout)?.closeDrawers() - listener.onNavigationItemSelected(it) - } -} - @BindingAdapter("srcCompat") fun setImageResource(view: AppCompatImageView, @DrawableRes resId: Int) { 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") fun setMovieBehavior(view: TextView, isMovieBehavior: Boolean, text: String) { (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") fun setOnTouchListener(view: View, listener: View.OnTouchListener) { 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") fun setEnabled(view: View, isEnabled: Boolean) { view.isEnabled = isEnabled @@ -249,42 +109,6 @@ fun TextInputLayout.setErrorString(error: String) { // md2 -@BindingAdapter("onSelectClick", "onSelectReset", requireAll = false) -fun View.setOnSelectClickListener(listener: View.OnClickListener, resetTime: Long) { - - fun getHideTarget() = (parent as? ViewGroup)?.findViewWithTag(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( "android:layout_marginLeft", "android:layout_marginTop", @@ -320,55 +144,6 @@ fun View.isSelected(isSelected: Boolean) { 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) fun RecyclerView.setDividers(dividerVertical: Drawable?, dividerHorizontal: Drawable?) { 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") fun MaterialButton.setIconRes(res: Int) { setIconResource(res) } -@BindingAdapter("cardElevation") -fun MaterialCardView.setCardElevationBound(elevation: Float) { - cardElevation = elevation -} - @BindingAdapter("strokeWidth") fun MaterialCardView.setCardStrokeWidthBound(stroke: Float) { strokeWidth = stroke.roundToInt() @@ -411,11 +173,6 @@ fun Toolbar.setOnMenuClickListener(listener: Toolbar.OnMenuItemClickListener) { setOnMenuItemClickListener(listener) } -@BindingAdapter("tooltipText") -fun View.setTooltipTextCompat(text: String) { - ViewCompat.setTooltipText(this, text) -} - @BindingAdapter("onCloseClicked") fun Chip.setOnCloseClickedListenerBinding(listener: View.OnClickListener) { setOnCloseIconClickListener(listener) @@ -433,13 +190,6 @@ fun ProgressBar.setProgressAnimated(newProgress: Int) { }.start() } -@BindingAdapter("android:rotation") -fun View.setRotationNotAnimated(rotation: Int) { - if (animation != null) { - this.rotation = rotation.toFloat() - } -} - @BindingAdapter("android:text") fun TextView.setTextSafe(text: Int) { if (text == 0) this.text = null else setText(text) diff --git a/app/src/main/res/drawable/ic_checked.xml b/app/src/main/res/drawable/ic_checked.xml deleted file mode 100644 index 696760bdb..000000000 --- a/app/src/main/res/drawable/ic_checked.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_indeterminate.xml b/app/src/main/res/drawable/ic_indeterminate.xml deleted file mode 100644 index 0d821b586..000000000 --- a/app/src/main/res/drawable/ic_indeterminate.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_unchecked.xml b/app/src/main/res/drawable/ic_unchecked.xml deleted file mode 100644 index e90297236..000000000 --- a/app/src/main/res/drawable/ic_unchecked.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 8b7a31746..c40ea25df 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -1,35 +1,5 @@ - - - - #009688 - #00796B - #D50000 - #6D1111 - - #1D1D1D - #6a6868 - #fff - - #FFFFFF - #2A000000 - - @color/green500 - @color/red500 - @color/blue500 - - - #009688 - #00796B - #FBC02D - #757575 - - #F44336 - #4CAF50 - #2196f3 - - #dedede #e0e0e0 diff --git a/app/src/main/res/values/ids.xml b/app/src/main/res/values/ids.xml index 17fff2f0d..77b8f273e 100644 --- a/app/src/main/res/values/ids.xml +++ b/app/src/main/res/values/ids.xml @@ -1,8 +1,6 @@ - - \ No newline at end of file diff --git a/app/src/main/res/values/view_appearances.xml b/app/src/main/res/values/view_appearances.xml deleted file mode 100644 index d7e2850f6..000000000 --- a/app/src/main/res/values/view_appearances.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/values/view_button_styles.xml b/app/src/main/res/values/view_button_styles.xml deleted file mode 100644 index 5d2e2279f..000000000 --- a/app/src/main/res/values/view_button_styles.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/app/src/main/res/values/view_image_styles.xml b/app/src/main/res/values/view_image_styles.xml deleted file mode 100644 index 83651a21c..000000000 --- a/app/src/main/res/values/view_image_styles.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/values/view_text_styles.xml b/app/src/main/res/values/view_text_styles.xml deleted file mode 100644 index 823f3a29e..000000000 --- a/app/src/main/res/values/view_text_styles.xml +++ /dev/null @@ -1,52 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file