Search in sources :

Example 1 with Incident

use of com.ushahidi.java.sdk.api.Incident 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)

Example 2 with Incident

use of com.ushahidi.java.sdk.api.Incident in project Ushahidi_Android by ushahidi.

the class AddReportActivity method addReport.

/**
	 * Post to local database
	 * 
	 * @author henryaddo
	 */
private boolean addReport() {
    log("Adding new reports");
    File[] pendingPhotos = PhotoUtils.getPendingPhotos(this);
    ReportEntity report = new ReportEntity();
    Incident incident = new Incident();
    incident.setTitle(view.mIncidentTitle.getText().toString());
    incident.setDescription(view.mIncidentDesc.getText().toString());
    incident.setMode(0);
    incident.setLocationName(view.mIncidentLocation.getText().toString());
    incident.setVerified(0);
    incident.setLatitude(Double.valueOf(view.mLatitude.getText().toString()));
    incident.setLongitude(Double.valueOf(view.mLongitude.getText().toString()));
    if (date != null) {
        incident.setDate(date);
    } else {
        incident.setDate(new Date());
    }
    report.setIncident(incident);
    report.setPending(1);
    if (id == 0) {
        // Add a new pending report
        if (model.addPendingReport(report, mVectorCategories, pendingPhotos, view.mNews.getText().toString())) {
            // move saved photos
            log("Moving photos to fetched folder");
            ImageManager.movePendingPhotos(this);
            id = report.getDbId();
        } else {
            return false;
        }
    } else {
        // Update existing report
        List<PhotoEntity> photos = new ArrayList<PhotoEntity>();
        for (int i = 0; i < pendingPhoto.getCount(); i++) {
            photos.add(pendingPhoto.getItem(i));
        }
        if (model.updatePendingReport(id, report, mVectorCategories, photos, view.mNews.getText().toString())) {
            // move saved photos
            log("Moving photos to fetched folder");
            ImageManager.movePendingPhotos(this);
        } else {
            return false;
        }
    }
    if (mSendOpenGeoSms) {
        mOgsDao.addReport(id);
    } else {
        mOgsDao.deleteReport(id);
    }
    return true;
}
Also used : ArrayList(java.util.ArrayList) Incident(com.ushahidi.java.sdk.api.Incident) File(java.io.File) ReportEntity(com.ushahidi.android.app.entities.ReportEntity) PhotoEntity(com.ushahidi.android.app.entities.PhotoEntity) Date(java.util.Date)

Example 3 with Incident

use of com.ushahidi.java.sdk.api.Incident in project Ushahidi_Android by ushahidi.

the class ListReportFragment method uploadPendingReports.

private boolean uploadPendingReports() {
    boolean retVal = true;
    ReportFields fields = new ReportFields();
    Incident incident = new Incident();
    ReportsApi reportApi = new ReportsApi();
    if (mPendingReports != null) {
        for (ReportEntity report : mPendingReports) {
            long rid = report.getDbId();
            ;
            int state = Database.mOpenGeoSmsDao.getReportState(rid);
            if (state != IOpenGeoSmsSchema.STATE_NOT_OPENGEOSMS) {
                if (!sendOpenGeoSmsReport(report, state)) {
                    retVal = false;
                }
                continue;
            }
            // Set the incident details
            incident.setTitle(report.getIncident().getTitle());
            incident.setDescription(report.getIncident().getDescription());
            incident.setDate(report.getIncident().getDate());
            incident.setLatitude(report.getIncident().getLatitude());
            incident.setLongitude(report.getIncident().getLongitude());
            incident.setLocationName(report.getIncident().getLocationName());
            fields.fill(incident);
            // Set person details
            if ((!TextUtils.isEmpty(Preferences.fileName)) && (!TextUtils.isEmpty(Preferences.lastname)) && (!TextUtils.isEmpty(Preferences.email))) {
                fields.setPerson(new Person(Preferences.firstname, Preferences.lastname, Preferences.email));
            }
            // Add categories
            fields.addCategory(report.getCategories());
            // Add photos
            List<File> photos = new UploadPhotoAdapter(getActivity()).pendingPhotos((int) report.getDbId());
            if (photos != null && photos.size() > 0)
                fields.addPhotos(photos);
            // Upload
            Response response = reportApi.submitReport(fields);
            if (response != null) {
                if (response.getErrorCode() == 0) {
                    deletePendingReport((int) report.getDbId());
                } else {
                    retVal = false;
                }
            } else {
                deletePendingReport((int) report.getDbId());
            }
        }
    }
    return retVal;
}
Also used : Response(com.ushahidi.java.sdk.api.json.Response) ReportsApi(com.ushahidi.android.app.api.ReportsApi) UploadPhotoAdapter(com.ushahidi.android.app.adapters.UploadPhotoAdapter) Incident(com.ushahidi.java.sdk.api.Incident) ReportEntity(com.ushahidi.android.app.entities.ReportEntity) Person(com.ushahidi.java.sdk.api.Person) File(java.io.File) ReportFields(com.ushahidi.java.sdk.api.ReportFields)

Aggregations

ReportEntity (com.ushahidi.android.app.entities.ReportEntity)3 Incident (com.ushahidi.java.sdk.api.Incident)3 File (java.io.File)2 UploadPhotoAdapter (com.ushahidi.android.app.adapters.UploadPhotoAdapter)1 ReportsApi (com.ushahidi.android.app.api.ReportsApi)1 PhotoEntity (com.ushahidi.android.app.entities.PhotoEntity)1 Person (com.ushahidi.java.sdk.api.Person)1 ReportFields (com.ushahidi.java.sdk.api.ReportFields)1 Response (com.ushahidi.java.sdk.api.json.Response)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1