Search in sources :

Example 6 with ReportEntity

use of com.ushahidi.android.app.entities.ReportEntity in project Ushahidi_Android by ushahidi.

the class ReportDao method fetchPendingReportByCategoryId.

@Override
public List<ReportEntity> fetchPendingReportByCategoryId(int categoryId) {
    final String sortOrder = INCIDENT_TITLE + " DESC";
    final String sql = "SELECT reports.* FROM " + INCIDENTS_TABLE + " reports INNER JOIN " + IReportCategorySchema.TABLE + " cats ON reports." + ID + " = cats." + IReportCategorySchema.REPORT_ID + " WHERE cats." + IReportCategorySchema.CATEGORY_ID + " =? AND " + "cats." + IReportCategorySchema.STATUS + " =?  AND cats." + INCIDENT_PENDING + "=? ORDER BY  " + sortOrder;
    final String[] selectionArgs = { String.valueOf(categoryId), String.valueOf(IReportSchema.PENDING), String.valueOf(IReportSchema.PENDING) };
    listReport = new ArrayList<ReportEntity>();
    cursor = super.rawQuery(sql, selectionArgs);
    if (cursor != null) {
        cursor.moveToFirst();
        while (!cursor.isAfterLast()) {
            ReportEntity report = cursorToEntity(cursor);
            listReport.add(report);
            cursor.moveToNext();
        }
        cursor.close();
    }
    return listReport;
}
Also used : ReportEntity(com.ushahidi.android.app.entities.ReportEntity)

Example 7 with ReportEntity

use of com.ushahidi.android.app.entities.ReportEntity in project Ushahidi_Android by ushahidi.

the class ReportDao method fetchAllPendingReports.

@Override
public List<ReportEntity> fetchAllPendingReports() {
    final String sortOrder = INCIDENT_DATE + " DESC";
    final String selection = INCIDENT_PENDING + " =?";
    final String[] selectionArgs = { String.valueOf(1) };
    listReport = new ArrayList<ReportEntity>();
    cursor = super.query(INCIDENTS_TABLE, null, selection, selectionArgs, sortOrder);
    if (cursor != null) {
        cursor.moveToFirst();
        while (!cursor.isAfterLast()) {
            ReportEntity report = cursorToEntity(cursor);
            listReport.add(report);
            cursor.moveToNext();
        }
        cursor.close();
    }
    return listReport;
}
Also used : ReportEntity(com.ushahidi.android.app.entities.ReportEntity)

Example 8 with ReportEntity

use of com.ushahidi.android.app.entities.ReportEntity in project Ushahidi_Android by ushahidi.

the class AddReportActivity method setSavedReport.

/**
	 * Edit existing report
	 * 
	 * @author henryaddo
	 */
private void setSavedReport(int reportId) {
    // set text part of reports
    ReportEntity report = model.fetchPendingReportById(reportId);
    if (report != null) {
        view.mIncidentTitle.setText(report.getIncident().getTitle());
        view.mIncidentDesc.setText(report.getIncident().getDescription());
        view.mLongitude.setText(String.valueOf(report.getIncident().getLongitude()));
        view.mLatitude.setText(String.valueOf(report.getIncident().getLatitude()));
        view.mIncidentLocation.setText(report.getIncident().getLocationName());
        // set date and time
        setDateAndTime(report.getIncident().getDate());
    }
    // set Categories.
    mVectorCategories.clear();
    for (ReportCategory reportCategory : model.fetchReportCategories(reportId, IReportSchema.PENDING)) {
        mVectorCategories.add(reportCategory.getCategoryId());
    }
    setSelectedCategories(mVectorCategories);
    // set the photos
    pendingPhoto.refresh(id);
    // set news
    List<MediaEntity> newsMedia = model.fetchReportNews(reportId);
    if (newsMedia != null && newsMedia.size() > 0) {
        view.mNews.setText(newsMedia.get(0).getLink());
    }
    mIsReportEditable = mOgsDao.getReportState(id) != IOpenGeoSmsSchema.STATE_SENT;
    if (!mIsReportEditable) {
        View[] views = new View[] { view.mBtnAddCategory, view.mIncidentDesc, view.mIncidentLocation, view.mIncidentTitle, view.mLatitude, view.mLongitude, view.mPickDate, view.mPickTime };
        for (View v : views) {
            v.setEnabled(false);
        }
        updateMarker(report.getIncident().getLatitude(), report.getIncident().getLongitude(), true);
    }
}
Also used : ReportCategory(com.ushahidi.android.app.entities.ReportCategory) ReportEntity(com.ushahidi.android.app.entities.ReportEntity) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) AddReportView(com.ushahidi.android.app.views.AddReportView) MediaEntity(com.ushahidi.android.app.entities.MediaEntity)

Example 9 with ReportEntity

use of com.ushahidi.android.app.entities.ReportEntity in project Ushahidi_Android by ushahidi.

the class AddReportActivity method addReport.

/**
	 * Post to local database
	 * 
	 * @author henryaddo
	 */
private boolean addReport() {
    log("Adding new reports");
    File[] pendingPhotos = PhotoUtils.getPendingPhotos(this);
    ReportEntity report = new ReportEntity();
    Incident incident = new Incident();
    incident.setTitle(view.mIncidentTitle.getText().toString());
    incident.setDescription(view.mIncidentDesc.getText().toString());
    incident.setMode(0);
    incident.setLocationName(view.mIncidentLocation.getText().toString());
    incident.setVerified(0);
    incident.setLatitude(Double.valueOf(view.mLatitude.getText().toString()));
    incident.setLongitude(Double.valueOf(view.mLongitude.getText().toString()));
    if (date != null) {
        incident.setDate(date);
    } else {
        incident.setDate(new Date());
    }
    report.setIncident(incident);
    report.setPending(1);
    if (id == 0) {
        // Add a new pending report
        if (model.addPendingReport(report, mVectorCategories, pendingPhotos, view.mNews.getText().toString())) {
            // move saved photos
            log("Moving photos to fetched folder");
            ImageManager.movePendingPhotos(this);
            id = report.getDbId();
        } else {
            return false;
        }
    } else {
        // Update existing report
        List<PhotoEntity> photos = new ArrayList<PhotoEntity>();
        for (int i = 0; i < pendingPhoto.getCount(); i++) {
            photos.add(pendingPhoto.getItem(i));
        }
        if (model.updatePendingReport(id, report, mVectorCategories, photos, view.mNews.getText().toString())) {
            // move saved photos
            log("Moving photos to fetched folder");
            ImageManager.movePendingPhotos(this);
        } else {
            return false;
        }
    }
    if (mSendOpenGeoSms) {
        mOgsDao.addReport(id);
    } else {
        mOgsDao.deleteReport(id);
    }
    return true;
}
Also used : ArrayList(java.util.ArrayList) Incident(com.ushahidi.java.sdk.api.Incident) File(java.io.File) ReportEntity(com.ushahidi.android.app.entities.ReportEntity) PhotoEntity(com.ushahidi.android.app.entities.PhotoEntity) Date(java.util.Date)

Example 10 with ReportEntity

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

Aggregations

ReportEntity (com.ushahidi.android.app.entities.ReportEntity)18 Incident (com.ushahidi.java.sdk.api.Incident)3 ReportCategory (com.ushahidi.android.app.entities.ReportCategory)2 File (java.io.File)2 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 ImageView (android.widget.ImageView)1 ListView (android.widget.ListView)1 LatLng (com.google.android.gms.maps.model.LatLng)1 LatLngBounds (com.google.android.gms.maps.model.LatLngBounds)1 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 UploadPhotoAdapter (com.ushahidi.android.app.adapters.UploadPhotoAdapter)1 ReportsApi (com.ushahidi.android.app.api.ReportsApi)1 MediaEntity (com.ushahidi.android.app.entities.MediaEntity)1 PhotoEntity (com.ushahidi.android.app.entities.PhotoEntity)1 AddReportView (com.ushahidi.android.app.views.AddReportView)1 UshahidiException (com.ushahidi.java.sdk.UshahidiException)1 Category (com.ushahidi.java.sdk.api.Category)1 Incidents (com.ushahidi.java.sdk.api.Incidents)1 Person (com.ushahidi.java.sdk.api.Person)1