Search in sources :

Example 16 with MediaModel

use of org.wordpress.android.fluxc.model.MediaModel in project WordPress-Android by wordpress-mobile.

the class MediaDeleteService method handleOnMediaChangedError.

private void handleOnMediaChangedError(@NonNull OnMediaChanged event) {
    MediaModel media = event.mediaList.get(0);
    switch(event.error.type) {
        case AUTHORIZATION_REQUIRED:
            AppLog.v(T.MEDIA, "Authorization required. Stopping MediaDeleteService.");
            // stop delete service until authorized to perform actions on site
            stopSelf();
            break;
        case NULL_MEDIA_ARG:
            // shouldn't happen, get back to deleting the queue
            AppLog.d(T.MEDIA, "Null media argument supplied, skipping current delete.");
            completeCurrentDelete();
            break;
        case NOT_FOUND:
            if (media == null) {
                break;
            }
            AppLog.d(T.MEDIA, "Could not find media (id=" + media.getMediaId() + "). on remote");
            // remove media from local database
            mDispatcher.dispatch(MediaActionBuilder.newRemoveMediaAction(mCurrentDelete));
            break;
        case PARSE_ERROR:
            AppLog.d(T.MEDIA, "Error parsing reponse to " + event.cause.toString() + ".");
            completeCurrentDelete();
            break;
        default:
            completeCurrentDelete();
            break;
    }
}
Also used : MediaModel(org.wordpress.android.fluxc.model.MediaModel)

Example 17 with MediaModel

use of org.wordpress.android.fluxc.model.MediaModel in project WordPress-Android by wordpress-mobile.

the class MediaGalleryPickerActivity method onAdapterItemSelected.

@Override
public void onAdapterItemSelected(int position) {
    if (mIsSelectOneItem) {
        // Single select, just finish the activity once an item is selected
        Intent intent = new Intent();
        int localId = mGridAdapter.getLocalMediaIdAtPosition(position);
        ArrayList<Long> remoteMediaIds = new ArrayList<>();
        MediaModel media = mMediaStore.getMediaWithLocalId(localId);
        if (media != null) {
            remoteMediaIds.add(media.getMediaId());
            intent.putExtra(RESULT_IDS, ListUtils.toLongArray(remoteMediaIds));
            setResult(RESULT_OK, intent);
            finish();
        }
    }
}
Also used : MediaModel(org.wordpress.android.fluxc.model.MediaModel) ArrayList(java.util.ArrayList) Intent(android.content.Intent)

Example 18 with MediaModel

use of org.wordpress.android.fluxc.model.MediaModel in project WordPress-Android by wordpress-mobile.

the class FluxCUtils method mediaModelFromMediaFile.

public static MediaModel mediaModelFromMediaFile(MediaFile file) {
    if (file == null) {
        return null;
    }
    MediaModel mediaModel = new MediaModel();
    mediaModel.setFileName(file.getFileName());
    mediaModel.setFilePath(file.getFilePath());
    mediaModel.setFileExtension(org.wordpress.android.fluxc.utils.MediaUtils.getExtension(file.getFilePath()));
    mediaModel.setMimeType(file.getMimeType());
    mediaModel.setThumbnailUrl(file.getThumbnailURL());
    mediaModel.setUrl(file.getFileURL());
    mediaModel.setTitle(file.getTitle());
    mediaModel.setDescription(file.getDescription());
    mediaModel.setCaption(file.getCaption());
    mediaModel.setMediaId(file.getMediaId() != null ? Long.valueOf(file.getMediaId()) : 0);
    mediaModel.setId(file.getId());
    mediaModel.setUploadState(file.getUploadState());
    mediaModel.setLocalSiteId(Integer.valueOf(file.getBlogId()));
    mediaModel.setVideoPressGuid(ShortcodeUtils.getVideoPressIdFromShortCode(file.getVideoPressShortCode()));
    return mediaModel;
}
Also used : MediaModel(org.wordpress.android.fluxc.model.MediaModel)

Example 19 with MediaModel

use of org.wordpress.android.fluxc.model.MediaModel in project WordPress-Android by wordpress-mobile.

the class EditPostActivity method addMediaVisualEditor.

private boolean addMediaVisualEditor(Uri uri, boolean isVideo) {
    String path;
    if (uri.toString().contains("content:")) {
        path = getPathFromContentUri(uri);
    } else {
        // File is not in media library
        path = uri.toString().replace("file://", "");
    }
    if (path == null) {
        ToastUtils.showToast(this, R.string.file_not_found, Duration.SHORT);
        return false;
    }
    boolean isOptimized = false;
    if (!NetworkUtils.isWiFiConnected(this) && !isVideo) {
        SiteSettingsInterface siteSettings = SiteSettingsInterface.getInterface(this, mSite, null);
        // Site Settings are implemented on .com/Jetpack sites only
        if (siteSettings != null && siteSettings.init(false).getOptimizedImage()) {
            // Not on WiFi and optimize image is set to ON
            // Max picture size will be 3000px wide. That's the maximum resolution you can set in the current picker.
            String optimizedPath = ImageUtils.optimizeImage(this, path, 3000, 85);
            if (optimizedPath == null) {
                AppLog.e(T.EDITOR, "Optimized picture was null!");
            // TODO: track analytics here
            // AnalyticsTracker.track(Stat.EDITOR_RESIZED_PHOTO_ERROR);
            } else {
                // TODO: track analytics here
                // AnalyticsTracker.track(Stat.EDITOR_RESIZED_PHOTO);
                Uri optimizedImageUri = Uri.parse(optimizedPath);
                if (optimizedImageUri != null) {
                    uri = optimizedImageUri;
                    isOptimized = true;
                }
            }
        }
    }
    MediaModel media = queueFileForUpload(uri, getContentResolver().getType(uri));
    MediaFile mediaFile = FluxCUtils.mediaFileFromMediaModel(media);
    trackAddMediaFromDeviceEvents(isVideo, isOptimized, null, path);
    if (media != null) {
        mEditorFragment.appendMediaFile(mediaFile, path, mImageLoader);
    }
    return true;
}
Also used : MediaFile(org.wordpress.android.util.helpers.MediaFile) MediaModel(org.wordpress.android.fluxc.model.MediaModel) SiteSettingsInterface(org.wordpress.android.ui.prefs.SiteSettingsInterface) Uri(android.net.Uri)

Example 20 with MediaModel

use of org.wordpress.android.fluxc.model.MediaModel in project WordPress-Android by wordpress-mobile.

the class EditPostActivity method buildMediaModel.

private MediaModel buildMediaModel(Uri uri, String mimeType, UploadState startingState) {
    String path = getRealPathFromURI(uri);
    MediaModel media = mMediaStore.instantiateMediaModel();
    AppLog.i(T.MEDIA, "New media instantiated localId=" + media.getId());
    String filename = org.wordpress.android.fluxc.utils.MediaUtils.getFileName(path);
    String fileExtension = org.wordpress.android.fluxc.utils.MediaUtils.getExtension(path);
    // Try to get mimetype 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;
    }
    if (org.wordpress.android.fluxc.utils.MediaUtils.isVideoMimeType(mimeType)) {
        media.setThumbnailUrl(getVideoThumbnail(path));
    }
    media.setFileName(filename);
    media.setFilePath(path);
    media.setLocalSiteId(mSite.getId());
    media.setFileExtension(fileExtension);
    media.setMimeType(mimeType);
    media.setUploadState(startingState.name());
    media.setUploadDate(DateTimeUtils.iso8601UTCFromTimestamp(System.currentTimeMillis() / 1000));
    return media;
}
Also used : MediaModel(org.wordpress.android.fluxc.model.MediaModel)

Aggregations

MediaModel (org.wordpress.android.fluxc.model.MediaModel)23 ArrayList (java.util.ArrayList)6 MediaFile (org.wordpress.android.util.helpers.MediaFile)5 Intent (android.content.Intent)3 SuppressLint (android.annotation.SuppressLint)2 AlertDialog (android.app.AlertDialog)2 Builder (android.app.AlertDialog.Builder)2 DialogInterface (android.content.DialogInterface)2 Uri (android.net.Uri)2 File (java.io.File)2 OnClickListener (android.content.DialogInterface.OnClickListener)1 Bitmap (android.graphics.Bitmap)1 Drawable (android.graphics.drawable.Drawable)1 AlignmentSpan (android.text.style.AlignmentSpan)1 ImageSpan (android.text.style.ImageSpan)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Subscribe (org.greenrobot.eventbus.Subscribe)1 MediaActionBuilder (org.wordpress.android.fluxc.generated.MediaActionBuilder)1 MediaPayload (org.wordpress.android.fluxc.store.MediaStore.MediaPayload)1