Search in sources :

Example 1 with OpenGeoSmsDao

use of com.ushahidi.android.app.database.OpenGeoSmsDao 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

UploadPhotoAdapter (com.ushahidi.android.app.adapters.UploadPhotoAdapter)1 ReportsApi (com.ushahidi.android.app.api.ReportsApi)1 OpenGeoSmsDao (com.ushahidi.android.app.database.OpenGeoSmsDao)1 Body (com.ushahidi.java.sdk.net.content.Body)1 FileBody (com.ushahidi.java.sdk.net.content.FileBody)1 File (java.io.File)1