/** * Edit existing report * * @author henryaddo */ private void setSavedReport(int reportId) { // set text part of reports Report report = model.fetchPendingReportById(reportId); if (report != null) { view.mIncidentTitle.setText(report.getTitle()); view.mIncidentDesc.setText(report.getDescription()); view.mLongitude.setText(report.getLongitude()); view.mLatitude.setText(report.getLatitude()); view.mIncidentLocation.setText(report.getLocationName()); // set date and time setDateAndTime(report.getReportDate()); } // set Categories. mVectorCategories.clear(); for (ReportCategory reportCategory : model.fetchReportCategories(reportId)) { mVectorCategories.add(String.valueOf(reportCategory.getCategoryId())); } setSelectedCategories(mVectorCategories); // set the photos pendingPhoto.refresh(id); // set news List<Media> newsMedia = model.fetchReportNews(reportId); if (newsMedia != null && newsMedia.size() > 0) { view.mNews.setText(newsMedia.get(0).getLink()); } mIsReportEditable = mOgsDao.getReportState(id) != IOpenGeoSmsSchema.STATE_SENT; if (!mIsReportEditable) { View views[] = new View[] { view.mBtnAddCategory, view.mIncidentDesc, view.mIncidentLocation, view.mIncidentTitle, view.mLatitude, view.mLongitude, view.mPickDate, view.mPickTime }; for (View v : views) { v.setEnabled(false); } updateMarker( Double.parseDouble(report.getLatitude()), Double.parseDouble(report.getLongitude()), true); } }
/** * 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; }