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
}
}
}
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();
}
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();
}
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);
}
}
}
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);
}
Aggregations