Search in sources :

Example 11 with LbryUri

use of com.odysee.app.utils.LbryUri 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 12 with LbryUri

use of com.odysee.app.utils.LbryUri in project odysee-android by OdyseeTeam.

the class FollowingFragment method buildChannelIdsAndUrls.

private void buildChannelIdsAndUrls() {
    channelIds = new ArrayList<>();
    channelUrls = new ArrayList<>();
    if (subscriptionsList != null) {
        for (Subscription subscription : subscriptionsList) {
            try {
                String url = subscription.getUrl();
                LbryUri uri = LbryUri.parse(url);
                String claimId = uri.getClaimId();
                if (Helper.isNullOrEmpty(claimId) || Helper.isNullOrEmpty(url)) {
                    // don't add null / empty claim IDs or URLs
                    continue;
                }
                channelIds.add(claimId);
                channelUrls.add(url);
            } catch (LbryUriException ex) {
            // pass
            }
        }
    }
    excludeChannelIdsForDiscover = new ArrayList<>(channelIds);
}
Also used : LbryUriException(com.odysee.app.exceptions.LbryUriException) Subscription(com.odysee.app.model.lbryinc.Subscription) LbryUri(com.odysee.app.utils.LbryUri)

Example 13 with LbryUri

use of com.odysee.app.utils.LbryUri in project odysee-android by OdyseeTeam.

the class SearchFragment method buildVanityUrl.

private String buildVanityUrl(String query) {
    LbryUri url = new LbryUri();
    url.setClaimName(query);
    return url.toString();
}
Also used : LbryUri(com.odysee.app.utils.LbryUri)

Example 14 with LbryUri

use of com.odysee.app.utils.LbryUri in project odysee-android by OdyseeTeam.

the class Claim method fromSearchJSONObject.

@SuppressLint("SimpleDateFormat")
public static Claim fromSearchJSONObject(JSONObject searchResultObject) {
    Claim claim = new Claim();
    LbryUri claimUri = new LbryUri();
    try {
        claim.setClaimId(searchResultObject.getString("claimId"));
        claim.setName(searchResultObject.getString("name"));
        claim.setConfirmations(1);
        if (claim.getName().startsWith("@")) {
            claimUri.setChannelClaimId(claim.getClaimId());
            claimUri.setChannelName(claim.getName());
            claim.setValueType(TYPE_CHANNEL);
        } else {
            claimUri.setStreamClaimId(claim.getClaimId());
            claimUri.setStreamName(claim.getName());
            claim.setValueType((!searchResultObject.isNull("value_type") && searchResultObject.getString("value_type").equalsIgnoreCase("collection")) ? TYPE_COLLECTION : TYPE_STREAM);
        }
        int duration = searchResultObject.isNull("duration") ? 0 : searchResultObject.getInt("duration");
        long feeAmount = searchResultObject.isNull("fee") ? 0 : searchResultObject.getLong("fee");
        String releaseTimeString = !searchResultObject.isNull("release_time") ? searchResultObject.getString("release_time") : null;
        long releaseTime = 0;
        try {
            if (releaseTimeString != null) {
                Date releaseTimeAsDate = new SimpleDateFormat(RELEASE_TIME_DATE_FORMAT).parse(releaseTimeString);
                if (releaseTimeAsDate != null) {
                    releaseTime = Double.valueOf(releaseTimeAsDate.getTime() / 1000.0).longValue();
                }
            }
        } catch (ParseException ex) {
        // pass
        }
        GenericMetadata metadata = (duration > 0 || releaseTime > 0 || feeAmount > 0) ? new StreamMetadata() : new GenericMetadata();
        metadata.setTitle(searchResultObject.getString("title"));
        if (metadata instanceof StreamMetadata) {
            StreamInfo streamInfo = new StreamInfo();
            if (duration > 0) {
                // assume stream type video
                ((StreamMetadata) metadata).setStreamType(STREAM_TYPE_VIDEO);
                streamInfo.setDuration(duration);
            }
            Fee fee = null;
            if (feeAmount > 0) {
                fee = new Fee();
                fee.setAmount(String.valueOf(new BigDecimal(String.valueOf(feeAmount)).divide(new BigDecimal(100000000))));
                fee.setCurrency("LBC");
            }
            ((StreamMetadata) metadata).setFee(fee);
            ((StreamMetadata) metadata).setVideo(streamInfo);
            ((StreamMetadata) metadata).setReleaseTime(releaseTime);
        }
        claim.setValue(metadata);
        if (!searchResultObject.isNull("thumbnail_url")) {
            Resource thumbnail = new Resource();
            thumbnail.setUrl(searchResultObject.getString("thumbnail_url"));
            claim.getValue().setThumbnail(thumbnail);
        }
        if (!searchResultObject.isNull("channel_claim_id") && !searchResultObject.isNull("channel")) {
            Claim signingChannel = new Claim();
            signingChannel.setClaimId(searchResultObject.getString("channel_claim_id"));
            signingChannel.setName(searchResultObject.getString("channel"));
            LbryUri channelUri = new LbryUri();
            channelUri.setChannelClaimId(signingChannel.getClaimId());
            channelUri.setChannelName(signingChannel.getName());
            signingChannel.setPermanentUrl(channelUri.toString());
            claim.setSigningChannel(signingChannel);
        }
    } catch (JSONException ex) {
    // pass
    }
    claim.setPermanentUrl(claimUri.toString());
    return claim;
}
Also used : JSONException(org.json.JSONException) SuppressLint(android.annotation.SuppressLint) Date(java.util.Date) BigDecimal(java.math.BigDecimal) ParseException(java.text.ParseException) LbryUri(com.odysee.app.utils.LbryUri) SimpleDateFormat(java.text.SimpleDateFormat) SuppressLint(android.annotation.SuppressLint)

Example 15 with LbryUri

use of com.odysee.app.utils.LbryUri in project odysee-android by OdyseeTeam.

the class ClaimCacheKey method fromClaimPermanentUrl.

public static ClaimCacheKey fromClaimPermanentUrl(Claim claim) {
    ClaimCacheKey key = new ClaimCacheKey();
    LbryUri url = LbryUri.tryParse(claim.getPermanentUrl());
    if (url != null) {
        key.setUrl(url.toString());
    }
    return key;
}
Also used : LbryUri(com.odysee.app.utils.LbryUri)

Aggregations

LbryUri (com.odysee.app.utils.LbryUri)30 LbryUriException (com.odysee.app.exceptions.LbryUriException)10 ArrayList (java.util.ArrayList)10 JSONException (org.json.JSONException)9 Subscription (com.odysee.app.model.lbryinc.Subscription)8 ApiCallException (com.odysee.app.exceptions.ApiCallException)7 Claim (com.odysee.app.model.Claim)7 JSONObject (org.json.JSONObject)7 SQLiteException (android.database.sqlite.SQLiteException)6 MainActivity (com.odysee.app.MainActivity)6 LbryioRequestException (com.odysee.app.exceptions.LbryioRequestException)6 LbryioResponseException (com.odysee.app.exceptions.LbryioResponseException)6 ExecutionException (java.util.concurrent.ExecutionException)6 SuppressLint (android.annotation.SuppressLint)4 Context (android.content.Context)4 RecyclerView (androidx.recyclerview.widget.RecyclerView)4 Tag (com.odysee.app.model.Tag)4 HashMap (java.util.HashMap)4 AccountManager (android.accounts.AccountManager)3 View (android.view.View)3