diff --git a/.idea/AndroidProjectSystem.xml b/.idea/AndroidProjectSystem.xml new file mode 100644 index 0000000000..4a53bee8cb --- /dev/null +++ b/.idea/AndroidProjectSystem.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/artifacts/library_jvm_1_0_0.xml b/.idea/artifacts/library_jvm_1_0_0.xml new file mode 100644 index 0000000000..aa29393f4b --- /dev/null +++ b/.idea/artifacts/library_jvm_1_0_0.xml @@ -0,0 +1,8 @@ + + + $PROJECT_DIR$/library/build/libs + + + + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml index b589d56e9f..b86273d942 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/.idea/deploymentTargetSelector.xml b/.idea/deploymentTargetSelector.xml new file mode 100644 index 0000000000..fe3f085ffb --- /dev/null +++ b/.idea/deploymentTargetSelector.xml @@ -0,0 +1,18 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml index d06216153d..4a0157633d 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -15,7 +15,6 @@ - diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml new file mode 100644 index 0000000000..c22b6fa9ee --- /dev/null +++ b/.idea/kotlinc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000000..16660f1d80 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,17 @@ + + + + + + \ No newline at end of file diff --git a/.kotlin/sessions/kotlin-compiler-2935608288755244211.salive b/.kotlin/sessions/kotlin-compiler-2935608288755244211.salive new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app/src/main/java/com/lagradost/cloudstream3/widget/ZoomLayout.kt b/app/src/main/java/com/lagradost/cloudstream3/widget/ZoomLayout.kt new file mode 100644 index 0000000000..45e07cdbd6 --- /dev/null +++ b/app/src/main/java/com/lagradost/cloudstream3/widget/ZoomLayout.kt @@ -0,0 +1,97 @@ +package com.lagradost.cloudstream3.widget + +import android.content.Context +import android.graphics.Canvas +import android.util.AttributeSet +import android.view.MotionEvent +import android.view.ScaleGestureDetector +import android.widget.FrameLayout +import android.animation.ValueAnimator +import androidx.interpolator.view.animation.FastOutSlowInInterpolator + +/** + *This is a container that lets the user pinch to zoom its entire contents + */ +class ZoomLayout @JvmOverloads constructor( //Why not + context: Context, + attrs: AttributeSet? = null +) : FrameLayout(context, attrs), ScaleGestureDetector.OnScaleGestureListener { + + private var scaleFactor = 1f //current scale factor + + //pivot points + private var focusX = 0f + private var focusY = 0f + + //the gesture detector + private val detector = ScaleGestureDetector(context, this) + + //animator that resets scaleFactor/focus back to defaults + private val resetAnimator = ValueAnimator.ofFloat(0f,1f).apply { + interpolator = FastOutSlowInInterpolator() + duration = 300L + addUpdateListener { anim -> + // anim.animatedValue will go from 1f → 0f + val fraction = anim.animatedFraction + // lerp scaleFactor from current → 1f + scaleFactor = lerp(scaleFactorStart, 1f, fraction) + // lerp focus back to center + focusX = lerp(focusXStart, width / 2f, fraction) + focusY = lerp(focusYStart, height / 2f, fraction) + invalidate() + } + } + + + private var scaleFactorStart = 1f + private var focusXStart = 0f + private var focusYStart = 0f + + override fun onInterceptTouchEvent(ev: MotionEvent): Boolean { + //lets the detector see all touches + detector.onTouchEvent(ev) + //if we're in a scaling gesture, intercept so children don't steal it + return detector.isInProgress || super.onInterceptTouchEvent(ev) + } + + override fun onTouchEvent(ev: MotionEvent): Boolean { + detector.onTouchEvent(ev) + //consume all touch events to keep the zooming based on the current view + return true + } + + override fun dispatchDraw(canvas: Canvas) { + //before drawing children, scale the canvas around the pivot point + canvas.save() + canvas.translate(focusX, focusY) + canvas.scale(scaleFactor, scaleFactor) + canvas.translate(-focusX, -focusY) + super.dispatchDraw(canvas) + canvas.restore() + } + + //scaleGestureDetector callbacks + override fun onScaleBegin(detector: ScaleGestureDetector) = true + + override fun onScale(detector: ScaleGestureDetector): Boolean { + // Update scale and pivot + scaleFactor = (scaleFactor * detector.scaleFactor).coerceIn(0.5f, 3.0f) + focusX = detector.focusX + focusY = detector.focusY + // Tell Android we need to redraw + invalidate() + return true + } + + + //we now use it for a cleaner approach since it already works + override fun onScaleEnd(detector: ScaleGestureDetector) { + scaleFactorStart = scaleFactor + focusXStart = focusX + focusYStart = focusY + resetAnimator.start() + } + + //simple helper + private fun lerp(a: Float, b: Float, t: Float): Float = a + (b - a) * t +} diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index a06e6a157c..3dd2e36686 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,4 +1,10 @@ + + - \ No newline at end of file + + \ No newline at end of file