use of com.ushahidi.android.app.adapters.UploadPhotoAdapter in project Ushahidi_Android by ushahidi.
the class ListReportFragment method deletePendingReport.
private void deletePendingReport(int reportId) {
// make sure it's an existing report
AddReportModel model = new AddReportModel();
UploadPhotoAdapter pendingPhoto = new UploadPhotoAdapter(getActivity());
if (reportId > 0) {
if (model.deleteReport(reportId)) {
// delete images
for (int i = 0; i < pendingPhoto.getCount(); i++) {
ImageManager.deletePendingPhoto(getActivity(), "/" + pendingPhoto.getItem(i).getPhoto());
}
}
}
}
use of com.ushahidi.android.app.adapters.UploadPhotoAdapter 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;
}
use of com.ushahidi.android.app.adapters.UploadPhotoAdapter 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;
}
use of com.ushahidi.android.app.adapters.UploadPhotoAdapter in project Ushahidi_Android by ushahidi.
the class AddReportActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
view.mLatitude.addTextChangedListener(latLonTextWatcher);
view.mLongitude.addTextChangedListener(latLonTextWatcher);
if (checkForGMap()) {
SupportMapFragment mapFrag = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.location_map);
view.map = mapFrag.getMap();
}
view.mBtnPicture.setOnClickListener(this);
view.mBtnAddCategory.setOnClickListener(this);
view.mPickDate.setOnClickListener(this);
view.mPickTime.setOnClickListener(this);
mCalendar = Calendar.getInstance();
pendingPhoto = new UploadPhotoAdapter(this);
view.gallery.setAdapter(pendingPhoto);
view.gallery.setOnItemClickListener(this);
view.mSwitcher.setFactory(this);
if (getIntent().getExtras() != null) {
this.id = getIntent().getExtras().getInt("id", 0);
}
mOgsDao = Database.mOpenGeoSmsDao;
// edit existing report
if (id > 0) {
// make the delete button visible because we're editing
view.mDeleteReport.setOnClickListener(this);
view.mDeleteReport.setVisibility(View.VISIBLE);
setSavedReport(id);
} else {
// add a new report
updateDisplay();
pendingPhoto.refresh();
}
registerForContextMenu(view.gallery);
createSendMethodDialog();
}
Aggregations