Search in sources :

Example 1 with Incidents

use of com.ushahidi.java.sdk.api.Incidents 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;
}
Also used : Category(com.ushahidi.java.sdk.api.Category) ReportCategory(com.ushahidi.android.app.entities.ReportCategory) JsonSyntaxException(com.google.gson.JsonSyntaxException) Incidents(com.ushahidi.java.sdk.api.Incidents) UshahidiException(com.ushahidi.java.sdk.UshahidiException) ReportEntity(com.ushahidi.android.app.entities.ReportEntity)

Aggregations

JsonSyntaxException (com.google.gson.JsonSyntaxException)1 ReportCategory (com.ushahidi.android.app.entities.ReportCategory)1 ReportEntity (com.ushahidi.android.app.entities.ReportEntity)1 UshahidiException (com.ushahidi.java.sdk.UshahidiException)1 Category (com.ushahidi.java.sdk.api.Category)1 Incidents (com.ushahidi.java.sdk.api.Incidents)1