Search in sources :

Example 1 with ReportsApi

use of com.ushahidi.android.app.api.ReportsApi 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)

Example 2 with ReportsApi

use of com.ushahidi.android.app.api.ReportsApi in project Ushahidi_Android by ushahidi.

the class FetchReports method executeTask.

@Override
protected void executeTask(Intent intent) {
    new Util().log("executeTask() executing this task");
    clearCachedData();
    ApiUtils.updateDomain(this);
    // fetch categories
    new CategoriesApi().getCategoriesList();
    // fetch reports
    status = new ReportsApi().saveReports(this) ? 0 : 99;
    statusIntent.putExtra("status", status);
    sendBroadcast(statusIntent);
}
Also used : ReportsApi(com.ushahidi.android.app.api.ReportsApi) CategoriesApi(com.ushahidi.android.app.api.CategoriesApi) Util(com.ushahidi.android.app.util.Util)

Example 3 with ReportsApi

use of com.ushahidi.android.app.api.ReportsApi in project Ushahidi_Android by ushahidi.

the class ListReportFragment method sendOpenGeoSmsReport.

private boolean sendOpenGeoSmsReport(ReportEntity r, int state) {
    long id = r.getDbId();
    OpenGeoSmsDao dao = Database.mOpenGeoSmsDao;
    switch(state) {
        case IOpenGeoSmsSchema.STATE_PENDING:
            if (sendOpenGeoSms(r)) {
                List<File> photos = new UploadPhotoAdapter(getActivity()).pendingPhotos((int) id);
                if ((photos != null) && (photos.size() > 0)) {
                    dao.setReportState(id, IOpenGeoSmsSchema.STATE_SENT);
                } else {
                    deletePendingReport((int) id);
                    dao.deleteReport(id);
                }
                return true;
            } else {
                return false;
            }
        case IOpenGeoSmsSchema.STATE_SENT:
            List<File> photos = new UploadPhotoAdapter(getActivity()).pendingPhotos((int) id);
            if ((photos != null) && (photos.size() > 0)) {
                String url = Preferences.domain + "opengeosms/attach";
                String m = OpenGeoSMSSender.createReport(Preferences.openGeoSmsUrl, r);
                Body body = new Body();
                body.addField("m", m);
                for (File file : photos) {
                    body.addField("filename", new FileBody(file));
                }
                ReportsApi report = new ReportsApi();
                if (!report.upload(url, body)) {
                    return false;
                }
            }
            deletePendingReport((int) id);
            dao.deleteReport(id);
            return true;
    }
    return false;
}
Also used : FileBody(com.ushahidi.java.sdk.net.content.FileBody) ReportsApi(com.ushahidi.android.app.api.ReportsApi) UploadPhotoAdapter(com.ushahidi.android.app.adapters.UploadPhotoAdapter) OpenGeoSmsDao(com.ushahidi.android.app.database.OpenGeoSmsDao) File(java.io.File) Body(com.ushahidi.java.sdk.net.content.Body) FileBody(com.ushahidi.java.sdk.net.content.FileBody)

Aggregations

ReportsApi (com.ushahidi.android.app.api.ReportsApi)3 UploadPhotoAdapter (com.ushahidi.android.app.adapters.UploadPhotoAdapter)2 File (java.io.File)2 CategoriesApi (com.ushahidi.android.app.api.CategoriesApi)1 OpenGeoSmsDao (com.ushahidi.android.app.database.OpenGeoSmsDao)1 ReportEntity (com.ushahidi.android.app.entities.ReportEntity)1 Util (com.ushahidi.android.app.util.Util)1 Incident (com.ushahidi.java.sdk.api.Incident)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 Body (com.ushahidi.java.sdk.net.content.Body)1 FileBody (com.ushahidi.java.sdk.net.content.FileBody)1