use of com.ushahidi.java.sdk.net.content.FileBody 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;
}
Aggregations