Search in sources :

Example 1 with ImgurUploadRequest

use of com.ferg.awfulapp.task.ImgurUploadRequest in project Awful.apk by Awful.

the class ImgurInserter method startUpload.

// /////////////////////////////////////////////////////////////////////////
// Upload request and normal response handling
// /////////////////////////////////////////////////////////////////////////
/**
 * Attempt to start an upload for the current image source, cancelling any upload in progress.
 */
void startUpload() {
    if (state != State.READY_TO_UPLOAD) {
        return;
    }
    setState(State.UPLOADING);
    cancelUploadTask();
    // do a url if we have one
    if (uploadSourceIsUrl) {
        uploadTask = new ImgurUploadRequest(uploadUrlEditText.getText().toString(), this::parseUploadResponse, this::handleUploadError);
        NetworkUtils.queueRequest(uploadTask);
    } else {
        ContentResolver contentResolver = getActivity().getContentResolver();
        if (contentResolver != null) {
            try {
                InputStream inputStream = contentResolver.openInputStream(imageFile);
                if (inputStream != null) {
                    uploadTask = new ImgurUploadRequest(inputStream, this::parseUploadResponse, this::handleUploadError);
                }
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }
        if (uploadTask == null) {
            onUploadError(getString(R.string.imgur_uploader_error_file_access));
        } else {
            NetworkUtils.queueRequest(uploadTask);
        }
    }
}
Also used : InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) ImgurUploadRequest(com.ferg.awfulapp.task.ImgurUploadRequest) ContentResolver(android.content.ContentResolver)

Aggregations

ContentResolver (android.content.ContentResolver)1 ImgurUploadRequest (com.ferg.awfulapp.task.ImgurUploadRequest)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1