Search in sources :

Example 21 with MediaModel

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

the class EditPostSettingsFragment method updateFeaturedImage.

public void updateFeaturedImage(long id) {
    if (mFeaturedImageId != id) {
        mFeaturedImageId = id;
        if (mFeaturedImageId > 0) {
            MediaModel media = mMediaStore.getSiteMediaWithId(mSite, mFeaturedImageId);
            if (media == null) {
                return;
            }
            mFeaturedImageView.setVisibility(View.VISIBLE);
            mFeaturedImageButton.setVisibility(View.GONE);
            // Get max width for photon thumbnail
            int maxWidth = getResources().getDisplayMetrics().widthPixels;
            int padding = DisplayUtils.dpToPx(getActivity(), 16);
            int imageWidth = (maxWidth - padding);
            WordPressMediaUtils.loadNetworkImage(media.getThumbnailUrl() + "?w=" + imageWidth, mFeaturedImageView, mImageLoader);
        } else {
            mFeaturedImageView.setVisibility(View.GONE);
            mFeaturedImageButton.setVisibility(View.VISIBLE);
        }
    }
}
Also used : MediaModel(org.wordpress.android.fluxc.model.MediaModel)

Example 22 with MediaModel

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

the class EditPostActivity method queueFileForUpload.

private MediaModel queueFileForUpload(Uri uri, String mimeType, UploadState startingState) {
    String path = getRealPathFromURI(uri);
    // Invalid file path
    if (TextUtils.isEmpty(path)) {
        Toast.makeText(this, R.string.editor_toast_invalid_path, Toast.LENGTH_SHORT).show();
        return null;
    }
    // File not found
    File file = new File(path);
    if (!file.exists()) {
        Toast.makeText(this, R.string.file_not_found, Toast.LENGTH_SHORT).show();
        return null;
    }
    MediaModel media = buildMediaModel(uri, mimeType, startingState);
    mDispatcher.dispatch(MediaActionBuilder.newUpdateMediaAction(media));
    mPendingUploads.add(media);
    startMediaUploadService();
    return media;
}
Also used : MediaModel(org.wordpress.android.fluxc.model.MediaModel) MediaFile(org.wordpress.android.util.helpers.MediaFile) File(java.io.File)

Example 23 with MediaModel

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

the class EditPostActivity method addMediaLegacyEditor.

private boolean addMediaLegacyEditor(Uri mediaUri, boolean isVideo) {
    trackAddMediaFromDeviceEvents(isVideo, false, mediaUri, null);
    MediaModel mediaModel = buildMediaModel(mediaUri, getContentResolver().getType(mediaUri), UploadState.QUEUED);
    if (isVideo) {
        mediaModel.setTitle(getResources().getString(R.string.video));
    } else {
        mediaModel.setTitle(ImageUtils.getTitleForWPImageSpan(this, mediaUri.getEncodedPath()));
    }
    mediaModel.setPostId(mPost.getId());
    mDispatcher.dispatch(MediaActionBuilder.newUpdateMediaAction(mediaModel));
    MediaFile mediaFile = FluxCUtils.mediaFileFromMediaModel(mediaModel);
    mEditorFragment.appendMediaFile(mediaFile, mediaFile.getFilePath(), mImageLoader);
    return true;
}
Also used : MediaFile(org.wordpress.android.util.helpers.MediaFile) 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