/** 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(); }
/** Read the optional fields in the form and fill in the site */ private void getOptionalFields() { site.setName(etName.getText().toString()); site.setAddress(etAddress.getText().toString()); site.setPostnr(etPostnr.getText().toString()); site.setPostaddress(etPostaddress.getText().toString()); site.setCoordinates(etCoord.getText().toString()); if (imageUri != null) { Log.d(TAG, "Saving URI: " + imageUri.toString()); site.setImageUriStr(imageUri.toString()); } }
/** Fill fields with intent-extras, disable input on ProductionSiteNr. */ private void setupUpdate() { updating = true; Intent intent = getIntent(); String siteNrStr = intent.getStringExtra(EXTRA_PRODUCTION_SITE); ProductionSiteNr siteNr = new ProductionSiteNr(siteNrStr); if (siteNr != null) { site = productionSiteDB.getProductionSite(siteNr); } if (site == null) { String text = getString(R.string.toast_could_not_fetch) + " " + siteNrStr; Toast.makeText(this, text, Toast.LENGTH_SHORT).show(); return; } Log.d(TAG, "site id: " + site.get_id()); etOrg.setText(site.getSiteNr().getOrg()); etPpnr.setText(site.getSiteNr().getPpnr()); // disable input Utils.disableEntry(etOrg); Utils.disableEntry(etPpnr); if (site.hasName()) etName.setText(site.getName()); if (site.hasAddress()) etAddress.setText(site.getAddress()); if (site.hasPostnr()) etPostnr.setText(site.getPostnr()); if (site.hasPostaddress()) etPostaddress.setText(site.getPostaddress()); if (site.hasCoordinates()) etCoord.setText(site.getCoordinates()); if (site.hasImageUriStr()) { imageUri = Uri.parse(site.getImageUriStr()); Log.d(TAG, "loaded URI: " + imageUri); setThumbnail(); } else { Log.d(TAG, "no loaded URI"); } }