Search in sources :

Example 1 with ClaimCacheKey

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

the class Lbry method unsetFilesForCachedClaims.

public static void unsetFilesForCachedClaims(List<String> claimIds) {
    for (String claimId : claimIds) {
        ClaimCacheKey key = new ClaimCacheKey();
        key.setClaimId(claimId);
        if (claimCache.containsKey(key)) {
            claimCache.get(key).setFile(null);
        }
    }
}
Also used : ClaimCacheKey(com.odysee.app.model.ClaimCacheKey)

Example 2 with ClaimCacheKey

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

the class Lbry method fileList.

public static List<LbryFile> fileList(String claimId, boolean downloads, int page, int pageSize) throws ApiCallException {
    List<LbryFile> files = new ArrayList<>();
    Map<String, Object> params = new HashMap<>();
    if (!Helper.isNullOrEmpty(claimId)) {
        params.put("claim_id", claimId);
    }
    if (downloads) {
        params.put("download_path", null);
        params.put("comparison", "ne");
    }
    if (page > 0) {
        params.put("page", page);
    }
    if (pageSize > 0) {
        params.put("page_size", pageSize);
    }
    try {
        JSONObject result = (JSONObject) parseResponse(apiCall(METHOD_FILE_LIST, params));
        JSONArray items = result.getJSONArray("items");
        for (int i = 0; i < items.length(); i++) {
            JSONObject fileObject = items.getJSONObject(i);
            LbryFile file = LbryFile.fromJSONObject(fileObject);
            files.add(file);
            String fileClaimId = file.getClaimId();
            if (!Helper.isNullOrEmpty(fileClaimId)) {
                ClaimCacheKey key = new ClaimCacheKey();
                key.setClaimId(fileClaimId);
                if (claimCache.containsKey(key)) {
                    claimCache.get(key).setFile(file);
                }
            }
        }
    } catch (LbryRequestException | LbryResponseException | JSONException ex) {
        throw new ApiCallException("Could not execute resolve call", ex);
    }
    return files;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ApiCallException(com.odysee.app.exceptions.ApiCallException) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) LbryResponseException(com.odysee.app.exceptions.LbryResponseException) LbryRequestException(com.odysee.app.exceptions.LbryRequestException) ClaimCacheKey(com.odysee.app.model.ClaimCacheKey) JSONObject(org.json.JSONObject) LbryFile(com.odysee.app.model.LbryFile) JSONObject(org.json.JSONObject)

Example 3 with ClaimCacheKey

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

the class ChannelFragment method checkParams.

private void checkParams() {
    boolean updateRequired = false;
    Map<String, Object> params = getParams();
    String newUrl;
    if (params != null) {
        if (params.containsKey("claim")) {
            Claim claim = (Claim) params.get("claim");
            if (claim != null && !claim.equals(this.claim)) {
                this.claim = claim;
                updateRequired = true;
            }
        }
        if (params.containsKey("url")) {
            Object o = params.get("url");
            String urlString = "";
            if (o != null) {
                urlString = o.toString();
            }
            LbryUri newLbryUri = LbryUri.tryParse(urlString);
            if (newLbryUri != null) {
                newUrl = newLbryUri.toString();
                String qs = newLbryUri.getQueryString();
                if (!Helper.isNullOrEmpty(qs)) {
                    String[] qsPairs = qs.split("&");
                    for (String pair : qsPairs) {
                        String[] parts = pair.split("=");
                        if (parts.length < 2) {
                            continue;
                        }
                        if ("comment_hash".equalsIgnoreCase(parts[0])) {
                            commentHash = parts[1];
                            break;
                        }
                    }
                }
                if (claim == null || !newUrl.equalsIgnoreCase(currentUrl)) {
                    this.claim = null;
                    this.currentUrl = newUrl;
                    updateRequired = true;
                }
            }
        }
    }
    if (updateRequired) {
        resetSubCount();
        if (!Helper.isNullOrEmpty(currentUrl)) {
            // check if the claim is already cached
            ClaimCacheKey key = new ClaimCacheKey();
            key.setUrl(currentUrl);
            if (Lbry.claimCache.containsKey(key)) {
                claim = Lbry.claimCache.get(key);
            } else {
                resolveUrl();
            }
        } else if (claim == null) {
            // nothing at this location
            renderNothingAtLocation();
        }
    }
    if (!Helper.isNullOrEmpty(currentUrl)) {
        Helper.saveUrlHistory(currentUrl, claim != null ? claim.getTitle() : null, UrlSuggestion.TYPE_CHANNEL);
    }
    if (claim != null) {
        renderClaim();
    }
}
Also used : ClaimCacheKey(com.odysee.app.model.ClaimCacheKey) LbryUri(com.odysee.app.utils.LbryUri) Claim(com.odysee.app.model.Claim)

Example 4 with ClaimCacheKey

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

the class FileViewFragment method checkParams.

private void checkParams() {
    boolean updateRequired = false;
    Context context = getContext();
    // claim.setClaimId(FileViewFragmentArgs.fromBundle(getArguments()).getClaimId());
    try {
        Map<String, Object> params = getParams();
        Claim newClaim = null;
        String newUrl = null;
        if (params != null) {
            if (params.containsKey("collection")) {
                handlePlayCollection(params);
                return;
            }
            if (params.containsKey("claim")) {
                newClaim = (Claim) params.get("claim");
                // Only update fragment if new claim is different than currently being played
                if (newClaim != null && !newClaim.equals(this.fileClaim)) {
                    updateRequired = true;
                }
            }
            if (params.containsKey("url")) {
                LbryUri newLbryUri = LbryUri.tryParse(params.get("url").toString());
                if (newLbryUri != null) {
                    newUrl = newLbryUri.toString();
                    String qs = newLbryUri.getQueryString();
                    if (!Helper.isNullOrEmpty(qs)) {
                        String[] qsPairs = qs.split("&");
                        for (String pair : qsPairs) {
                            String[] parts = pair.split("=");
                            if (parts.length < 2) {
                                continue;
                            }
                            if ("comment_hash".equalsIgnoreCase(parts[0])) {
                                commentHash = parts[1];
                                break;
                            }
                        }
                    }
                    if (fileClaim == null || !newUrl.equalsIgnoreCase(currentUrl)) {
                        updateRequired = true;
                    }
                }
            }
        } else if (currentUrl != null) {
            updateRequired = true;
        } else if (context instanceof MainActivity) {
            ((MainActivity) context).onBackPressed();
        }
        boolean invalidRepost = false;
        if (updateRequired) {
            resetViewCount();
            resetFee();
            checkNewClaimAndUrl(newClaim, newUrl);
            // This is required to recycle current fragment with new claim from related content
            fileClaim = null;
            if (newClaim != null) {
                fileClaim = newClaim;
            }
            if (fileClaim == null && !Helper.isNullOrEmpty(newUrl)) {
                // check if the claim is already cached
                currentUrl = newUrl;
                ClaimCacheKey key = new ClaimCacheKey();
                key.setUrl(currentUrl);
                onNewClaim(currentUrl);
                if (Lbry.claimCache.containsKey(key)) {
                    fileClaim = Lbry.claimCache.get(key);
                }
            }
            if (fileClaim != null && Claim.TYPE_REPOST.equalsIgnoreCase(fileClaim.getValueType())) {
                fileClaim = fileClaim.getRepostedClaim();
                if (fileClaim == null || Helper.isNullOrEmpty(fileClaim.getClaimId())) {
                    // Invalid repost, probably
                    invalidRepost = true;
                    renderNothingAtLocation();
                } else if (fileClaim.getName().startsWith("@")) {
                    // this is a reposted channel, so launch the channel url
                    if (context instanceof MainActivity) {
                        MainActivity activity = (MainActivity) context;
                        // activity.onBackPressed(); // remove the reposted url page from the back stack
                        activity.getSupportFragmentManager().popBackStack();
                        activity.openChannelUrl(!Helper.isNullOrEmpty(fileClaim.getShortUrl()) ? fileClaim.getShortUrl() : fileClaim.getPermanentUrl());
                    }
                    return;
                }
            }
            if (fileClaim == null) {
                resolveUrl(currentUrl);
            }
        } else {
            checkAndResetNowPlayingClaim();
        }
        if (!Helper.isNullOrEmpty(currentUrl)) {
            Helper.saveUrlHistory(currentUrl, fileClaim != null ? fileClaim.getTitle() : null, UrlSuggestion.TYPE_FILE);
        }
        if (fileClaim != null && !invalidRepost) {
            if (Claim.TYPE_COLLECTION.equalsIgnoreCase(fileClaim.getValueType()) && fileClaim.getClaimIds() != null && fileClaim.getClaimIds().size() > 0) {
                resolvePlaylistClaimsAndPlayFirst();
                return;
            }
            Claim actualClaim = collectionClaimItem != null ? collectionClaimItem : fileClaim;
            if (!Claim.TYPE_COLLECTION.equalsIgnoreCase(actualClaim.getType())) {
                // We don't want to save actual collections to the view history
                Helper.saveViewHistory(currentUrl, actualClaim);
            }
            if (Helper.isClaimBlocked(actualClaim)) {
                renderClaimBlocked();
            } else {
                checkAndLoadRelatedContent();
                checkAndLoadComments();
                renderClaim();
                if (actualClaim.getFile() == null) {
                    loadFile();
                } else {
                // initialFileLoadDone = true;
                }
            }
        }
        checkIsFileComplete();
    } catch (Exception ex) {
        android.util.Log.e(TAG, ex.getMessage(), ex);
    }
}
Also used : AttributeProviderContext(org.commonmark.renderer.html.AttributeProviderContext) Context(android.content.Context) ClaimCacheKey(com.odysee.app.model.ClaimCacheKey) JSONObject(org.json.JSONObject) MainActivity(com.odysee.app.MainActivity) LbryUri(com.odysee.app.utils.LbryUri) 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 5 with ClaimCacheKey

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

the class MainActivity method getCachedClaimForUrl.

private Claim getCachedClaimForUrl(String url) {
    ClaimCacheKey key = new ClaimCacheKey();
    key.setUrl(url);
    return Lbry.claimCache.containsKey(key) ? Lbry.claimCache.get(key) : null;
}
Also used : ClaimCacheKey(com.odysee.app.model.ClaimCacheKey)

Aggregations

ClaimCacheKey (com.odysee.app.model.ClaimCacheKey)8 ApiCallException (com.odysee.app.exceptions.ApiCallException)3 LbryRequestException (com.odysee.app.exceptions.LbryRequestException)3 LbryResponseException (com.odysee.app.exceptions.LbryResponseException)3 Claim (com.odysee.app.model.Claim)3 JSONException (org.json.JSONException)3 JSONObject (org.json.JSONObject)3 LbryFile (com.odysee.app.model.LbryFile)2 LbryUri (com.odysee.app.utils.LbryUri)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Context (android.content.Context)1 MainActivity (com.odysee.app.MainActivity)1 LbryUriException (com.odysee.app.exceptions.LbryUriException)1 LbryioRequestException (com.odysee.app.exceptions.LbryioRequestException)1 LbryioResponseException (com.odysee.app.exceptions.LbryioResponseException)1 ClaimListResultHandler (com.odysee.app.tasks.claim.ClaimListResultHandler)1 ResolveTask (com.odysee.app.tasks.claim.ResolveTask)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1