public boolean performAction(android.view.MenuItem item, int position) { if (item.getItemId() == R.id.remove_photo) { // adding a new report if (id == 0) { // Delete by name if (ImageManager.deletePendingPhoto( this, "/" + pendingPhoto.getItem(position).getPhoto())) { pendingPhoto.refresh(); } return true; } else { // editing existing report if (ImageManager.deletePendingPhoto( this, "/" + pendingPhoto.getItem(position).getPhoto())) { pendingPhoto.removeItem(position); } return true; } } return false; }
/** * Post to local database * * @author henryaddo */ private boolean addReport() { log("Adding new reports"); File[] pendingPhotos = PhotoUtils.getPendingPhotos(this); Report report = new Report(); report.setTitle(view.mIncidentTitle.getText().toString()); report.setDescription(view.mIncidentDesc.getText().toString()); report.setLatitude(view.mLatitude.getText().toString()); report.setLongitude(view.mLongitude.getText().toString()); report.setLocationName(view.mIncidentLocation.getText().toString()); report.setReportDate(mDateToSubmit); report.setMode(String.valueOf(0)); report.setVerified(String.valueOf(0)); report.setPending(1); if (id == 0) { // Add a new pending report if (model.addPendingReport( report, mVectorCategories, pendingPhotos, view.mNews.getText().toString())) { // move saved photos log("Moving photos to fetched folder"); ImageManager.movePendingPhotos(this); id = report.getDbId(); } else { return false; } } else { // Update exisiting report List<Photo> photos = new ArrayList<Photo>(); for (int i = 0; i < pendingPhoto.getCount(); i++) { photos.add(pendingPhoto.getItem(i)); } if (model.updatePendingReport( id, report, mVectorCategories, photos, view.mNews.getText().toString())) { // move saved photos log("Moving photos to fetched folder"); ImageManager.movePendingPhotos(this); } else { return false; } } if (mSendOpenGeoSms) { mOgsDao.addReport(id); } else { mOgsDao.deleteReport(id); } return true; }
private void deleteReport() { // make sure it's an existing report if (id > 0) { if (model.deleteReport(id)) { // delete images for (int i = 0; i < pendingPhoto.getCount(); i++) { ImageManager.deletePendingPhoto(this, "/" + pendingPhoto.getItem(i).getPhoto()); } // return to report listing page. finish(); } } }
/** * (non-Javadoc) * * @see android.widget.AdapterView.OnItemClickListener#onItemClick(android.widget .AdapterView, * android.view.View, int, long) */ @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { this.view.mSwitcher.setImageDrawable( ImageManager.getPendingDrawables( this, pendingPhoto.getItem(position).getPhoto(), Util.getScreenWidth(this))); }