diff --git a/brouter-routing-app/src/main/java/btools/routingapp/BInstallerActivity.java b/brouter-routing-app/src/main/java/btools/routingapp/BInstallerActivity.java index 31320dc..e14b800 100644 --- a/brouter-routing-app/src/main/java/btools/routingapp/BInstallerActivity.java +++ b/brouter-routing-app/src/main/java/btools/routingapp/BInstallerActivity.java @@ -59,7 +59,12 @@ public class BInstallerActivity extends Activity { setContentView(R.layout.activity_binstaller); mBInstallerView = findViewById(R.id.BInstallerView); mBInstallerView.setOnClickListener( - view -> mBInstallerView.toggleDownload() + view -> { + if (mBInstallerView.getSelectedTiles(MASK_DELETED_RD5).size() > 0) { + showConfirmDelete(); + } + mBInstallerView.toggleDownload(); + } ); mDownloadInfo = findViewById(R.id.view_download_progress); mDownloadInfoText = findViewById(R.id.textViewDownloadProgress); @@ -72,14 +77,6 @@ public class BInstallerActivity extends Activity { scanExistingFiles(); } - private String baseNameForTile(int tileIndex) { - int lon = (tileIndex % 72) * 5 - 180; - int lat = (tileIndex / 72) * 5 - 90; - String slon = lon < 0 ? "W" + (-lon) : "E" + lon; - String slat = lat < 0 ? "S" + (-lat) : "N" + lat; - return slon + "_" + slat; - } - private void deleteRawTracks() { File modeDir = new File(mBaseDir, "brouter/modes"); String[] fileNames = modeDir.list(); @@ -149,7 +146,7 @@ public class BInstallerActivity extends Activity { .setTitle("Confirm Delete") .setMessage("Really delete?").setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { - mBInstallerView.deleteSelectedTiles(); + deleteSelectedTiles(); } }).setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { @@ -199,6 +196,14 @@ public class BInstallerActivity extends Activity { } } + private void deleteSelectedTiles() { + ArrayList selectedTiles = mBInstallerView.getSelectedTiles(MASK_DELETED_RD5); + for (int tileIndex : selectedTiles) { + new File(mBaseDir, "brouter/segments4/" + baseNameForTile(tileIndex) + ".rd5").delete(); + } + scanExistingFiles(); + } + private int tileForBaseName(String basename) { String uname = basename.toUpperCase(Locale.ROOT); int idx = uname.indexOf("_"); @@ -214,6 +219,14 @@ public class BInstallerActivity extends Activity { return (ilon + 180) / 5 + 72 * ((ilat + 90) / 5); } + protected String baseNameForTile(int tileIndex) { + int lon = (tileIndex % 72) * 5 - 180; + int lat = (tileIndex / 72) * 5 - 90; + String slon = lon < 0 ? "W" + (-lon) : "E" + lon; + String slat = lat < 0 ? "S" + (-lat) : "N" + lat; + return slon + "_" + slat; + } + public class DownloadReceiver extends BroadcastReceiver { @Override diff --git a/brouter-routing-app/src/main/java/btools/routingapp/BInstallerView.java b/brouter-routing-app/src/main/java/btools/routingapp/BInstallerView.java index af90c5c..e8d82f6 100644 --- a/brouter-routing-app/src/main/java/btools/routingapp/BInstallerView.java +++ b/brouter-routing-app/src/main/java/btools/routingapp/BInstallerView.java @@ -86,7 +86,6 @@ public class BInstallerView extends View { } tileStatus = new int[72 * 36]; - scanExistingFiles(); float scaleX = imgwOrig / ((float) bmp.getWidth()); float scaley = imghOrig / ((float) bmp.getHeight()); @@ -97,10 +96,6 @@ public class BInstallerView extends View { mat.postScale(viewscale, viewscale); } - private void scanExistingFiles() { - - } - public void setAvailableSize(long availableSize) { this.availableSize = availableSize; } @@ -119,6 +114,20 @@ public class BInstallerView extends View { invalidate(); } + public ArrayList getSelectedTiles(int tileMask) { + ArrayList selectedTiles = new ArrayList<>(); + for (int ix = 0; ix < 72; ix++) { + for (int iy = 0; iy < 36; iy++) { + int tileIndex = gridPos2Tileindex(ix, iy); + if ((tileStatus[tileIndex] & tileMask) != 0 && BInstallerSizes.getRd5Size(tileIndex) > 0) { + selectedTiles.add(tileIndex); + } + } + } + + return selectedTiles; + } + @Override public void setOnClickListener(OnClickListener listener) { mOnClickListener = listener; @@ -137,11 +146,6 @@ public class BInstallerView extends View { } public void toggleDownload() { - if (delTiles > 0) { - ((BInstallerActivity) getContext()).showConfirmDelete(); - return; - } - int min_size = Integer.MAX_VALUE; ArrayList downloadList = new ArrayList<>(); @@ -298,19 +302,6 @@ public class BInstallerView extends View { } } - public void deleteSelectedTiles() { - for (int ix = 0; ix < 72; ix++) { - for (int iy = 0; iy < 36; iy++) { - int tidx = gridPos2Tileindex(ix, iy); - if ((tileStatus[tidx] & MASK_DELETED_RD5) != 0) { - new File(baseDir, "brouter/segments4/" + baseNameForTile(tidx) + ".rd5").delete(); - } - } - } - scanExistingFiles(); - invalidate(); - } - @Override public boolean onTouchEvent(MotionEvent event) {