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();
}
}
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);
}
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();
}
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;
}
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;
}
Aggregations