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