Search in sources :

Example 6 with ClaimCacheKey

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

the class Lbry method get.

public static LbryFile get(boolean saveFile) throws ApiCallException {
    LbryFile file = null;
    Map<String, Object> params = new HashMap<>();
    params.put("save_file", saveFile);
    try {
        JSONObject result = (JSONObject) parseResponse(apiCall(METHOD_GET, params));
        file = LbryFile.fromJSONObject(result);
        if (file != null) {
            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 ex) {
        throw new ApiCallException("Could not execute resolve call", ex);
    }
    return file;
}
Also used : ClaimCacheKey(com.odysee.app.model.ClaimCacheKey) JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ApiCallException(com.odysee.app.exceptions.ApiCallException) LbryFile(com.odysee.app.model.LbryFile) JSONObject(org.json.JSONObject) LbryResponseException(com.odysee.app.exceptions.LbryResponseException) LbryRequestException(com.odysee.app.exceptions.LbryRequestException)

Example 7 with ClaimCacheKey

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

the class Lbry method addClaimToCache.

public static void addClaimToCache(Claim claim) {
    ClaimCacheKey fullKey = ClaimCacheKey.fromClaim(claim);
    ClaimCacheKey shortUrlKey = ClaimCacheKey.fromClaimShortUrl(claim);
    ClaimCacheKey permanentUrlKey = ClaimCacheKey.fromClaimPermanentUrl(claim);
    if (!Helper.isNullOrEmpty(fullKey.getUrl())) {
        claimCache.put(fullKey, claim);
    }
    if (!Helper.isNullOrEmpty(permanentUrlKey.getUrl())) {
        claimCache.put(permanentUrlKey, claim);
    }
    if (!Helper.isNullOrEmpty(shortUrlKey.getUrl())) {
        claimCache.put(shortUrlKey, claim);
    }
}
Also used : ClaimCacheKey(com.odysee.app.model.ClaimCacheKey)

Example 8 with ClaimCacheKey

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

the class SearchFragment method resolveFeaturedItem.

private void resolveFeaturedItem(String vanityUrl) {
    final ClaimCacheKey key = new ClaimCacheKey();
    key.setUrl(vanityUrl);
    if (Lbry.claimCache.containsKey(key)) {
        Claim cachedClaim = Lbry.claimCache.get(key);
        updateFeaturedItemFromResolvedClaim(cachedClaim);
        return;
    }
    ResolveTask task = new ResolveTask(vanityUrl, Lbry.API_CONNECTION_STRING, null, new ClaimListResultHandler() {

        @Override
        public void onSuccess(List<Claim> claims) {
            if (claims.size() > 0 && !Helper.isNullOrEmpty(claims.get(0).getClaimId())) {
                Claim resolved = claims.get(0);
                Lbry.claimCache.put(key, resolved);
                updateFeaturedItemFromResolvedClaim(resolved);
            }
        }

        @Override
        public void onError(Exception error) {
        }
    });
    task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : ClaimListResultHandler(com.odysee.app.tasks.claim.ClaimListResultHandler) ClaimCacheKey(com.odysee.app.model.ClaimCacheKey) Claim(com.odysee.app.model.Claim) JSONException(org.json.JSONException) ResolveTask(com.odysee.app.tasks.claim.ResolveTask)

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