Search in sources :

Example 1 with Category

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;
}
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)

Example 2 with Category

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;
}
Also used : Category(com.ushahidi.java.sdk.api.Category) ArrayList(java.util.ArrayList) CategoryEntity(com.ushahidi.android.app.entities.CategoryEntity)

Example 3 with Category

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;
}
Also used : Category(com.ushahidi.java.sdk.api.Category) JsonSyntaxException(com.google.gson.JsonSyntaxException) Util(com.ushahidi.android.app.util.Util) UshahidiException(com.ushahidi.java.sdk.UshahidiException) Category(com.ushahidi.java.sdk.api.Category) CategoryEntity(com.ushahidi.android.app.entities.CategoryEntity)

Aggregations

Category (com.ushahidi.java.sdk.api.Category)3 JsonSyntaxException (com.google.gson.JsonSyntaxException)2 CategoryEntity (com.ushahidi.android.app.entities.CategoryEntity)2 UshahidiException (com.ushahidi.java.sdk.UshahidiException)2 ReportCategory (com.ushahidi.android.app.entities.ReportCategory)1 ReportEntity (com.ushahidi.android.app.entities.ReportEntity)1 Util (com.ushahidi.android.app.util.Util)1 Incidents (com.ushahidi.java.sdk.api.Incidents)1 ArrayList (java.util.ArrayList)1