/** Save the ProductionSite to DB. */ protected void saveForm() { Log.d(TAG, "Save form."); boolean savedOK = false; if (updating) { getOptionalFields(); savedOK = productionSiteDB.saveProductionSite(site); Log.d(TAG, "Updated the ProductionSite " + site.toString() + ": " + savedOK); } else { // save savedOK = verifyForm(); Log.d(TAG, "Verified the form: " + savedOK); if (savedOK) { createProductionSiteFromForm(); Log.d(TAG, "Has created site from form: " + site.get_id() + ", " + site.toString()); savedOK = productionSiteDB.saveProductionSite(site); } } if (savedOK) { Intent intent = new Intent(this, MainActivity.class); intent.putExtra(MainActivity.EXTRA_SITE_UPDATED, site.getTitle()); startActivity(intent); } else { String text = getString(R.string.toast_could_not_save) + " " + site.getTitle(); Toast.makeText(this, text, Toast.LENGTH_SHORT).show(); } }
/** Show a dialog, confirming the user's wish to delete a ProductionSite. */ private void showDialogDelete() { // ask for confirmation first AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage(getString(R.string.dialog_ask_delete_site) + " " + site.getTitle() + "?"); builder.setCancelable(true); // YES button builder.setPositiveButton( R.string.dialog_yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { deleteProductionSite(); } }); // NO button builder.setNegativeButton( R.string.dialog_no, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // nothing? } }); builder.show(); }