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