use of com.odysee.app.model.Claim 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.model.Claim in project odysee-android by OdyseeTeam.
the class FileViewFragment method loadRelatedContent.
private void loadRelatedContent() {
// reset the list view
View root = getView();
if (fileClaim != null && root != null) {
Context context = getContext();
List<Claim> loadingPlaceholders = new ArrayList<>();
int loadingPlaceholdersLength = Claim.TYPE_COLLECTION.equalsIgnoreCase(fileClaim.getValueType()) ? fileClaim.getClaimIds().size() : 15;
for (int i = 0; i < loadingPlaceholdersLength; i++) {
Claim placeholder = new Claim();
placeholder.setLoadingPlaceholder(true);
loadingPlaceholders.add(placeholder);
}
relatedContentAdapter = new ClaimListAdapter(loadingPlaceholders, context);
relatedContentAdapter.setContextGroupId(FILE_CONTEXT_GROUP_ID);
RecyclerView relatedContentList = root.findViewById(R.id.file_view_related_content_list);
relatedContentList.setAdapter(relatedContentAdapter);
ProgressBar relatedLoading = root.findViewById(R.id.file_view_related_content_progress);
boolean canShowMatureContent = false;
if (context != null) {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
canShowMatureContent = sp.getBoolean(MainActivity.PREFERENCE_KEY_SHOW_MATURE_CONTENT, false);
}
if (!Claim.TYPE_COLLECTION.equalsIgnoreCase(fileClaim.getValueType())) {
String title = fileClaim.getTitle();
String claimId = fileClaim.getClaimId();
final boolean nsfw = canShowMatureContent;
relatedLoading.setVisibility(View.VISIBLE);
// Making a request which explicitly uses a certain value form the amount of results needed
// and no processing any possible exception, so using a callable instead of an AsyncTask
// makes sense for all Android API Levels
Thread t = new Thread(new Runnable() {
@Override
public void run() {
ExecutorService executor = Executors.newSingleThreadExecutor();
LighthouseSearch callable = new LighthouseSearch(title, RELATED_CONTENT_SIZE, 0, nsfw, claimId);
Future<List<Claim>> future = executor.submit(callable);
try {
List<Claim> result = future.get();
if (executor != null && !executor.isShutdown()) {
executor.shutdown();
}
MainActivity a = (MainActivity) getActivity();
if (a != null) {
a.runOnUiThread(new Runnable() {
@Override
public void run() {
relatedContentRequestSuccedded(result);
relatedLoading.setVisibility(View.GONE);
}
});
}
} catch (InterruptedException | ExecutionException e) {
if (executor != null && !executor.isShutdown()) {
executor.shutdown();
}
e.printStackTrace();
}
}
});
t.start();
} else {
TextView relatedOrPlayList = root.findViewById(R.id.related_or_playlist);
relatedOrPlayList.setText(fileClaim.getTitle());
relatedOrPlayList.setCompoundDrawablesRelativeWithIntrinsicBounds(R.drawable.ic_cast_connected, 0, 0, 0);
relatedOrPlayList.setPadding(0, 0, 0, 16);
relatedOrPlayList.setTypeface(null, Typeface.BOLD);
Map<String, Object> claimSearchOptions = new HashMap<>(3);
claimSearchOptions.put("claim_ids", fileClaim.getClaimIds());
claimSearchOptions.put("not_tags", canShowMatureContent ? null : new ArrayList<>(Predefined.MATURE_TAGS));
claimSearchOptions.put("page_size", fileClaim.getClaimIds().size());
ExecutorService executor = Executors.newSingleThreadExecutor();
Future<List<Claim>> future = executor.submit(new Search(claimSearchOptions));
try {
List<Claim> playlistClaimItems = future.get();
if (playlistClaimItems != null) {
relatedContentAdapter.setItems(playlistClaimItems);
relatedContentAdapter.setListener(FileViewFragment.this);
View v = getView();
if (v != null) {
relatedContentList.setAdapter(relatedContentAdapter);
relatedContentAdapter.notifyDataSetChanged();
Helper.setViewVisibility(v.findViewById(R.id.file_view_no_related_content), relatedContentAdapter == null || relatedContentAdapter.getItemCount() == 0 ? View.VISIBLE : View.GONE);
}
scrollToCommentHash();
}
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
}
}
}
use of com.odysee.app.model.Claim in project odysee-android by OdyseeTeam.
the class FileViewFragment method resolveUrl.
private void resolveUrl(String url) {
// resolving = true;
Helper.setViewVisibility(layoutDisplayArea, View.INVISIBLE);
Helper.setViewVisibility(layoutLoadingState, View.VISIBLE);
Helper.setViewVisibility(layoutNothingAtLocation, View.GONE);
ResolveTask task = new ResolveTask(url, Lbry.API_CONNECTION_STRING, layoutResolving, new ClaimListResultHandler() {
@Override
public void onSuccess(List<Claim> claims) {
if (!claims.isEmpty() && !Helper.isNullOrEmpty(claims.get(0).getClaimId())) {
fileClaim = claims.get(0);
if (Claim.TYPE_REPOST.equalsIgnoreCase(fileClaim.getValueType())) {
fileClaim = fileClaim.getRepostedClaim();
// cache the reposted claim too for subsequent loads
Lbry.addClaimToCache(fileClaim);
if (fileClaim.getName().startsWith("@")) {
// this is a reposted channel, so finish this activity and launch the channel url
Context context = getContext();
if (context instanceof MainActivity) {
MainActivity activity = (MainActivity) context;
activity.getSupportFragmentManager().popBackStack();
activity.openChannelUrl(!Helper.isNullOrEmpty(fileClaim.getShortUrl()) ? fileClaim.getShortUrl() : fileClaim.getPermanentUrl());
}
return;
}
} else {
Lbry.addClaimToCache(fileClaim);
}
if (Claim.TYPE_COLLECTION.equalsIgnoreCase(fileClaim.getValueType()) && fileClaim.getClaimIds() != null && fileClaim.getClaimIds().size() > 0) {
collectionClaimItem = null;
}
Helper.saveUrlHistory(url, fileClaim.getTitle(), UrlSuggestion.TYPE_FILE);
// do not save collections to view history
if (!Claim.TYPE_COLLECTION.equalsIgnoreCase(fileClaim.getType())) {
// also save view history
Helper.saveViewHistory(url, fileClaim);
}
checkAndResetNowPlayingClaim();
if (Helper.isClaimBlocked(fileClaim)) {
renderClaimBlocked();
} else {
loadFile();
checkAndLoadRelatedContent();
checkAndLoadComments();
renderClaim();
}
} else {
// render nothing at location
renderNothingAtLocation();
}
}
@Override
public void onError(Exception error) {
// resolving = false;
}
});
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
use of com.odysee.app.model.Claim in project odysee-android by OdyseeTeam.
the class FileViewFragment method onMainActionButtonClicked.
private void onMainActionButtonClicked() {
Claim actualClaim = collectionClaimItem != null ? collectionClaimItem : fileClaim;
// Check if the claim is free
Claim.GenericMetadata metadata = actualClaim.getValue();
if (metadata instanceof Claim.StreamMetadata) {
View root = getView();
if (root != null) {
root.findViewById(R.id.file_view_main_action_button).setVisibility(View.INVISIBLE);
root.findViewById(R.id.file_view_main_action_loading).setVisibility(View.VISIBLE);
}
if (actualClaim.getFile() == null && !actualClaim.isFree()) {
checkAndConfirmPurchaseUrl();
} else {
handleMainActionForClaim();
}
} else {
showError(getString(R.string.cannot_view_claim));
}
}
use of com.odysee.app.model.Claim in project odysee-android by OdyseeTeam.
the class FileViewFragment method onDownloadAborted.
private void onDownloadAborted() {
downloadInProgress = false;
Claim actualClaim = collectionClaimItem != null ? collectionClaimItem : fileClaim;
if (actualClaim != null) {
actualClaim.setFile(null);
}
View root = getView();
if (root != null) {
((ImageView) root.findViewById(R.id.file_view_action_download_icon)).setImageResource(R.drawable.ic_download);
Helper.setViewVisibility(root.findViewById(R.id.file_view_download_progress), View.GONE);
Helper.setViewVisibility(root.findViewById(R.id.file_view_unsupported_container), View.GONE);
}
checkIsFileComplete();
restoreMainActionButton();
}
Aggregations