use of com.ushahidi.java.sdk.api.Category 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.java.sdk.api.Category in project Ushahidi_Android by ushahidi.
the class ListPendingReportAdapter method fetchCategoriesId.
public List<Category> fetchCategoriesId(int reportId) {
List<Category> categories = new ArrayList<Category>();
Category c = new Category();
for (CategoryEntity category : mListReportModel.getCategoriesByReportId(reportId)) {
c.setId(category.getCategoryId());
categories.add(c);
}
return categories;
}
use of com.ushahidi.java.sdk.api.Category in project Ushahidi_Android by ushahidi.
the class CategoriesApi method getCategoriesList.
/**
* Fetch categories using the Ushahidi API
*
* @return boolean Successful return true otherwise return false
*/
public boolean getCategoriesList() {
new Util().log("Save categories list");
if (processingResult) {
try {
List<Category> cats = task.all();
if (cats != null) {
for (com.ushahidi.java.sdk.api.Category cat : cats) {
CategoryEntity category = new CategoryEntity();
category.addCategory(cat);
categories.add(category);
}
return saveCategories(categories);
}
} catch (UshahidiException e) {
log("UshahidiException", e);
processingResult = false;
} catch (JsonSyntaxException e) {
log("JSONSyntaxException", e);
}
}
return false;
}
Aggregations