use of com.ushahidi.android.app.entities.ReportEntity in project Ushahidi_Android by ushahidi.
the class ReportDao method fetchPendingReportByCategoryId.
@Override
public List<ReportEntity> fetchPendingReportByCategoryId(int categoryId) {
final String sortOrder = INCIDENT_TITLE + " DESC";
final String sql = "SELECT reports.* FROM " + INCIDENTS_TABLE + " reports INNER JOIN " + IReportCategorySchema.TABLE + " cats ON reports." + ID + " = cats." + IReportCategorySchema.REPORT_ID + " WHERE cats." + IReportCategorySchema.CATEGORY_ID + " =? AND " + "cats." + IReportCategorySchema.STATUS + " =? AND cats." + INCIDENT_PENDING + "=? ORDER BY " + sortOrder;
final String[] selectionArgs = { String.valueOf(categoryId), String.valueOf(IReportSchema.PENDING), String.valueOf(IReportSchema.PENDING) };
listReport = new ArrayList<ReportEntity>();
cursor = super.rawQuery(sql, selectionArgs);
if (cursor != null) {
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
ReportEntity report = cursorToEntity(cursor);
listReport.add(report);
cursor.moveToNext();
}
cursor.close();
}
return listReport;
}
use of com.ushahidi.android.app.entities.ReportEntity in project Ushahidi_Android by ushahidi.
the class ReportDao method fetchAllPendingReports.
@Override
public List<ReportEntity> fetchAllPendingReports() {
final String sortOrder = INCIDENT_DATE + " DESC";
final String selection = INCIDENT_PENDING + " =?";
final String[] selectionArgs = { String.valueOf(1) };
listReport = new ArrayList<ReportEntity>();
cursor = super.query(INCIDENTS_TABLE, null, selection, selectionArgs, sortOrder);
if (cursor != null) {
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
ReportEntity report = cursorToEntity(cursor);
listReport.add(report);
cursor.moveToNext();
}
cursor.close();
}
return listReport;
}
use of com.ushahidi.android.app.entities.ReportEntity in project Ushahidi_Android by ushahidi.
the class AddReportActivity method setSavedReport.
/**
* Edit existing report
*
* @author henryaddo
*/
private void setSavedReport(int reportId) {
// set text part of reports
ReportEntity report = model.fetchPendingReportById(reportId);
if (report != null) {
view.mIncidentTitle.setText(report.getIncident().getTitle());
view.mIncidentDesc.setText(report.getIncident().getDescription());
view.mLongitude.setText(String.valueOf(report.getIncident().getLongitude()));
view.mLatitude.setText(String.valueOf(report.getIncident().getLatitude()));
view.mIncidentLocation.setText(report.getIncident().getLocationName());
// set date and time
setDateAndTime(report.getIncident().getDate());
}
// set Categories.
mVectorCategories.clear();
for (ReportCategory reportCategory : model.fetchReportCategories(reportId, IReportSchema.PENDING)) {
mVectorCategories.add(reportCategory.getCategoryId());
}
setSelectedCategories(mVectorCategories);
// set the photos
pendingPhoto.refresh(id);
// set news
List<MediaEntity> 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(report.getIncident().getLatitude(), report.getIncident().getLongitude(), true);
}
}
use of com.ushahidi.android.app.entities.ReportEntity 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.android.app.entities.ReportEntity 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