use of com.ushahidi.android.app.entities.ReportEntity in project Ushahidi_Android by ushahidi.
the class ReportsApi method getReportList.
/**
* Fetch reports via the Ushahidi API
*
* @param context The calling activity
* @return The list of reports
*/
private List<ReportEntity> getReportList(Context context) {
log("Save report");
if (processingResult) {
try {
List<Incidents> incidents = task.all();
if (incidents != null && incidents.size() > 0) {
for (Incidents i : incidents) {
ReportEntity report = new ReportEntity();
report.setIncident(i.incident);
reports.add(report);
// save categories
if ((i.getCategories() != null) && (i.getCategories().size() > 0)) {
for (Category c : i.getCategories()) {
saveCategories(c.getId(), i.incident.getId());
}
}
// save media
if ((i.getMedia() != null) && (!i.getMedia().isEmpty())) {
for (com.ushahidi.java.sdk.api.Media m : i.getMedia()) {
// find photos, it's type is 1
if (m != null) {
if (m.getType() == 1) {
if (m.getLinkUrl() != null) {
//This will capture entire picture descriptor to prevent duplicates
final String fileName = m.getLinkUrl().substring(m.getLinkUrl().lastIndexOf('/') + 1, m.getLinkUrl().length());
// save details of photo to database
saveMedia(m.getId(), i.incident.getId(), m.getType(), fileName);
saveImages(m.getLinkUrl(), fileName, context);
}
} else {
// other media type to database
if (m.getLink() != null)
saveMedia(m.getId(), (int) i.incident.getId(), m.getType(), m.getLink());
}
}
}
}
}
}
} catch (UshahidiException e) {
log("UshahidiException", e);
processingResult = false;
} catch (JsonSyntaxException e) {
log("JSONSyntaxException", e);
processingResult = false;
}
}
return reports;
}
use of com.ushahidi.android.app.entities.ReportEntity in project Ushahidi_Android by ushahidi.
the class ReportDao method fetchPendingReportIdById.
@Override
public ReportEntity fetchPendingReportIdById(int reportId) {
final String sortOrder = INCIDENT_DATE + " DESC";
final String[] selectionArgs = { String.valueOf(reportId), String.valueOf(1) };
final String selection = ID + " =? AND " + INCIDENT_PENDING + " =? ";
ReportEntity report = new ReportEntity();
cursor = super.query(INCIDENTS_TABLE, null, selection, selectionArgs, sortOrder);
if (cursor != null) {
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
report = cursorToEntity(cursor);
cursor.moveToNext();
}
cursor.close();
}
return report;
}
use of com.ushahidi.android.app.entities.ReportEntity in project Ushahidi_Android by ushahidi.
the class ReportDao method fetchPendingReportIdByDate.
@Override
public int fetchPendingReportIdByDate(String date) {
final String sortOrder = ID + " DESC";
final String[] selectionArgs = { date, String.valueOf(1) };
final String selection = INCIDENT_DATE + " =? AND " + INCIDENT_PENDING + " =? ";
int id = 0;
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);
id = report.getDbId();
cursor.moveToNext();
}
cursor.close();
}
return id;
}
use of com.ushahidi.android.app.entities.ReportEntity in project Ushahidi_Android by ushahidi.
the class ReportDao method fetchReportById.
@Override
public List<ReportEntity> fetchReportById(long id) {
final String sortOrder = INCIDENT_TITLE;
final String[] selectionArgs = { String.valueOf(id) };
final String selection = INCIDENT_ID + " = ?";
listReport = new ArrayList<ReportEntity>();
cursor = super.query(INCIDENTS_TABLE, INCIDENTS_COLUMNS, 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 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;
}
Aggregations