Search in sources :

Example 1 with ReportEntity

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

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;
}
Also used : ReportEntity(com.ushahidi.android.app.entities.ReportEntity)

Example 3 with ReportEntity

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;
}
Also used : ReportEntity(com.ushahidi.android.app.entities.ReportEntity)

Example 4 with ReportEntity

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;
}
Also used : ReportEntity(com.ushahidi.android.app.entities.ReportEntity)

Example 5 with ReportEntity

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

Aggregations

ReportEntity (com.ushahidi.android.app.entities.ReportEntity)18 Incident (com.ushahidi.java.sdk.api.Incident)3 ReportCategory (com.ushahidi.android.app.entities.ReportCategory)2 File (java.io.File)2 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 ImageView (android.widget.ImageView)1 ListView (android.widget.ListView)1 LatLng (com.google.android.gms.maps.model.LatLng)1 LatLngBounds (com.google.android.gms.maps.model.LatLngBounds)1 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 UploadPhotoAdapter (com.ushahidi.android.app.adapters.UploadPhotoAdapter)1 ReportsApi (com.ushahidi.android.app.api.ReportsApi)1 MediaEntity (com.ushahidi.android.app.entities.MediaEntity)1 PhotoEntity (com.ushahidi.android.app.entities.PhotoEntity)1 AddReportView (com.ushahidi.android.app.views.AddReportView)1 UshahidiException (com.ushahidi.java.sdk.UshahidiException)1 Category (com.ushahidi.java.sdk.api.Category)1 Incidents (com.ushahidi.java.sdk.api.Incidents)1 Person (com.ushahidi.java.sdk.api.Person)1