Search in sources :

Example 1 with PhotoEntity

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

the class AddCheckinModel method updatePendingCheckin.

public boolean updatePendingCheckin(int checkinId, Checkin checkin, List<PhotoEntity> pendingPhotos) {
    boolean status;
    // update pending reports
    status = Database.mCheckin.updatePendingCheckin(checkinId, checkin);
    // update photos
    if (pendingPhotos != null && pendingPhotos.size() > 0) {
        // delete existing photo
        Database.mMediaDao.deleteReportPhoto(checkinId);
        for (PhotoEntity photo : pendingPhotos) {
            MediaEntity media = new MediaEntity();
            media.setMediaId(0);
            // FIXME:: this is nasty.
            String[] sections = photo.getPhoto().split("/");
            media.setLink(sections[1]);
            // get report ID
            media.setCheckinId(checkinId);
            media.setType(IMediaSchema.IMAGE);
            Database.mMediaDao.addMedia(media);
        }
    }
    return status;
}
Also used : PhotoEntity(com.ushahidi.android.app.entities.PhotoEntity) MediaEntity(com.ushahidi.android.app.entities.MediaEntity)

Example 2 with PhotoEntity

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

the class ListPhotoModel method getPendingPhotos.

public List<PhotoEntity> getPendingPhotos(Context context) {
    mPhotoModel = new ArrayList<PhotoEntity>();
    File[] pendingPhotos = PhotoUtils.getPendingPhotos(context);
    if (pendingPhotos != null && pendingPhotos.length > 0) {
        int id = 0;
        for (File file : pendingPhotos) {
            if (file.exists()) {
                id += 1;
                PhotoEntity photo = new PhotoEntity();
                photo.setDbId(id);
                photo.setPhoto(PENDING + file.getName());
                mPhotoModel.add(photo);
            }
        }
    }
    return mPhotoModel;
}
Also used : PhotoEntity(com.ushahidi.android.app.entities.PhotoEntity) File(java.io.File)

Example 3 with PhotoEntity

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

the class AddReportActivity method addPhotoToReport.

/**
	 * Set photo to be attached to an existing report
	 */
private void addPhotoToReport() {
    File[] pendingPhotos = PhotoUtils.getPendingPhotos(this);
    if (pendingPhotos != null && pendingPhotos.length > 0) {
        int id = 0;
        for (File file : pendingPhotos) {
            if (file.exists()) {
                id += 1;
                PhotoEntity photo = new PhotoEntity();
                photo.setDbId(id);
                photo.setPhoto(file.getName());
                pendingPhoto.addItem(photo);
            }
        }
    }
}
Also used : File(java.io.File) PhotoEntity(com.ushahidi.android.app.entities.PhotoEntity)

Example 4 with PhotoEntity

use of com.ushahidi.android.app.entities.PhotoEntity 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 5 with PhotoEntity

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

the class ViewReportView method setListPhotos.

public void setListPhotos(int reportId) {
    if (photo != null) {
        ListPhotoModel mListPhotoModel = new ListPhotoModel();
        final boolean loaded = mListPhotoModel.load(reportId);
        int totalPhotos = mListPhotoModel.totalReportPhoto();
        if (loaded) {
            final List<PhotoEntity> items = mListPhotoModel.getPhotos();
            if (items.size() > 0) {
                getPhoto(items.get(0).getPhoto(), photo);
                total.setText(context.getResources().getQuantityString(R.plurals.no_of_images, totalPhotos, totalPhotos));
            } else {
                photo.setVisibility(View.GONE);
                total.setVisibility(View.GONE);
                listPhotosEmptyView.setVisibility(View.VISIBLE);
            }
        }
    }
}
Also used : ListPhotoModel(com.ushahidi.android.app.models.ListPhotoModel) PhotoEntity(com.ushahidi.android.app.entities.PhotoEntity)

Aggregations

PhotoEntity (com.ushahidi.android.app.entities.PhotoEntity)11 MediaEntity (com.ushahidi.android.app.entities.MediaEntity)6 File (java.io.File)3 ReportCategory (com.ushahidi.android.app.entities.ReportCategory)1 ReportEntity (com.ushahidi.android.app.entities.ReportEntity)1 ListPhotoModel (com.ushahidi.android.app.models.ListPhotoModel)1 Incident (com.ushahidi.java.sdk.api.Incident)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1