Search in sources :

Example 1 with MediaModel

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

the class HtmlToSpannedConverter method startImg.

private void startImg(SpannableStringBuilder text, Attributes attributes, WPHtml.ImageGetter img) {
    if (mContext == null)
        return;
    String src = attributes.getValue("android-uri");
    Bitmap resizedBitmap = null;
    try {
        resizedBitmap = ImageUtils.getWPImageSpanThumbnailFromFilePath(mContext, src, mMaxImageWidth);
        if (resizedBitmap == null && src != null) {
            if (src.contains("video")) {
                resizedBitmap = BitmapFactory.decodeResource(mContext.getResources(), org.wordpress.android.editor.R.drawable.media_movieclip);
            } else {
                resizedBitmap = BitmapFactory.decodeResource(mContext.getResources(), org.wordpress.android.R.drawable.media_image_placeholder);
            }
        }
    } catch (OutOfMemoryError e) {
        CrashlyticsUtils.logException(e, AppLog.T.UTILS);
    }
    if (resizedBitmap != null) {
        int len = text.length();
        text.append("");
        Uri curStream = Uri.parse(src);
        if (curStream == null) {
            return;
        }
        WPImageSpan is = new WPImageSpan(mContext, resizedBitmap, curStream);
        // Get the MediaFile data from db
        MediaModel mediaModel = mMediaStore.getPostMediaWithPath(mPost.getId(), src);
        MediaFile mediaFile = FluxCUtils.mediaFileFromMediaModel(mediaModel);
        if (mediaFile != null) {
            is.setMediaFile(mediaFile);
            is.setImageSource(curStream);
            text.setSpan(is, len, text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            AlignmentSpan.Standard as = new AlignmentSpan.Standard(Layout.Alignment.ALIGN_CENTER);
            text.setSpan(as, text.getSpanStart(is), text.getSpanEnd(is), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    } else if (mPost != null) {
        if (mPost.isLocalDraft()) {
            if (attributes != null) {
                text.append("<img");
                for (int i = 0; i < attributes.getLength(); i++) {
                    // Attr name
                    String aName = attributes.getLocalName(i);
                    if ("".equals(aName))
                        aName = attributes.getQName(i);
                    text.append(" ");
                    text.append(aName + "=\"" + attributes.getValue(i) + "\"");
                }
                text.append(" />\n");
            }
        }
    } else if (src == null) {
        //get regular src value from <img/> tag's src attribute
        src = attributes.getValue("", "src");
        Drawable d = null;
        if (img != null) {
            d = img.getDrawable(src);
        }
        if (d != null) {
            int len = text.length();
            text.append("");
            text.setSpan(new ImageSpan(d, src), len, text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        } else {
        // noop - we're not showing a default image here
        }
    }
}
Also used : MediaFile(org.wordpress.android.util.helpers.MediaFile) AlignmentSpan(android.text.style.AlignmentSpan) Drawable(android.graphics.drawable.Drawable) WPImageSpan(org.wordpress.android.util.helpers.WPImageSpan) Uri(android.net.Uri) Bitmap(android.graphics.Bitmap) MediaModel(org.wordpress.android.fluxc.model.MediaModel) ImageSpan(android.text.style.ImageSpan) WPImageSpan(org.wordpress.android.util.helpers.WPImageSpan)

Example 2 with MediaModel

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

the class MediaGalleryPickerActivity method setResultIdsAndFinish.

private void setResultIdsAndFinish() {
    Intent intent = new Intent();
    if (mGridAdapter.getSelectedItemCount() > 0) {
        ArrayList<Long> remoteMediaIds = new ArrayList<>();
        for (Integer localId : mGridAdapter.getSelectedItems()) {
            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 3 with MediaModel

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

the class MediaGridFragment method handleMultiSelectDelete.

private void handleMultiSelectDelete() {
    if (!isAdded()) {
        return;
    }
    Builder builder = new AlertDialog.Builder(getActivity()).setMessage(R.string.confirm_delete_multi_media).setCancelable(true).setPositiveButton(R.string.delete, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (getActivity() instanceof MediaBrowserActivity) {
                ((MediaBrowserActivity) getActivity()).deleteMedia(mGridAdapter.getSelectedItems());
            }
            // update upload state
            for (int itemId : mGridAdapter.getSelectedItems()) {
                MediaModel media = mMediaStore.getMediaWithLocalId(itemId);
                media.setUploadState(MediaUploadState.DELETE.name());
                mDispatcher.dispatch(MediaActionBuilder.newUpdateMediaAction(media));
            }
            mGridAdapter.clearSelection();
            if (mActionMode != null) {
                mActionMode.finish();
            }
            refreshMediaFromDB();
            refreshSpinnerAdapter();
        }
    }).setNegativeButton(R.string.cancel, null);
    AlertDialog dialog = builder.create();
    dialog.show();
}
Also used : AlertDialog(android.app.AlertDialog) MediaModel(org.wordpress.android.fluxc.model.MediaModel) DialogInterface(android.content.DialogInterface) Builder(android.app.AlertDialog.Builder) MediaActionBuilder(org.wordpress.android.fluxc.generated.MediaActionBuilder)

Example 4 with MediaModel

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

the class MediaUploadService method unpackIntent.

private void unpackIntent(@NonNull Intent intent) {
    mSite = (SiteModel) intent.getSerializableExtra(WordPress.SITE);
    // add local queued media from store
    List<MediaModel> localMedia = mMediaStore.getLocalSiteMedia(mSite);
    if (localMedia != null && !localMedia.isEmpty()) {
        // uploading is updated to queued, queued media added to the queue, failed media added to completed list
        for (MediaModel mediaItem : localMedia) {
            if (MediaUploadState.UPLOADING.name().equals(mediaItem.getUploadState())) {
                mediaItem.setUploadState(MediaUploadState.QUEUED.name());
                mDispatcher.dispatch(MediaActionBuilder.newUpdateMediaAction(mediaItem));
            }
            if (MediaUploadState.QUEUED.name().equals(mediaItem.getUploadState())) {
                addUniqueMediaToQueue(mediaItem);
            } else if (MediaUploadState.FAILED.name().equals(mediaItem.getUploadState())) {
                getCompletedItems().add(mediaItem);
            }
        }
    }
    // add new media
    @SuppressWarnings("unchecked") List<MediaModel> mediaList = (List<MediaModel>) intent.getSerializableExtra(MEDIA_LIST_KEY);
    if (mediaList != null) {
        for (MediaModel media : mediaList) {
            addUniqueMediaToQueue(media);
        }
    }
}
Also used : MediaModel(org.wordpress.android.fluxc.model.MediaModel) ArrayList(java.util.ArrayList) List(java.util.List)

Example 5 with MediaModel

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

the class MediaItemFragment method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int itemId = item.getItemId();
    if (itemId == R.id.menu_delete) {
        MediaModel mediaModel = mMediaStore.getMediaWithLocalId(getLocalMediaId());
        if (mediaModel == null) {
            return true;
        }
        boolean canDeleteMedia = WordPressMediaUtils.canDeleteMedia(mediaModel);
        if (!canDeleteMedia) {
            Toast.makeText(getActivity(), R.string.wait_until_upload_completes, Toast.LENGTH_LONG).show();
            return true;
        }
        Builder builder = new AlertDialog.Builder(getActivity()).setMessage(R.string.confirm_delete_media).setCancelable(true).setPositiveButton(R.string.delete, new OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                ArrayList<Integer> ids = new ArrayList<>(1);
                ids.add(getLocalMediaId());
                if (getActivity() instanceof MediaBrowserActivity) {
                    ((MediaBrowserActivity) getActivity()).deleteMedia(ids);
                }
            }
        }).setNegativeButton(R.string.cancel, null);
        AlertDialog dialog = builder.create();
        dialog.show();
        return true;
    } else if (itemId == R.id.menu_copy_media_url) {
        copyUrlToClipboard();
        return true;
    }
    return super.onOptionsItemSelected(item);
}
Also used : AlertDialog(android.app.AlertDialog) MediaModel(org.wordpress.android.fluxc.model.MediaModel) DialogInterface(android.content.DialogInterface) Builder(android.app.AlertDialog.Builder) ArrayList(java.util.ArrayList) OnClickListener(android.content.DialogInterface.OnClickListener)

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