use of com.ushahidi.java.sdk.api.Incident in project Ushahidi_Android by ushahidi.
the class ReportDao method cursorToEntity.
@SuppressWarnings("unchecked")
@Override
protected ReportEntity cursorToEntity(Cursor cursor) {
ReportEntity r = new ReportEntity();
Incident report = new Incident();
int idIndex;
int reportIdIndex;
int titleIndex;
int dateIndex;
int verifiedIndex;
int locationIndex;
int descIndex;
int longitudeIndex;
int latitudeIndex;
if (cursor != null) {
if (cursor.getColumnIndex(ID) != -1) {
idIndex = cursor.getColumnIndexOrThrow(ID);
r.setDbId(cursor.getInt(idIndex));
}
if (cursor.getColumnIndex(INCIDENT_ID) != -1) {
reportIdIndex = cursor.getColumnIndexOrThrow(INCIDENT_ID);
report.setId(cursor.getInt(reportIdIndex));
}
if (cursor.getColumnIndex(INCIDENT_TITLE) != -1) {
titleIndex = cursor.getColumnIndexOrThrow(INCIDENT_TITLE);
report.setTitle(cursor.getString(titleIndex));
}
if (cursor.getColumnIndex(INCIDENT_DATE) != -1) {
dateIndex = cursor.getColumnIndexOrThrow(INCIDENT_DATE);
report.setDate(setDate(cursor.getString(dateIndex)));
}
if (cursor.getColumnIndex(INCIDENT_VERIFIED) != -1) {
verifiedIndex = cursor.getColumnIndexOrThrow(INCIDENT_VERIFIED);
report.setVerified(cursor.getInt(verifiedIndex));
}
if (cursor.getColumnIndex(INCIDENT_LOC_NAME) != -1) {
locationIndex = cursor.getColumnIndexOrThrow(INCIDENT_LOC_NAME);
report.setLocationName(cursor.getString(locationIndex));
}
if (cursor.getColumnIndex(INCIDENT_DESC) != -1) {
descIndex = cursor.getColumnIndexOrThrow(INCIDENT_DESC);
report.setDescription(cursor.getString(descIndex));
}
if (cursor.getColumnIndex(INCIDENT_LOC_LATITUDE) != -1) {
latitudeIndex = cursor.getColumnIndexOrThrow(INCIDENT_LOC_LATITUDE);
report.setLatitude(cursor.getDouble(latitudeIndex));
}
if (cursor.getColumnIndex(INCIDENT_LOC_LONGITUDE) != -1) {
longitudeIndex = cursor.getColumnIndexOrThrow(INCIDENT_LOC_LONGITUDE);
report.setLongitude(cursor.getDouble(longitudeIndex));
}
r.setIncident(report);
}
return r;
}
use of com.ushahidi.java.sdk.api.Incident in project Ushahidi_Android by ushahidi.
the class AddReportActivity method addReport.
/**
* Post to local database
*
* @author henryaddo
*/
private boolean addReport() {
log("Adding new reports");
File[] pendingPhotos = PhotoUtils.getPendingPhotos(this);
ReportEntity report = new ReportEntity();
Incident incident = new Incident();
incident.setTitle(view.mIncidentTitle.getText().toString());
incident.setDescription(view.mIncidentDesc.getText().toString());
incident.setMode(0);
incident.setLocationName(view.mIncidentLocation.getText().toString());
incident.setVerified(0);
incident.setLatitude(Double.valueOf(view.mLatitude.getText().toString()));
incident.setLongitude(Double.valueOf(view.mLongitude.getText().toString()));
if (date != null) {
incident.setDate(date);
} else {
incident.setDate(new Date());
}
report.setIncident(incident);
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 existing report
List<PhotoEntity> photos = new ArrayList<PhotoEntity>();
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;
}
use of com.ushahidi.java.sdk.api.Incident in project Ushahidi_Android by ushahidi.
the class ListReportFragment method uploadPendingReports.
private boolean uploadPendingReports() {
boolean retVal = true;
ReportFields fields = new ReportFields();
Incident incident = new Incident();
ReportsApi reportApi = new ReportsApi();
if (mPendingReports != null) {
for (ReportEntity report : mPendingReports) {
long rid = report.getDbId();
;
int state = Database.mOpenGeoSmsDao.getReportState(rid);
if (state != IOpenGeoSmsSchema.STATE_NOT_OPENGEOSMS) {
if (!sendOpenGeoSmsReport(report, state)) {
retVal = false;
}
continue;
}
// Set the incident details
incident.setTitle(report.getIncident().getTitle());
incident.setDescription(report.getIncident().getDescription());
incident.setDate(report.getIncident().getDate());
incident.setLatitude(report.getIncident().getLatitude());
incident.setLongitude(report.getIncident().getLongitude());
incident.setLocationName(report.getIncident().getLocationName());
fields.fill(incident);
// Set person details
if ((!TextUtils.isEmpty(Preferences.fileName)) && (!TextUtils.isEmpty(Preferences.lastname)) && (!TextUtils.isEmpty(Preferences.email))) {
fields.setPerson(new Person(Preferences.firstname, Preferences.lastname, Preferences.email));
}
// Add categories
fields.addCategory(report.getCategories());
// Add photos
List<File> photos = new UploadPhotoAdapter(getActivity()).pendingPhotos((int) report.getDbId());
if (photos != null && photos.size() > 0)
fields.addPhotos(photos);
// Upload
Response response = reportApi.submitReport(fields);
if (response != null) {
if (response.getErrorCode() == 0) {
deletePendingReport((int) report.getDbId());
} else {
retVal = false;
}
} else {
deletePendingReport((int) report.getDbId());
}
}
}
return retVal;
}
Aggregations