use of com.ushahidi.android.app.entities.MediaEntity in project Ushahidi_Android by ushahidi.
the class ReportsApi method saveMedia.
/**
* Save fetched media to the database
*
* @param mediaId The ID of the media
* @param reportId The report ID associated with the media
* @param type The media type. 1 for image, 2 for news link, 3 for video
* link
* @param link The URL of the media
* @return void
*/
private void saveMedia(int mediaId, int reportId, int type, String link) {
log("downloading... " + link + " ReportId: " + reportId);
MediaEntity media = new MediaEntity();
media.setMediaId(mediaId);
media.setReportId(reportId);
media.setType(type);
media.setLink(link);
List<MediaEntity> sMedia = new ArrayList<MediaEntity>();
sMedia.add(media);
// save new data
Database.mMediaDao.addMedia(sMedia);
}
use of com.ushahidi.android.app.entities.MediaEntity 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;
}
use of com.ushahidi.android.app.entities.MediaEntity in project Ushahidi_Android by ushahidi.
the class AddCheckinModel method addPendingCheckin.
public boolean addPendingCheckin(Checkin checkin, File[] pendingPhotos) {
boolean status;
// add pending reports
status = Database.mCheckin.addCheckin(checkin);
// int id = Database.mCheckin.
int id = Database.mCheckin.fetchPendingCheckinIdByDate(checkin.getDate());
// add photos
if (pendingPhotos != null && pendingPhotos.length > 0) {
for (File file : pendingPhotos) {
if (file.exists()) {
MediaEntity media = new MediaEntity();
media.setMediaId(0);
media.setLink(file.getName());
// get report ID;
media.setCheckinId(id);
media.setType(IMediaSchema.IMAGE);
Database.mMediaDao.addMedia(media);
}
}
}
return status;
}
use of com.ushahidi.android.app.entities.MediaEntity in project Ushahidi_Android by ushahidi.
the class ListReportNewsModel method getNewsByReportId.
public List<ListReportNewsModel> getNewsByReportId(int reportId) {
mNewsModel = new ArrayList<ListReportNewsModel>();
mMedia = Database.mMediaDao.fetchReportNews(reportId);
if (mMedia != null && mMedia.size() > 0) {
for (MediaEntity item : mMedia) {
ListReportNewsModel newsModel = new ListReportNewsModel();
newsModel.setId(item.getDbId());
newsModel.setTitle(item.getLink());
newsModel.setUrl(item.getLink());
mNewsModel.add(newsModel);
}
}
return mNewsModel;
}
use of com.ushahidi.android.app.entities.MediaEntity in project Ushahidi_Android by ushahidi.
the class MediaDao method fetchReportNews.
@Override
public List<MediaEntity> fetchReportNews(int reportId) {
listMedia = new ArrayList<MediaEntity>();
final String selection = REPORT_ID + " = " + reportId + " AND " + TYPE + " =" + NEWS;
cursor = super.query(TABLE, MEDIA_COLUMNS, selection, null, null);
if (cursor != null) {
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
MediaEntity media = cursorToEntity(cursor);
listMedia.add(media);
cursor.moveToNext();
}
cursor.close();
}
return listMedia;
}
Aggregations