Search in sources :

Example 1 with UploadPhotoAdapter

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());
            }
        }
    }
}
Also used : UploadPhotoAdapter(com.ushahidi.android.app.adapters.UploadPhotoAdapter) AddReportModel(com.ushahidi.android.app.models.AddReportModel)

Example 2 with UploadPhotoAdapter

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;
}
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 3 with UploadPhotoAdapter

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;
}
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)

Example 4 with UploadPhotoAdapter

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();
}
Also used : SupportMapFragment(com.google.android.gms.maps.SupportMapFragment) UploadPhotoAdapter(com.ushahidi.android.app.adapters.UploadPhotoAdapter)

Aggregations

UploadPhotoAdapter (com.ushahidi.android.app.adapters.UploadPhotoAdapter)4 ReportsApi (com.ushahidi.android.app.api.ReportsApi)2 File (java.io.File)2 SupportMapFragment (com.google.android.gms.maps.SupportMapFragment)1 OpenGeoSmsDao (com.ushahidi.android.app.database.OpenGeoSmsDao)1 ReportEntity (com.ushahidi.android.app.entities.ReportEntity)1 AddReportModel (com.ushahidi.android.app.models.AddReportModel)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