use of com.odysee.app.tasks.claim.ClaimSearchResultHandler in project odysee-android by OdyseeTeam.
the class FileViewFragment method checkAndConfirmPurchaseUrl.
private void checkAndConfirmPurchaseUrl() {
Claim actualClaim = collectionClaimItem != null ? collectionClaimItem : fileClaim;
if (actualClaim != null) {
PurchaseListTask task = new PurchaseListTask(actualClaim.getClaimId(), null, new ClaimSearchResultHandler() {
@Override
public void onSuccess(List<Claim> claims, boolean hasReachedEnd) {
boolean purchased = false;
if (claims.size() == 1) {
Claim purchasedClaim = claims.get(0);
if (actualClaim.getClaimId().equalsIgnoreCase(purchasedClaim.getClaimId())) {
// already purchased
purchased = true;
}
}
if (purchased) {
handleMainActionForClaim();
} else {
restoreMainActionButton();
confirmPurchaseUrl();
}
}
@Override
public void onError(Exception error) {
// pass
restoreMainActionButton();
}
});
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
use of com.odysee.app.tasks.claim.ClaimSearchResultHandler in project odysee-android by OdyseeTeam.
the class FileViewFragment method resolvePlaylistClaimsAndPlayFirst.
private void resolvePlaylistClaimsAndPlayFirst() {
if (playlistResolved) {
return;
}
Helper.setViewVisibility(layoutLoadingState, View.VISIBLE);
Helper.setViewVisibility(layoutResolving, View.VISIBLE);
Helper.setViewVisibility(layoutNothingAtLocation, View.GONE);
Helper.setViewVisibility(layoutDisplayArea, View.GONE);
Map<String, Object> options = new HashMap<>();
options.put("claim_type", "stream");
options.put("page", 1);
options.put("page_size", 999);
options.put("claim_ids", fileClaim.getClaimIds());
ClaimSearchTask task = new ClaimSearchTask(options, Lbry.API_CONNECTION_STRING, null, new ClaimSearchResultHandler() {
@Override
public void onSuccess(List<Claim> claims, boolean hasReachedEnd) {
playlistResolved = true;
// reorder the claims based on the order in the list, TODO: find a more efficient way to do this
Map<String, Claim> playlistClaimMap = new LinkedHashMap<>();
List<String> claimIds = fileClaim.getClaimIds();
for (String id : claimIds) {
for (Claim claim : claims) {
if (id.equalsIgnoreCase(claim.getClaimId())) {
playlistClaimMap.put(id, claim);
break;
}
}
}
playlistClaims = new ArrayList<>(playlistClaimMap.values());
if (playlistClaims.size() > 0) {
playClaimFromCollection(playlistClaims.get(0), 0);
}
relatedContentAdapter = new ClaimListAdapter(playlistClaims, getContext());
relatedContentAdapter.setListener(FileViewFragment.this);
View root = getView();
if (root != null) {
RecyclerView relatedContentList = root.findViewById(R.id.file_view_related_content_list);
relatedContentList.setAdapter(relatedContentAdapter);
}
}
@Override
public void onError(Exception error) {
showError(getString(R.string.comment_error));
}
});
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
use of com.odysee.app.tasks.claim.ClaimSearchResultHandler in project odysee-android by OdyseeTeam.
the class FollowingFragment method fetchClaimSearchContent.
private void fetchClaimSearchContent(boolean reset) {
if (reset && contentListAdapter != null) {
contentListAdapter.clearItems();
currentClaimSearchPage = 1;
}
contentClaimSearchLoading = true;
Helper.setViewVisibility(noContentView, View.GONE);
Map<String, Object> claimSearchOptions = buildContentOptions();
contentClaimSearchTask = new ClaimSearchTask(claimSearchOptions, Lbry.API_CONNECTION_STRING, getLoadingView(), new ClaimSearchResultHandler() {
@Override
public void onSuccess(List<Claim> claims, boolean hasReachedEnd) {
claims = Helper.filterClaimsByOutpoint(claims);
claims = Helper.filterClaimsByBlockedChannels(claims, Lbryio.blockedChannels);
Date d = new Date();
Calendar cal = new GregorianCalendar();
cal.setTime(d);
// Remove claims with a release time in the future
claims.removeIf(e -> {
Claim.GenericMetadata metadata = e.getValue();
return metadata instanceof Claim.StreamMetadata && (((Claim.StreamMetadata) metadata).getReleaseTime()) > (cal.getTimeInMillis() / 1000L);
});
// Sort claims so those which are livestreaming now are shwon on the top of the list
Collections.sort(claims, new Comparator<Claim>() {
@Override
public int compare(Claim claim, Claim t1) {
if (claim.isLive() && !t1.isLive())
return -1;
else if (!claim.isLive() && t1.isLive())
return 1;
else
return 0;
}
});
if (contentListAdapter == null) {
Context context = getContext();
if (context != null) {
contentListAdapter = new ClaimListAdapter(claims, context);
contentListAdapter.setListener(new ClaimListAdapter.ClaimListItemListener() {
@Override
public void onClaimClicked(Claim claim, int position) {
Context context = getContext();
if (context instanceof MainActivity) {
MainActivity activity = (MainActivity) context;
if (claim.getName().startsWith("@")) {
// channel claim
activity.openChannelClaim(claim);
} else {
activity.openFileClaim(claim);
}
}
}
});
}
} else {
contentListAdapter.addItems(claims);
}
if (contentList != null && contentList.getAdapter() == null) {
contentList.setAdapter(contentListAdapter);
}
contentHasReachedEnd = hasReachedEnd;
contentClaimSearchLoading = false;
checkNoContent(false);
}
@Override
public void onError(Exception error) {
contentClaimSearchLoading = false;
checkNoContent(false);
}
});
contentClaimSearchTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
use of com.odysee.app.tasks.claim.ClaimSearchResultHandler in project odysee-android by OdyseeTeam.
the class LibraryFragment method fetchPurchases.
private void fetchPurchases() {
contentListLoading = true;
Helper.setViewVisibility(linkStats, View.GONE);
Helper.setViewVisibility(layoutListEmpty, View.GONE);
PurchaseListTask task = new PurchaseListTask(currentPage, PAGE_SIZE, listLoading, new ClaimSearchResultHandler() {
@Override
public void onSuccess(List<Claim> claims, boolean hasReachedEnd) {
listReachedEnd = hasReachedEnd;
if (contentListAdapter == null) {
initContentListAdapter(claims);
} else {
contentListAdapter.addItems(claims);
}
if (contentListAdapter != null && contentList.getAdapter() == null) {
contentList.setAdapter(contentListAdapter);
}
checkListEmpty();
contentListLoading = false;
}
@Override
public void onError(Exception error) {
checkStatsLink();
checkListEmpty();
contentListLoading = false;
}
});
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
use of com.odysee.app.tasks.claim.ClaimSearchResultHandler in project odysee-android by OdyseeTeam.
the class ChannelContentFragment method fetchClaimSearchContent.
private void fetchClaimSearchContent(boolean reset) {
if (reset && contentListAdapter != null) {
contentListAdapter.clearItems();
currentClaimSearchPage = 1;
}
contentClaimSearchLoading = true;
Helper.setViewVisibility(noContentView, View.GONE);
Map<String, Object> claimSearchOptions = buildContentOptions();
contentClaimSearchTask = new ClaimSearchTask(claimSearchOptions, Lbry.API_CONNECTION_STRING, getLoadingView(), new ClaimSearchResultHandler() {
@Override
public void onSuccess(List<Claim> claims, boolean hasReachedEnd) {
claims = Helper.filterClaimsByOutpoint(claims);
if (contentListAdapter == null) {
Context context = getContext();
if (context != null) {
contentListAdapter = new ClaimListAdapter(claims, context);
contentListAdapter.setListener(new ClaimListAdapter.ClaimListItemListener() {
@Override
public void onClaimClicked(Claim claim, int position) {
Context context = getContext();
if (context instanceof MainActivity) {
MainActivity activity = (MainActivity) context;
if (claim.getName().startsWith("@")) {
// channel claim
activity.openChannelClaim(claim);
} else {
activity.openFileClaim(claim);
}
}
}
});
}
} else {
contentListAdapter.addItems(claims);
}
if (contentList != null && contentList.getAdapter() == null) {
contentList.setAdapter(contentListAdapter);
}
contentHasReachedEnd = hasReachedEnd;
contentClaimSearchLoading = false;
checkNoContent();
}
@Override
public void onError(Exception error) {
contentClaimSearchLoading = false;
checkNoContent();
}
});
contentClaimSearchTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Aggregations