use of com.odysee.app.model.Claim in project odysee-android by OdyseeTeam.
the class PublishClaimTask method doInBackground.
protected Claim doInBackground(Void... params) {
Claim.StreamMetadata metadata = (Claim.StreamMetadata) claim.getValue();
DecimalFormat amountFormat = new DecimalFormat(Helper.SDK_AMOUNT_FORMAT, new DecimalFormatSymbols(Locale.US));
Map<String, Object> options = new HashMap<>();
options.put("blocking", true);
options.put("name", claim.getName());
options.put("bid", amountFormat.format(new BigDecimal(claim.getAmount()).doubleValue()));
options.put("title", Helper.isNullOrEmpty(claim.getTitle()) ? "" : claim.getTitle());
options.put("description", Helper.isNullOrEmpty(claim.getDescription()) ? "" : claim.getDescription());
options.put("thumbnail_url", Helper.isNullOrEmpty(claim.getThumbnailUrl()) ? "" : claim.getThumbnailUrl());
if (!Helper.isNullOrEmpty(filePath)) {
options.put("file_path", filePath);
}
if (claim.getTags() != null && claim.getTags().size() > 0) {
options.put("tags", new ArrayList<>(claim.getTags()));
}
if (metadata.getFee() != null) {
options.put("fee_currency", metadata.getFee().getCurrency());
options.put("fee_amount", amountFormat.format(new BigDecimal(metadata.getFee().getAmount()).doubleValue()));
}
if (claim.getSigningChannel() != null) {
options.put("channel_id", claim.getSigningChannel().getClaimId());
}
if (metadata.getLanguages() != null && metadata.getLanguages().size() > 0) {
options.put("languages", metadata.getLanguages());
}
if (!Helper.isNullOrEmpty(metadata.getLicense())) {
options.put("license", metadata.getLicense());
}
if (!Helper.isNullOrEmpty(metadata.getLicenseUrl())) {
options.put("license_url", metadata.getLicenseUrl());
}
if (metadata.getReleaseTime() > 0) {
options.put("release_time", metadata.getReleaseTime());
} else if (claim.getTimestamp() > 0) {
options.put("release_time", claim.getTimestamp());
} else {
options.put("release_time", Double.valueOf(Math.floor(System.currentTimeMillis() / 1000.0)).intValue());
}
Claim claimResult = null;
try {
JSONObject result = (JSONObject) Lbry.genericApiCall(Lbry.METHOD_PUBLISH, options);
if (result.has("outputs")) {
JSONArray outputs = result.getJSONArray("outputs");
for (int i = 0; i < outputs.length(); i++) {
JSONObject output = outputs.getJSONObject(i);
if (output.has("claim_id") && output.has("claim_op")) {
claimResult = Claim.claimFromOutput(output);
break;
}
}
}
} catch (ApiCallException | ClassCastException | JSONException ex) {
error = ex;
}
return claimResult;
}
use of com.odysee.app.model.Claim in project odysee-android by OdyseeTeam.
the class FileViewFragment method loadComments.
private void loadComments() {
Claim actualClaim = collectionClaimItem != null ? collectionClaimItem : fileClaim;
View root = getView();
if (root != null && actualClaim != null) {
ProgressBar commentsLoading = root.findViewById(R.id.file_view_comments_progress);
CommentListTask task = new CommentListTask(1, 200, actualClaim.getClaimId(), commentsLoading, new CommentListHandler() {
@Override
public void onSuccess(List<Comment> comments, boolean hasReachedEnd) {
if (!comments.isEmpty()) {
// Load and process comments reactions on a different thread so main thread is not blocked
Helper.setViewVisibility(commentsLoading, View.VISIBLE);
new Thread(new Runnable() {
@Override
public void run() {
Map<String, Reactions> commentReactions = loadReactions(comments);
Activity activity = getActivity();
if (activity != null) {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
Helper.setViewVisibility(commentsLoading, View.GONE);
processCommentReactions(comments, commentReactions);
}
});
}
}
}).start();
}
}
@Override
public void onError(Exception error) {
if (error != null) {
error.printStackTrace();
}
checkNoComments();
}
private void processCommentReactions(List<Comment> comments, Map<String, Reactions> commentReactions) {
for (Comment c : comments) {
if (commentReactions != null) {
c.setReactions(commentReactions.get(c.getId()));
} else {
c.setReactions(new Reactions(0, 0, false, false));
}
}
List<Comment> rootComments = new ArrayList<>();
for (Comment c : comments) {
if (c.getParentId() == null) {
rootComments.add(c);
}
}
if (commentReactions != null) {
Collections.sort(rootComments, new Comparator<Comment>() {
@Override
public int compare(Comment o1, Comment o2) {
int o1SelfLiked = (Lbryio.isSignedIn() && o1.getReactions() != null && o1.getReactions().isLiked()) ? 1 : 0;
int o2SelfLiked = (Lbryio.isSignedIn() && o2.getReactions() != null && o2.getReactions().isLiked()) ? 1 : 0;
int o1OtherLikes = o1.getReactions() != null ? o1.getReactions().getOthersLikes() : 0;
int o2OtherLikes = o2.getReactions() != null ? o2.getReactions().getOthersLikes() : 0;
return (o2OtherLikes + o2SelfLiked) - (o1OtherLikes + o1SelfLiked);
}
});
}
// Direct comments are now sorted by their amount of likes. We can now pick the
// one to be displayed as the collapsed single comment.
Comment singleComment = rootComments.get(0);
TextView commentText = singleCommentRoot.findViewById(R.id.comment_text);
ImageView thumbnailView = singleCommentRoot.findViewById(R.id.comment_thumbnail);
View noThumbnailView = singleCommentRoot.findViewById(R.id.comment_no_thumbnail);
TextView alphaView = singleCommentRoot.findViewById(R.id.comment_thumbnail_alpha);
commentText.setText(singleComment.getText());
commentText.setMaxLines(3);
commentText.setEllipsize(TextUtils.TruncateAt.END);
commentText.setClickable(true);
commentText.setTextIsSelectable(false);
boolean hasThumbnail = singleComment.getPoster() != null && !Helper.isNullOrEmpty(singleComment.getPoster().getThumbnailUrl());
thumbnailView.setVisibility(hasThumbnail ? View.VISIBLE : View.INVISIBLE);
noThumbnailView.setVisibility(!hasThumbnail ? View.VISIBLE : View.INVISIBLE);
int bgColor = Helper.generateRandomColorForValue(singleComment.getChannelId());
Helper.setIconViewBackgroundColor(noThumbnailView, bgColor, false, getContext());
if (hasThumbnail) {
Context ctx = getContext();
if (ctx != null) {
Context appCtx = ctx.getApplicationContext();
Glide.with(appCtx).asBitmap().load(singleComment.getPoster().getThumbnailUrl()).apply(RequestOptions.circleCropTransform()).into(thumbnailView);
}
}
alphaView.setText(singleComment.getChannelName() != null ? singleComment.getChannelName().substring(1, 2).toUpperCase() : null);
singleCommentRoot.findViewById(R.id.comment_actions_area).setVisibility(View.GONE);
singleCommentRoot.findViewById(R.id.comment_time).setVisibility(View.GONE);
singleCommentRoot.findViewById(R.id.comment_channel_name).setVisibility(View.GONE);
singleCommentRoot.findViewById(R.id.comment_more_options).setVisibility(View.GONE);
singleCommentRoot.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
expandButton.performClick();
}
});
List<Comment> parentComments = rootComments;
// rootComments.clear();
for (Comment c : comments) {
if (!parentComments.contains(c)) {
if (c.getParentId() != null) {
Comment item = parentComments.stream().filter(v -> c.getParentId().equalsIgnoreCase(v.getId())).findFirst().orElse(null);
if (item != null) {
parentComments.add(parentComments.indexOf(item) + 1, c);
}
}
}
}
comments = parentComments;
Context ctx = getContext();
View root = getView();
if (ctx != null && root != null) {
ensureCommentListAdapterCreated(comments);
}
}
});
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
use of com.odysee.app.model.Claim in project odysee-android by OdyseeTeam.
the class FileViewFragment method tryOpenFileOrFileGet.
private void tryOpenFileOrFileGet() {
Claim actualClaim = collectionClaimItem != null ? collectionClaimItem : fileClaim;
if (actualClaim != null) {
String claimId = actualClaim.getClaimId();
FileListTask task = new FileListTask(claimId, null, new FileListTask.FileListResultHandler() {
@Override
public void onSuccess(List<LbryFile> files, boolean hasReachedEnd) {
if (files.size() > 0) {
actualClaim.setFile(files.get(0));
handleMainActionForClaim();
checkIsFileComplete();
} else {
checkStoragePermissionAndFileGet();
}
}
@Override
public void onError(Exception error) {
checkStoragePermissionAndFileGet();
}
});
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
use of com.odysee.app.model.Claim in project odysee-android by OdyseeTeam.
the class FileViewFragment method onLandscapeOrientationEntered.
@Override
public void onLandscapeOrientationEntered() {
Context context = getContext();
if (context instanceof MainActivity) {
MainActivity activity = (MainActivity) context;
if (activity.isEnteringPIPMode() || activity.isInPictureInPictureMode()) {
return;
}
Claim actualClaim = collectionClaimItem != null ? collectionClaimItem : fileClaim;
if (actualClaim != null && actualClaim.isPlayable() && !activity.isInFullscreenMode()) {
enableFullScreenMode();
}
}
}
use of com.odysee.app.model.Claim in project odysee-android by OdyseeTeam.
the class FileViewFragment method fileGet.
private void fileGet(boolean save) {
if (getFileTask != null && getFileTask.getStatus() != AsyncTask.Status.FINISHED) {
return;
}
Claim actualClaim = collectionClaimItem != null ? collectionClaimItem : fileClaim;
getFileTask = new GetFileTask(actualClaim.getPermanentUrl(), save, null, new GetFileTask.GetFileHandler() {
@Override
public void beforeStart() {
}
@Override
public void onSuccess(LbryFile file, boolean saveFile) {
// queue the download
if (actualClaim != null) {
if (actualClaim.isFree()) {
// paid is handled differently
Bundle bundle = new Bundle();
bundle.putString("uri", currentUrl);
bundle.putString("paid", "false");
LbryAnalytics.logEvent(LbryAnalytics.EVENT_PURCHASE_URI, bundle);
}
if (!actualClaim.isPlayable()) {
logFileView(actualClaim.getPermanentUrl(), 0);
}
actualClaim.setFile(file);
playOrViewMedia();
}
}
@Override
public void onError(Exception error, boolean saveFile) {
try {
showError(getString(R.string.unable_to_view_url, currentUrl));
if (saveFile) {
onDownloadAborted();
}
restoreMainActionButton();
} catch (IllegalStateException ex) {
// pass
}
}
});
getFileTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Aggregations