You've already forked Magisk
mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-09-06 06:36:58 +00:00
Updated policy (apps) layout to be more compact
Added pinch in to increase list span count / out to decrease The setting will be remembered across the whole app (every list that uses Staggered Grid) Updated indication of whether the policy has root access enabled permitted or not Displays crossed out app logo if not permitted
This commit is contained in:
@@ -448,4 +448,12 @@ fun View.setRotationNotAnimated(rotation: Int) {
|
||||
@BindingAdapter("android:text")
|
||||
fun TextView.setTextSafe(text: Int) {
|
||||
if (text == 0) this.text = null else setText(text)
|
||||
}
|
||||
|
||||
@BindingAdapter("android:onLongClick")
|
||||
fun View.setOnLongClickListenerBinding(listener: () -> Unit) {
|
||||
setOnLongClickListener {
|
||||
listener()
|
||||
true
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.topjohnwu.magisk.utils
|
||||
|
||||
import android.view.ScaleGestureDetector
|
||||
|
||||
abstract class PinchGestureCallback : ScaleGestureDetector.SimpleOnScaleGestureListener() {
|
||||
|
||||
private var startFactor: Float = 1f
|
||||
|
||||
override fun onScaleBegin(detector: ScaleGestureDetector?): Boolean {
|
||||
startFactor = detector?.scaleFactor ?: 1f
|
||||
return super.onScaleBegin(detector)
|
||||
}
|
||||
|
||||
override fun onScaleEnd(detector: ScaleGestureDetector?) {
|
||||
val endFactor = detector?.scaleFactor ?: 1f
|
||||
|
||||
if (endFactor > startFactor) onZoom()
|
||||
else if (endFactor < startFactor) onPinch()
|
||||
}
|
||||
|
||||
abstract fun onPinch()
|
||||
abstract fun onZoom()
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.topjohnwu.magisk.utils
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.view.MotionEvent
|
||||
import android.view.ScaleGestureDetector
|
||||
import android.view.View
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.recyclerview.widget.StaggeredGridLayoutManager
|
||||
import androidx.transition.TransitionManager
|
||||
import com.topjohnwu.magisk.Config
|
||||
import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
|
||||
class PinchZoomTouchListener private constructor(
|
||||
private val view: RecyclerView,
|
||||
private val max: Int = 3,
|
||||
private val min: Int = 1
|
||||
) : View.OnTouchListener {
|
||||
|
||||
private val layoutManager
|
||||
get() = view.layoutManager
|
||||
|
||||
private val pinchListener = object : PinchGestureCallback() {
|
||||
override fun onPinch() = updateSpanCount(Config.listSpanCount + 1)
|
||||
override fun onZoom() = updateSpanCount(Config.listSpanCount - 1)
|
||||
}
|
||||
|
||||
private val gestureDetector by lazy { ScaleGestureDetector(view.context, pinchListener) }
|
||||
|
||||
init {
|
||||
updateSpanCount(Config.listSpanCount, false)
|
||||
}
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
override fun onTouch(v: View?, event: MotionEvent?): Boolean {
|
||||
gestureDetector.onTouchEvent(event)
|
||||
return false
|
||||
}
|
||||
|
||||
private fun updateSpanCount(count: Int, animate: Boolean = true) {
|
||||
if (animate) {
|
||||
TransitionManager.beginDelayedTransition(view)
|
||||
}
|
||||
|
||||
val boundCount = max(min, min(max, count))
|
||||
|
||||
when (val l = layoutManager) {
|
||||
is StaggeredGridLayoutManager -> l.spanCount = boundCount
|
||||
is GridLayoutManager -> l.spanCount = boundCount
|
||||
else -> Unit
|
||||
}
|
||||
|
||||
Config.listSpanCount = boundCount
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
fun attachTo(view: RecyclerView) = view.setOnTouchListener(PinchZoomTouchListener(view))
|
||||
|
||||
fun clear(view: View) = view.setOnTouchListener(null)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user