diff --git a/app/src/main/java/com/agronick/launcher/MainActivity.kt b/app/src/main/java/com/agronick/launcher/MainActivity.kt index 5cba71f..267c0ea 100644 --- a/app/src/main/java/com/agronick/launcher/MainActivity.kt +++ b/app/src/main/java/com/agronick/launcher/MainActivity.kt @@ -11,8 +11,8 @@ import android.view.Window import androidx.core.view.GestureDetectorCompat - class MainActivity : Activity(), GestureDetector.OnGestureListener { + private var wasScrolling = false private lateinit var mDetector: GestureDetectorCompat private lateinit var mainView: MainView @@ -45,8 +45,9 @@ class MainActivity : Activity(), GestureDetector.OnGestureListener { } else if (mainView.reorderer != null) { mainView.handleLongPress(event) return true - } else if (mainView.wasScrolling && event.action == MotionEvent.ACTION_UP) { + } else if (wasScrolling && event.action == MotionEvent.ACTION_UP) { mainView.checkOverPanLimit() + wasScrolling = false return true } else { super.onTouchEvent(event) @@ -114,8 +115,10 @@ class MainActivity : Activity(), GestureDetector.OnGestureListener { distanceX: Float, distanceY: Float ): Boolean { - mainView.handleScroll(distanceX, distanceY) - mainView.wasScrolling = true + mainView.offsetLeft -= distanceX + mainView.offsetTop -= distanceY + mainView.prepareInvalidate() + wasScrolling = true return true } diff --git a/app/src/main/java/com/agronick/launcher/MainView.kt b/app/src/main/java/com/agronick/launcher/MainView.kt index 9e9626a..8ebb382 100644 --- a/app/src/main/java/com/agronick/launcher/MainView.kt +++ b/app/src/main/java/com/agronick/launcher/MainView.kt @@ -4,7 +4,6 @@ import android.animation.AnimatorSet import android.animation.ValueAnimator import android.content.Context import android.graphics.Canvas -import android.util.Log import android.view.HapticFeedbackConstants import android.view.MotionEvent import android.view.View @@ -24,19 +23,6 @@ class MainView(context: Context, appList: List) : View(context) { private var edgeLimit = 100000f var allHidden = false - var scrollEndFn: (() -> Unit)? = null - var wasScrolling = false - set(value: Boolean) { - if (!wasScrolling) { - Log.e(StaticValues.tag, "ScrollEndFn without scroll") - } - if (scrollEndFn != null) { - scrollEndFn!!() - scrollEndFn = null - } - field = value - } - private val STATE_NONE = 0 private val STATE_REORDERING = 1 private val STATE_OPENING = 2 @@ -98,26 +84,19 @@ class MainView(context: Context, appList: List) : View(context) { val offset = getRelativePosition(Pair(event.x, event.y)) if (state == STATE_REORDERING) { if (event.action == MotionEvent.ACTION_UP) { - val scrollEndEvent = { - reorderer!!.onStopReorder( - when (container.getLimit(offsetLeft, offsetTop, canvasSize)) { - Pair(offsetLeft, offsetTop) -> container.getAppAtPoint( - Vector2( - offset.x, - offset.y - ) + reorderer!!.onStopReorder( + when (container.getLimit(offsetLeft, offsetTop, canvasSize)) { + Pair(offsetLeft, offsetTop) -> container.getAppAtPoint( + Vector2( + offset.x, + offset.y ) - else -> null - } - ) - reorderer = null - resetReorderEdgeTimer() - } - if (wasScrolling) { - scrollEndFn = scrollEndEvent - } else { - scrollEndEvent() - } + ) + else -> null + } + ) + reorderer = null + resetReorderEdgeTimer() } else { reorderer!!.onMove(offset) val newOffsets = @@ -168,10 +147,7 @@ class MainView(context: Context, appList: List) : View(context) { duration = StaticValues.durationOpen playTogether(*animators.toTypedArray()) start() - doOnEnd { wasScrolling = false } } - } else { - wasScrolling = false } }