Search in sources :

Example 1 with GetFileTask

use of com.odysee.app.tasks.file.GetFileTask in project odysee-android by OdyseeTeam.

the class FileViewFragment method fileGet.

private void fileGet(boolean save) {
    if (getFileTask != null && getFileTask.getStatus() != AsyncTask.Status.FINISHED) {
        return;
    }
    Claim actualClaim = collectionClaimItem != null ? collectionClaimItem : fileClaim;
    getFileTask = new GetFileTask(actualClaim.getPermanentUrl(), save, null, new GetFileTask.GetFileHandler() {

        @Override
        public void beforeStart() {
        }

        @Override
        public void onSuccess(LbryFile file, boolean saveFile) {
            // queue the download
            if (actualClaim != null) {
                if (actualClaim.isFree()) {
                    // paid is handled differently
                    Bundle bundle = new Bundle();
                    bundle.putString("uri", currentUrl);
                    bundle.putString("paid", "false");
                    LbryAnalytics.logEvent(LbryAnalytics.EVENT_PURCHASE_URI, bundle);
                }
                if (!actualClaim.isPlayable()) {
                    logFileView(actualClaim.getPermanentUrl(), 0);
                }
                actualClaim.setFile(file);
                playOrViewMedia();
            }
        }

        @Override
        public void onError(Exception error, boolean saveFile) {
            try {
                showError(getString(R.string.unable_to_view_url, currentUrl));
                if (saveFile) {
                    onDownloadAborted();
                }
                restoreMainActionButton();
            } catch (IllegalStateException ex) {
            // pass
            }
        }
    });
    getFileTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : Bundle(android.os.Bundle) LbryFile(com.odysee.app.model.LbryFile) GetFileTask(com.odysee.app.tasks.file.GetFileTask) Claim(com.odysee.app.model.Claim) LbryRequestException(com.odysee.app.exceptions.LbryRequestException) JSONException(org.json.JSONException) LbryUriException(com.odysee.app.exceptions.LbryUriException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) LbryResponseException(com.odysee.app.exceptions.LbryResponseException) LbryioRequestException(com.odysee.app.exceptions.LbryioRequestException) LbryioResponseException(com.odysee.app.exceptions.LbryioResponseException) ApiCallException(com.odysee.app.exceptions.ApiCallException)

Aggregations

Bundle (android.os.Bundle)1 ApiCallException (com.odysee.app.exceptions.ApiCallException)1 LbryRequestException (com.odysee.app.exceptions.LbryRequestException)1 LbryResponseException (com.odysee.app.exceptions.LbryResponseException)1 LbryUriException (com.odysee.app.exceptions.LbryUriException)1 LbryioRequestException (com.odysee.app.exceptions.LbryioRequestException)1 LbryioResponseException (com.odysee.app.exceptions.LbryioResponseException)1 Claim (com.odysee.app.model.Claim)1 LbryFile (com.odysee.app.model.LbryFile)1 GetFileTask (com.odysee.app.tasks.file.GetFileTask)1 IOException (java.io.IOException)1 ExecutionException (java.util.concurrent.ExecutionException)1 JSONException (org.json.JSONException)1