Skip to content

Commit 08aa3ba

Browse files
Merge pull request #267 from appdevforall/fix/ADFA-4884-delete-toggle
ADFA-4884: fix inverted delete-list toggle (mirror the tool's real st…
2 parents 1a0a56a + bd42f17 commit 08aa3ba

1 file changed

Lines changed: 11 additions & 10 deletions

File tree

‎controller/app/src/main/java/org/iiab/controller/redesign/FqrController.java‎

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -133,17 +133,16 @@ public void onExtractRequested(String name, String box) {
133133
box == null ? "" : box.replaceAll("\\s+", "")));
134134
}
135135

136-
/** The map's trash tool was activated → open the (searchable) region list so the user doesn't
137-
* have to hunt a tiny rectangle on the map. */
136+
/** The map's trash tool was toggled; {@code on} is its REAL state (read from the map cursor, not a
137+
* parallel flip that could desync/invert). Open the list when it turns on, close it when off. A
138+
* second press dismisses the list (feels native); closing via the sheet's X doesn't change the
139+
* tool, so the next deactivate correctly leaves it closed. */
138140
@JavascriptInterface
139-
public void onDeleteToolOpened() {
141+
public void onDeleteToolState(boolean on) {
140142
if (!active) return;
141-
// The map's trash tool toggles on every click, so mirror it: open on activate, close on
142-
// deactivate — a second press dismisses the list (feels native). Closing via the sheet's own
143-
// X does NOT flip this flag, so the following deactivate press correctly leaves it closed.
144143
activity.runOnUiThread(() -> {
145-
deleteToolOn = !deleteToolOn;
146-
if (deleteToolOn) openDeleteList(null);
144+
deleteToolOn = on;
145+
if (on) openDeleteList(null);
147146
else hideDeleteSheet();
148147
});
149148
}
@@ -587,12 +586,14 @@ private static String human(long bytes) {
587586
"var pre=(n.matches&&n.matches('pre'))?n:(n.querySelector?n.querySelector('.maplibregl-popup pre, pre'):null);" +
588587
"if(pre)handleDelete(pre);}});});" +
589588
// Connect the observer only while the trash tool is on -> no churn during normal map use.
590-
"var observing=false,deleteMode=false;" +
589+
"var observing=false;" +
591590
"function setObserve(on){try{if(on&&!observing){mo.observe(sr,{childList:true,subtree:true});observing=true;}else if(!on&&observing){mo.disconnect();observing=false;}}catch(e){}}" +
592591
// Delegated clicks: the trash tool opens our list; "Next" finalizes the extract name.
593592
"sr.addEventListener('click',function(ev){try{var path=ev.composedPath?ev.composedPath():[];" +
594593
"for(var i=0;i<path.length;i++){var el=path[i];if(!el)continue;" +
595-
"if(el.title==='Choose region to delete'){deleteMode=!deleteMode;setObserve(deleteMode);if(window.K2GoFQR&&K2GoFQR.onDeleteToolOpened){K2GoFQR.onDeleteToolOpened();}break;}" +
594+
// Read the tool's REAL state from the map cursor (crosshair = active) after the click,
595+
// so open/close mirrors the tool exactly (no flip-based desync/inversion).
596+
"if(el.title==='Choose region to delete'){setTimeout(function(){try{var on=host.map.getCanvas().style.cursor==='crosshair';setObserve(on);if(window.K2GoFQR&&K2GoFQR.onDeleteToolState){K2GoFQR.onDeleteToolState(on);}}catch(e){}},0);break;}" +
596597
"if(el.tagName==='BUTTON'&&(el.textContent||'').trim()==='Next'){setTimeout(fireExtract,0);break;}" +
597598
"}}catch(e){}},true);" +
598599
// Native calls this to fly the map behind the list sheet to a picked region.

0 commit comments

Comments
 (0)