use of org.wordpress.android.fluxc.model.MediaModel in project WordPress-Android by wordpress-mobile.
the class MediaBrowserActivity method onRetryUpload.
@Override
public void onRetryUpload(int localMediaId) {
MediaModel media = mMediaStore.getMediaWithLocalId(localMediaId);
if (media == null) {
return;
}
addMediaToUploadService(media);
}
use of org.wordpress.android.fluxc.model.MediaModel in project WordPress-Android by wordpress-mobile.
the class MediaBrowserActivity method queueFileForUpload.
private void queueFileForUpload(Uri uri, String mimeType) {
// It is a regular local media file
String path = getRealPathFromURI(uri);
if (path == null || path.equals("")) {
Toast.makeText(this, "Error opening file", Toast.LENGTH_SHORT).show();
return;
}
File file = new File(path);
if (!file.exists()) {
return;
}
MediaModel media = mMediaStore.instantiateMediaModel();
String filename = org.wordpress.android.fluxc.utils.MediaUtils.getFileName(path);
String fileExtension = org.wordpress.android.fluxc.utils.MediaUtils.getExtension(path);
// Try to get mime type if none was passed to this method
if (mimeType == null) {
mimeType = getContentResolver().getType(uri);
if (mimeType == null) {
mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(fileExtension);
}
if (mimeType == null) {
// Default to image jpeg
mimeType = "image/jpeg";
}
}
// If file extension is null, upload won't work on wordpress.com
if (fileExtension == null) {
fileExtension = MimeTypeMap.getSingleton().getExtensionFromMimeType(mimeType);
filename += "." + fileExtension;
}
media.setFileName(filename);
media.setFilePath(path);
media.setLocalSiteId(mSite.getId());
media.setFileExtension(fileExtension);
media.setMimeType(mimeType);
media.setUploadState(MediaUploadState.QUEUED.name());
media.setUploadDate(DateTimeUtils.iso8601UTCFromTimestamp(System.currentTimeMillis() / 1000));
mDispatcher.dispatch(MediaActionBuilder.newUpdateMediaAction(media));
addMediaToUploadService(media);
}
use of org.wordpress.android.fluxc.model.MediaModel in project WordPress-Android by wordpress-mobile.
the class MediaBrowserActivity method deleteMedia.
public void deleteMedia(final ArrayList<Integer> ids) {
Set<String> sanitizedIds = new HashSet<>(ids.size());
// phone layout: pop the item fragment if it's visible
doPopBackStack(getFragmentManager());
final ArrayList<MediaModel> mediaToDelete = new ArrayList<>();
// Make sure there are no media in "uploading"
for (int currentId : ids) {
MediaModel mediaModel = mMediaStore.getMediaWithLocalId(currentId);
if (mediaModel == null) {
continue;
}
if (WordPressMediaUtils.canDeleteMedia(mediaModel)) {
if (MediaUtils.isLocalFile(mediaModel.getUploadState().toLowerCase())) {
mDispatcher.dispatch(MediaActionBuilder.newRemoveMediaAction(mediaModel));
updateViews();
sanitizedIds.add(String.valueOf(currentId));
continue;
}
mediaToDelete.add(mediaModel);
mediaModel.setUploadState(MediaUploadState.DELETE.name());
mDispatcher.dispatch(MediaActionBuilder.newUpdateMediaAction(mediaModel));
updateViews();
sanitizedIds.add(String.valueOf(currentId));
}
}
if (sanitizedIds.size() != ids.size()) {
if (ids.size() == 1) {
Toast.makeText(this, R.string.wait_until_upload_completes, Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, R.string.cannot_delete_multi_media_items, Toast.LENGTH_LONG).show();
}
}
// and then refresh the grid
if (!mediaToDelete.isEmpty()) {
startMediaDeleteService(mediaToDelete);
}
if (mMediaGridFragment != null) {
mMediaGridFragment.clearSelectedItems();
updateViews();
}
}
use of org.wordpress.android.fluxc.model.MediaModel in project WordPress-Android by wordpress-mobile.
the class MediaBrowserActivity method onMediaChanged.
@SuppressWarnings("unused")
@Subscribe(threadMode = ThreadMode.MAIN)
public void onMediaChanged(OnMediaChanged event) {
if (event.isError()) {
AppLog.w(AppLog.T.MEDIA, "Received onMediaChanged error: " + event.error.type + " - " + event.error.message);
showMediaToastError(R.string.media_generic_error, event.error.message);
return;
}
switch(event.cause) {
case DELETE_MEDIA:
if (event.mediaList == null || event.mediaList.isEmpty()) {
break;
}
// detail view (if it was the one displayed)
for (MediaModel mediaModel : event.mediaList) {
int localMediaId = mediaModel.getId();
mMediaGridFragment.removeFromMultiSelect(localMediaId);
if (mMediaEditFragment != null && mMediaEditFragment.isVisible() && localMediaId == mMediaEditFragment.getLocalMediaId()) {
updateOnMediaChanged(localMediaId);
if (mMediaEditFragment.isInLayout()) {
mMediaEditFragment.loadMedia(MediaEditFragment.MISSING_MEDIA_ID);
} else {
getFragmentManager().popBackStack();
}
}
}
break;
}
updateViews();
}
use of org.wordpress.android.fluxc.model.MediaModel in project WordPress-Android by wordpress-mobile.
the class MediaItemFragment method loadMedia.
public void loadMedia(int localMediaId) {
if (mSite == null)
return;
MediaModel mediaModel = null;
if (localMediaId != MISSING_MEDIA_ID) {
mediaModel = mMediaStore.getMediaWithLocalId(localMediaId);
}
// if the id is null, get the first media item in the database
if (mediaModel == null) {
List<MediaModel> list = mMediaStore.getAllSiteMedia(mSite);
if (list != null && list.size() > 0) {
mediaModel = list.get(0);
}
}
refreshViews(mediaModel);
}
Aggregations