Move SSD dialog visibility checks to typed Kotlin
ober
7988308241dd4e62fa4bbab7e9a19833e522ecc1
--- a/templates/ssd-review.ss +++ b/templates/ssd-review.ss @@ -3799,6 +3799,8 @@ noSsdPdfsFoundStatus dialogCountValue editedGroupCountText selectionIgnoredLoadingStatus + shouldShowFiringArc shouldFocusFiringArc + hasReplacementLabel hasResolvedLabel clampPageIndex shiftPageIndex displayGroupCanvasLabel dropdownHeight dialogPageNumber dialogPageNumberText pageNumberText sessionIdFromUuid nullableLowercaseOrEmpty @@ -4172,6 +4174,17 @@ (parsedCountOrFallback text fallback)) (def (selectionIgnoredLoadingStatus) : String "Selection ignored: truth/detection is still loading") + (def (shouldShowFiringArc (firingArcText : String) + (boxTypeIsWeapon : Bool)) : Bool + (or (not (string-blank? firingArcText)) boxTypeIsWeapon)) + (def (shouldFocusFiringArc (firingArcText : String) + (boxTypeIsWeapon : Bool)) : Bool + (and (shouldShowFiringArc firingArcText boxTypeIsWeapon) + (string-blank? firingArcText))) + (def (hasReplacementLabel (replacement : String)) : Bool + (not (string-blank? replacement))) + (def (hasResolvedLabel (resolved : String)) : Bool + (not (string-blank? resolved))) (def (dropdownHeight (screenHeight : Int32)) : Int32 (let ((third (/ screenHeight (int32 3)))) (if (> third (int32 620)) @@ -5413,7 +5426,7 @@ " ) {" " var previousBoxType = initialBoxType" " fun update() {" - " val visible = firingArc.text.isNotBlank() || boxTypeRawIsWeapon(this, boxType.text.toString())" + " val visible = shouldShowFiringArc(firingArc.text.toString(), boxTypeRawIsWeapon(this, boxType.text.toString()))" " firingArc.visibility = if (visible) View.VISIBLE else View.GONE" " }" " boxType.addTextChangedListener(object : TextWatcher {" @@ -5425,7 +5438,7 @@ " replaceAutoLabelForBoxType(label, boxType.text.toString(), previousBoxType)" " previousBoxType = boxType.text.toString()" " update()" - " if (firingArc.visibility == View.VISIBLE && firingArc.text.isBlank()) {" + " if (shouldFocusFiringArc(firingArc.text.toString(), boxTypeRawIsWeapon(this, boxType.text.toString()))) {" " firingArc.requestFocus()" " firingArc.showDropDown()" " }" @@ -5436,7 +5449,7 @@ " private fun replaceAutoLabelForBoxType(label: EditText, boxType: String, previousBoxType: String) {" " if (!shouldReplaceLabelForBoxTypeAndroid(this, label.text.toString(), previousBoxType)) return" " val replacement = defaultLabelForBoxTypeAndroid(this, boxType)" - " if (replacement.isBlank()) return" + " if (!hasReplacementLabel(replacement)) return" " label.setText(replacement)" " label.setSelection(label.text.length)" " }" @@ -5444,7 +5457,7 @@ " private fun finalizeGroupLabel(group: SsdGroup) {" " val typeDisplay = BoxTypes.display(this, group.boxTypeId)" " val resolved = resolvedLabelForBoxTypeAndroid(this, group.label, typeDisplay, group.boxTypeId)" - " if (resolved.isNotBlank()) {" + " if (hasResolvedLabel(resolved)) {" " group.label = resolved" " }" " }"