Move SSD review view null checks to typed Kotlin
ober
14ed2561a76d00f8f59b7f0acceaec26eb8faff0
--- a/templates/ssd-review.ss +++ b/templates/ssd-review.ss @@ -1233,7 +1233,8 @@ rotationIs90 rotationIs180 rotationIs270 touchMoveExceeded shouldCollectSelectionMatches selectionUsesRawRect selectionHasMatches - selectionDragReady selectionRectTooSmall + selectionDragReady selectionDragReadyForPoints + selectionRectTooSmall touchShouldScale touchShouldIgnoreMultiPointer touchSelectionActive touchPanReady touchTapReady touchPointerReady touchPointerNotReady @@ -1279,6 +1280,13 @@ (hasStart : Bool) (hasEnd : Bool)) : Bool (and selectMode (and hasStart hasEnd))) + (def (selectionDragReadyForPoints (selectMode : Bool) + (start : (Nullable FloatArray)) + (end : (Nullable FloatArray))) : Bool + (selectionDragReady + selectMode + (not (nullable-null? start)) + (not (nullable-null? end)))) (def (selectionRectTooSmall (rect : FloatArray) (minimumSize : Float32)) : Bool (and (< (- (float-array-ref rect (int32 2)) (float-array-ref rect (int32 0))) @@ -8085,7 +8093,7 @@ " lastY = event.y" " invalidate()" " } else if (motionActionIsUpOrCancel(event.actionMasked, MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL)) {" - " if (selectionDragReady(selectMode, dragStart != null, dragEnd != null)) {" + " if (selectionDragReadyForPoints(selectMode, dragStart, dragEnd)) {" " finishSelection()" " } else if (touchTapReady(selectMode, moved, motionActionIsUp(event.actionMasked, MotionEvent.ACTION_UP))) {" " val point = viewToImage(event.x, event.y)" @@ -8133,11 +8141,12 @@ "" " fun restoreViewport(viewport: ViewportState?) {" " val img = bitmap ?: return" - " if (viewport == null) return" - " if (viewportImageMismatch(viewport, img.width, img.height, rotationDegrees)) return" - " scale = viewport.scale" - " offsetX = viewport.offsetX" - " offsetY = viewport.offsetY" + " if (!viewportStatePresent(viewport)) return" + " val savedViewport = viewportStateOrEmpty(viewport)" + " if (viewportImageMismatch(savedViewport, img.width, img.height, rotationDegrees)) return" + " scale = savedViewport.scale" + " offsetX = savedViewport.offsetX" + " offsetY = savedViewport.offsetY" " clampOffsets()" " updateMatrix()" " invalidate()"