rework deprecated showDialog

This commit is contained in:
afischerdev 2023-03-15 19:12:33 +01:00
parent 585724dbf8
commit 1925cbecab
2 changed files with 36 additions and 23 deletions

View file

@ -324,12 +324,14 @@ public class BInstallerActivity extends AppCompatActivity {
} }
@Override
protected Dialog onCreateDialog(int id) { protected Dialog createADialog(int id) {
AlertDialog.Builder builder; AlertDialog.Builder builder;
builder = new AlertDialog.Builder(this);
builder.setCancelable(false);
switch (id) { switch (id) {
case DIALOG_CONFIRM_DELETE_ID: case DIALOG_CONFIRM_DELETE_ID:
builder = new AlertDialog.Builder(this);
builder builder
.setTitle("Confirm Delete") .setTitle("Confirm Delete")
.setMessage("Really delete?").setPositiveButton("Yes", new DialogInterface.OnClickListener() { .setMessage("Really delete?").setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@ -343,7 +345,6 @@ public class BInstallerActivity extends AppCompatActivity {
return builder.create(); return builder.create();
case DIALOG_CONFIRM_NEXTSTEPS_ID: case DIALOG_CONFIRM_NEXTSTEPS_ID:
builder = new AlertDialog.Builder(this);
builder builder
.setTitle("Version Problem") .setTitle("Version Problem")
.setMessage("The base version for tiles has changed. What to do?") .setMessage("The base version for tiles has changed. What to do?")
@ -373,7 +374,6 @@ public class BInstallerActivity extends AppCompatActivity {
return builder.create(); return builder.create();
case DIALOG_CONFIRM_GETDIFFS_ID: case DIALOG_CONFIRM_GETDIFFS_ID:
builder = new AlertDialog.Builder(this);
builder builder
.setTitle("Version Differences") .setTitle("Version Differences")
.setMessage("The base version for some tiles is different. What to do?") .setMessage("The base version for some tiles is different. What to do?")
@ -397,16 +397,21 @@ public class BInstallerActivity extends AppCompatActivity {
} }
} }
void showADialog(int id) {
Dialog d = createADialog(id);
if (d != null) d.show();
}
public void showConfirmDelete() { public void showConfirmDelete() {
showDialog(DIALOG_CONFIRM_DELETE_ID); showADialog(DIALOG_CONFIRM_DELETE_ID);
} }
public void showConfirmNextSteps() { public void showConfirmNextSteps() {
showDialog(DIALOG_CONFIRM_NEXTSTEPS_ID); showADialog(DIALOG_CONFIRM_NEXTSTEPS_ID);
} }
private void showConfirmGetDiffs() { private void showConfirmGetDiffs() {
showDialog(DIALOG_CONFIRM_GETDIFFS_ID); showADialog(DIALOG_CONFIRM_GETDIFFS_ID);
} }
@ -453,7 +458,7 @@ public class BInstallerActivity extends AppCompatActivity {
private void downloadInstalledTiles() { private void downloadInstalledTiles() {
ArrayList<Integer> selectedTiles = mBInstallerView.getSelectedTiles(MASK_INSTALLED_RD5); ArrayList<Integer> selectedTiles = mBInstallerView.getSelectedTiles(MASK_INSTALLED_RD5);
ArrayList<Integer> tmpSelectedTiles = mBInstallerView.getSelectedTiles(MASK_SELECTED_RD5); ArrayList<Integer> tmpSelectedTiles = mBInstallerView.getSelectedTiles(MASK_SELECTED_RD5);
if (tmpSelectedTiles.size()>0) { if (tmpSelectedTiles.size() > 0) {
selectedTiles.addAll(tmpSelectedTiles); selectedTiles.addAll(tmpSelectedTiles);
} }
downloadAll(selectedTiles, DownloadWorker.VALUE_SEGMENT_ALL); downloadAll(selectedTiles, DownloadWorker.VALUE_SEGMENT_ALL);

View file

@ -78,8 +78,7 @@ public class BRouterActivity extends AppCompatActivity implements ActivityCompat
setContentView(mBRouterView); setContentView(mBRouterView);
} }
@Override protected Dialog createADialog(int id) {
protected Dialog onCreateDialog(int id) {
AlertDialog.Builder builder; AlertDialog.Builder builder;
builder = new AlertDialog.Builder(this); builder = new AlertDialog.Builder(this);
builder.setCancelable(false); builder.setCancelable(false);
@ -103,7 +102,7 @@ public class BRouterActivity extends AppCompatActivity implements ActivityCompat
if (item == 0) if (item == 0)
startDownloadManager(); startDownloadManager();
else else
showDialog(DIALOG_SELECTPROFILE_ID); showADialog(DIALOG_SELECTPROFILE_ID);
} }
}) })
.setNegativeButton("Close", new DialogInterface.OnClickListener() { .setNegativeButton("Close", new DialogInterface.OnClickListener() {
@ -214,7 +213,7 @@ public class BRouterActivity extends AppCompatActivity implements ActivityCompat
if (selectedBasedir < availableBasedirs.size()) { if (selectedBasedir < availableBasedirs.size()) {
mBRouterView.startSetup(availableBasedirs.get(selectedBasedir), true); mBRouterView.startSetup(availableBasedirs.get(selectedBasedir), true);
} else { } else {
showDialog(DIALOG_TEXTENTRY_ID); showADialog(DIALOG_TEXTENTRY_ID);
} }
} }
}); });
@ -338,11 +337,11 @@ public class BRouterActivity extends AppCompatActivity implements ActivityCompat
Arrays.sort(availableProfiles); Arrays.sort(availableProfiles);
// show main dialog // show main dialog
showDialog(DIALOG_MAINACTION_ID); showADialog(DIALOG_MAINACTION_ID);
} }
public void startDownloadManager() { public void startDownloadManager() {
showDialog(DIALOG_SHOW_DM_INFO_ID); showADialog(DIALOG_SHOW_DM_INFO_ID);
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@ -354,7 +353,11 @@ public class BRouterActivity extends AppCompatActivity implements ActivityCompat
long size = 0L; long size = 0L;
try { try {
StatFs stat = new StatFs(f.getAbsolutePath()); StatFs stat = new StatFs(f.getAbsolutePath());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
size = stat.getAvailableBlocksLong() * stat.getBlockSizeLong();
} else {
size = (long) stat.getAvailableBlocks() * stat.getBlockSize(); size = (long) stat.getAvailableBlocks() * stat.getBlockSize();
}
} catch (Exception e) { } catch (Exception e) {
/* ignore */ } /* ignore */ }
dirFreeSizes.add(size); dirFreeSizes.add(size);
@ -376,26 +379,26 @@ public class BRouterActivity extends AppCompatActivity implements ActivityCompat
basedirOptions[bdidx] = "Enter path manually"; basedirOptions[bdidx] = "Enter path manually";
} }
showDialog(DIALOG_SELECTBASEDIR_ID); showADialog(DIALOG_SELECTBASEDIR_ID);
} }
public void selectRoutingModes(String[] modes, boolean[] modesChecked, String message) { public void selectRoutingModes(String[] modes, boolean[] modesChecked, String message) {
routingModes = modes; routingModes = modes;
routingModesChecked = modesChecked; routingModesChecked = modesChecked;
this.message = message; this.message = message;
showDialog(DIALOG_ROUTINGMODES_ID); showADialog(DIALOG_ROUTINGMODES_ID);
} }
public void showModeConfigOverview(String message) { public void showModeConfigOverview(String message) {
this.message = message; this.message = message;
showDialog(DIALOG_MODECONFIGOVERVIEW_ID); showADialog(DIALOG_MODECONFIGOVERVIEW_ID);
} }
public void selectVias(String[] items) { public void selectVias(String[] items) {
availableVias = items; availableVias = items;
selectedVias = new HashSet<>(availableVias.length); selectedVias = new HashSet<>(availableVias.length);
Collections.addAll(selectedVias, items); Collections.addAll(selectedVias, items);
showDialog(DIALOG_VIASELECT_ID); showADialog(DIALOG_VIASELECT_ID);
} }
public void selectWaypoint(String[] items) { public void selectWaypoint(String[] items) {
@ -409,15 +412,20 @@ public class BRouterActivity extends AppCompatActivity implements ActivityCompat
public void selectNogos(List<OsmNodeNamed> nogoList) { public void selectNogos(List<OsmNodeNamed> nogoList) {
this.nogoList = nogoList; this.nogoList = nogoList;
showDialog(DIALOG_NOGOSELECT_ID); showADialog(DIALOG_NOGOSELECT_ID);
}
private void showADialog(int id) {
Dialog d = createADialog(id);
if (d!=null) d.show();
} }
private void showNewDialog(int id) { private void showNewDialog(int id) {
if (dialogIds.contains(id)) { if (dialogIds.contains(id)) {
removeDialog(id); // removeDialog(id);
} }
dialogIds.add(id); dialogIds.add(id);
showDialog(id); showADialog(id);
} }
public void showErrorMessage(String msg) { public void showErrorMessage(String msg) {