Search in sources :

Example 6 with LbryFile

use of com.odysee.app.model.LbryFile in project odysee-android by OdyseeTeam.

the class ChannelContentFragment method onDownloadAction.

public void onDownloadAction(String downloadAction, String uri, String outpoint, String fileInfoJson, double progress) {
    if ("abort".equals(downloadAction)) {
        if (contentListAdapter != null) {
            contentListAdapter.clearFileForClaimOrUrl(outpoint, uri);
        }
        return;
    }
    try {
        JSONObject fileInfo = new JSONObject(fileInfoJson);
        LbryFile claimFile = LbryFile.fromJSONObject(fileInfo);
        String claimId = claimFile.getClaimId();
        if (contentListAdapter != null) {
            contentListAdapter.updateFileForClaimByIdOrUrl(claimFile, claimId, uri);
        }
    } catch (JSONException ex) {
    // invalid file info for download
    }
}
Also used : JSONObject(org.json.JSONObject) LbryFile(com.odysee.app.model.LbryFile) JSONException(org.json.JSONException)

Example 7 with LbryFile

use of com.odysee.app.model.LbryFile in project odysee-android by OdyseeTeam.

the class LibraryFragment method fetchDownloads.

private void fetchDownloads() {
    contentListLoading = true;
    Helper.setViewVisibility(linkStats, View.GONE);
    Helper.setViewVisibility(layoutListEmpty, View.GONE);
    FileListTask task = new FileListTask(currentPage, PAGE_SIZE, true, listLoading, new FileListTask.FileListResultHandler() {

        @Override
        public void onSuccess(List<LbryFile> files, boolean hasReachedEnd) {
            listReachedEnd = hasReachedEnd;
            List<LbryFile> filteredFiles = Helper.filterDownloads(files);
            List<Claim> claims = Helper.claimsFromFiles(filteredFiles);
            addFiles(filteredFiles);
            updateStats();
            checkStatsLink();
            if (contentListAdapter == null) {
                initContentListAdapter(claims);
            } else {
                contentListAdapter.addItems(claims);
            }
            if (contentListAdapter != null && contentList.getAdapter() == null) {
                contentList.setAdapter(contentListAdapter);
            }
            resolveMissingChannelNames(buildUrlsToResolve(claims));
            checkListEmpty();
            contentListLoading = false;
        }

        @Override
        public void onError(Exception error) {
            // pass
            checkStatsLink();
            checkListEmpty();
            contentListLoading = false;
        }
    });
    task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : FileListTask(com.odysee.app.tasks.file.FileListTask) LbryFile(com.odysee.app.model.LbryFile) List(java.util.List) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) ApiCallException(com.odysee.app.exceptions.ApiCallException)

Example 8 with LbryFile

use of com.odysee.app.model.LbryFile in project odysee-android by OdyseeTeam.

the class FileViewFragment method loadFile.

private void loadFile() {
    Claim actualClaim = collectionClaimItem != null ? collectionClaimItem : fileClaim;
    String claimId = actualClaim.getClaimId();
    FileListTask task = new FileListTask(claimId, null, new FileListTask.FileListResultHandler() {

        @Override
        public void onSuccess(List<LbryFile> files, boolean hasReachedEnd) {
            if (files.size() > 0) {
                actualClaim.setFile(files.get(0));
                checkIsFileComplete();
                if (!actualClaim.isPlayable() && !actualClaim.isViewable()) {
                    showUnsupportedView();
                }
            } else {
                if (!actualClaim.isPlayable() && !actualClaim.isViewable()) {
                    restoreMainActionButton();
                }
            }
        // initialFileLoadDone = true;
        }

        @Override
        public void onError(Exception error) {
        // initialFileLoadDone = true;
        }
    });
    task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : FileListTask(com.odysee.app.tasks.file.FileListTask) LbryFile(com.odysee.app.model.LbryFile) TrackSelectionOverride(com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride) 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)

Example 9 with LbryFile

use of com.odysee.app.model.LbryFile in project odysee-android by OdyseeTeam.

the class AllContentFragment method onDownloadAction.

public void onDownloadAction(String downloadAction, String uri, String outpoint, String fileInfoJson, double progress) {
    if ("abort".equals(downloadAction)) {
        if (contentListAdapter != null) {
            contentListAdapter.clearFileForClaimOrUrl(outpoint, uri);
        }
        return;
    }
    try {
        JSONObject fileInfo = new JSONObject(fileInfoJson);
        LbryFile claimFile = LbryFile.fromJSONObject(fileInfo);
        String claimId = claimFile.getClaimId();
        if (contentListAdapter != null) {
            contentListAdapter.updateFileForClaimByIdOrUrl(claimFile, claimId, uri);
        }
    } catch (JSONException ex) {
    // invalid file info for download
    }
}
Also used : JSONObject(org.json.JSONObject) LbryFile(com.odysee.app.model.LbryFile) JSONException(org.json.JSONException)

Example 10 with LbryFile

use of com.odysee.app.model.LbryFile in project odysee-android by OdyseeTeam.

the class GetFileTask method doInBackground.

protected LbryFile doInBackground(Void... params) {
    LbryFile file = null;
    try {
        Map<String, Object> options = new HashMap<>();
        options.put("uri", uri);
        options.put("save_file", saveFile);
        JSONObject streamInfo = (JSONObject) Lbry.genericApiCall("get", options);
        if (streamInfo.has("error")) {
            throw new ApiCallException(Helper.getJSONString("error", "", streamInfo));
        }
        file = LbryFile.fromJSONObject(streamInfo);
    } catch (ApiCallException ex) {
        error = ex;
    }
    return file;
}
Also used : JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) ApiCallException(com.odysee.app.exceptions.ApiCallException) LbryFile(com.odysee.app.model.LbryFile) JSONObject(org.json.JSONObject)

Aggregations

LbryFile (com.odysee.app.model.LbryFile)17 JSONException (org.json.JSONException)11 JSONObject (org.json.JSONObject)9 ApiCallException (com.odysee.app.exceptions.ApiCallException)7 Claim (com.odysee.app.model.Claim)6 LbryRequestException (com.odysee.app.exceptions.LbryRequestException)5 LbryResponseException (com.odysee.app.exceptions.LbryResponseException)5 View (android.view.View)3 ImageView (android.widget.ImageView)3 TextView (android.widget.TextView)3 RecyclerView (androidx.recyclerview.widget.RecyclerView)3 LbryUriException (com.odysee.app.exceptions.LbryUriException)3 LbryioRequestException (com.odysee.app.exceptions.LbryioRequestException)3 LbryioResponseException (com.odysee.app.exceptions.LbryioResponseException)3 FileListTask (com.odysee.app.tasks.file.FileListTask)3 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 ExecutionException (java.util.concurrent.ExecutionException)3 WebView (android.webkit.WebView)2 AdapterView (android.widget.AdapterView)2