Search in sources :

Example 11 with MediaModel

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);
}
Also used : MediaModel(org.wordpress.android.fluxc.model.MediaModel)

Example 12 with MediaModel

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);
}
Also used : MediaModel(org.wordpress.android.fluxc.model.MediaModel) File(java.io.File)

Example 13 with MediaModel

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();
    }
}
Also used : MediaModel(org.wordpress.android.fluxc.model.MediaModel) ArrayList(java.util.ArrayList) SuppressLint(android.annotation.SuppressLint) HashSet(java.util.HashSet)

Example 14 with MediaModel

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();
}
Also used : MediaModel(org.wordpress.android.fluxc.model.MediaModel) SuppressLint(android.annotation.SuppressLint) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 15 with MediaModel

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