use of com.odysee.app.model.Claim in project odysee-android by OdyseeTeam.
the class MainActivity method fetchOwnClaims.
public void fetchOwnClaims() {
ClaimListTask task = new ClaimListTask(Arrays.asList(Claim.TYPE_STREAM, Claim.TYPE_REPOST), null, new ClaimListResultHandler() {
@Override
public void onSuccess(List<Claim> claims) {
Lbry.ownClaims = Helper.filterDeletedClaims(new ArrayList<>(claims));
for (FetchClaimsListener listener : fetchClaimsListeners) {
listener.onClaimsFetched(claims);
}
}
@Override
public void onError(Exception error) {
}
});
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
use of com.odysee.app.model.Claim in project odysee-android by OdyseeTeam.
the class ClaimListAdapter method setItems.
public void setItems(List<Claim> claims) {
if (items.size() > 0)
notifyItemRangeRemoved(0, items.size());
items = new ArrayList<>();
for (Claim claim : claims) {
if (claim != null) {
items.add(claim);
}
}
notifyItemRangeInserted(0, items.size());
}
use of com.odysee.app.model.Claim in project odysee-android by OdyseeTeam.
the class ClaimListAdapter method onBindViewHolder.
@SuppressLint("UseCompatLoadingForDrawables")
@Override
public void onBindViewHolder(ClaimListAdapter.ViewHolder vh, int position) {
int type = getItemViewType(position);
if (style == STYLE_SMALL_LIST) {
int paddingTop = position == 0 ? 16 : 8;
int paddingBottom = position == getItemCount() - 1 ? 16 : 8;
int paddingTopScaled = Helper.getScaledValue(paddingTop, scale);
int paddingBottomScaled = Helper.getScaledValue(paddingBottom, scale);
vh.itemView.setPadding(vh.itemView.getPaddingStart(), paddingTopScaled, vh.itemView.getPaddingEnd(), paddingBottomScaled);
} else if (style == STYLE_SMALL_LIST_HORIZONTAL) {
int paddingStart = position == 0 ? 16 : 8;
int paddingEnd = position == getItemCount() - 1 ? 16 : 8;
int paddingStartScaled = Helper.getScaledValue(paddingStart, scale);
int paddingEndScaled = Helper.getScaledValue(paddingEnd, scale);
vh.itemView.setPadding(paddingStartScaled, vh.itemView.getPaddingTop(), paddingEndScaled, vh.itemView.getPaddingBottom());
}
Claim original = items.get(position);
boolean isRepost = Claim.TYPE_REPOST.equalsIgnoreCase(original.getValueType());
final Claim item = Claim.TYPE_REPOST.equalsIgnoreCase(original.getValueType()) ? (original.getRepostedClaim() != null ? original.getRepostedClaim() : original) : original;
Claim.GenericMetadata metadata = item.getValue();
Claim signingChannel = item.getSigningChannel();
Claim.StreamMetadata streamMetadata = null;
if (metadata instanceof Claim.StreamMetadata) {
streamMetadata = (Claim.StreamMetadata) metadata;
}
String thumbnailUrl = item.getThumbnailUrl(vh.thumbnailView.getLayoutParams().width, vh.thumbnailView.getLayoutParams().height, 85);
long publishTime = (streamMetadata != null && streamMetadata.getReleaseTime() > 0) ? streamMetadata.getReleaseTime() * 1000 : item.getTimestamp() * 1000;
int bgColor = Helper.generateRandomColorForValue(item.getClaimId());
if (bgColor == 0) {
bgColor = Helper.generateRandomColorForValue(item.getName());
}
boolean isPending = item.getConfirmations() == 0;
boolean isSelected = isClaimSelected(original);
vh.itemView.setSelected(isSelected);
vh.setContextGroupId(contextGroupId);
vh.selectedOverlayView.setVisibility(isSelected ? View.VISIBLE : View.GONE);
vh.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (isPending) {
Snackbar snackbar = Snackbar.make(vh.itemView, R.string.item_pending_blockchain, Snackbar.LENGTH_LONG);
TextView snackbarText = snackbar.getView().findViewById(com.google.android.material.R.id.snackbar_text);
snackbarText.setMaxLines(5);
snackbar.show();
return;
}
if (inSelectionMode) {
toggleSelectedClaim(original);
} else {
if (listener != null) {
listener.onClaimClicked(item, position);
}
}
}
});
vh.itemView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
if (!canEnterSelectionMode) {
return false;
}
if (isPending) {
Snackbar snackbar = Snackbar.make(vh.itemView, R.string.item_pending_blockchain, Snackbar.LENGTH_LONG);
TextView snackbarText = snackbar.getView().findViewById(com.google.android.material.R.id.snackbar_text);
snackbarText.setMaxLines(5);
snackbar.show();
return false;
}
if (!inSelectionMode) {
inSelectionMode = true;
if (selectionModeListener != null) {
selectionModeListener.onEnterSelectionMode();
}
}
toggleSelectedClaim(original);
return true;
}
});
vh.publisherView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (listener != null && signingChannel != null) {
listener.onClaimClicked(signingChannel, position);
}
}
});
vh.publishTimeView.setVisibility(!isPending && style != STYLE_SMALL_LIST_HORIZONTAL ? View.VISIBLE : View.GONE);
vh.pendingTextView.setVisibility(isPending && !item.isLoadingPlaceholder() ? View.VISIBLE : View.GONE);
vh.repostInfoView.setVisibility(isRepost && type != VIEW_TYPE_FEATURED ? View.VISIBLE : View.GONE);
vh.repostChannelView.setText(isRepost && original.getSigningChannel() != null ? original.getSigningChannel().getName() : null);
vh.repostChannelView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (listener != null) {
listener.onClaimClicked(original.getSigningChannel(), position);
}
}
});
if (vh.optionsMenuView != null) {
vh.optionsMenuView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
setPosition(vh.getBindingAdapterPosition());
view.showContextMenu();
}
});
}
vh.titleView.setText(Helper.isNullOrEmpty(item.getTitle()) ? item.getName() : item.getTitle());
if (type == VIEW_TYPE_FEATURED) {
LbryUri vanityUrl = new LbryUri();
vanityUrl.setClaimName(item.getName());
vh.vanityUrlView.setText(vanityUrl.toString());
}
vh.feeContainer.setVisibility(item.isUnresolved() || !Claim.TYPE_STREAM.equalsIgnoreCase(item.getValueType()) ? View.GONE : View.VISIBLE);
vh.noThumbnailView.setVisibility(Helper.isNullOrEmpty(thumbnailUrl) ? View.VISIBLE : View.GONE);
Helper.setIconViewBackgroundColor(vh.noThumbnailView, bgColor, false, context);
Helper.setViewVisibility(vh.loadingImagePlaceholder, item.isLoadingPlaceholder() ? View.VISIBLE : View.GONE);
Helper.setViewVisibility(vh.loadingTextPlaceholder1, item.isLoadingPlaceholder() ? View.VISIBLE : View.GONE);
Helper.setViewVisibility(vh.loadingTextPlaceholder2, item.isLoadingPlaceholder() ? View.VISIBLE : View.GONE);
Helper.setViewVisibility(vh.titleView, !item.isLoadingPlaceholder() ? View.VISIBLE : View.GONE);
Helper.setViewVisibility(vh.publisherView, !item.isLoadingPlaceholder() ? View.VISIBLE : View.GONE);
Helper.setViewVisibility(vh.publishTimeView, !item.isLoadingPlaceholder() && !isPending && style != STYLE_SMALL_LIST_HORIZONTAL ? View.VISIBLE : View.GONE);
if (type == VIEW_TYPE_FEATURED && item.isUnresolved()) {
vh.durationView.setVisibility(View.GONE);
vh.titleView.setText("Nothing here. Publish something!");
String name = item.getName();
if (!Helper.isNullOrEmpty(name)) {
vh.alphaView.setText(name.substring(0, Math.min(5, name.length() - 1)));
}
} else {
ViewGroup.LayoutParams lp = vh.itemView.getLayoutParams();
if (Claim.TYPE_STREAM.equalsIgnoreCase(item.getValueType()) || Claim.TYPE_COLLECTION.equalsIgnoreCase(item.getValueType())) {
if ((filterTimeframeFrom == 0 || publishTime >= filterTimeframeFrom) && shouldDisplayClaim(item)) {
if (!Helper.isNullOrEmpty(thumbnailUrl)) {
Glide.with(context.getApplicationContext()).asBitmap().load(thumbnailUrl).placeholder(R.drawable.bg_thumbnail_placeholder).into(vh.thumbnailView);
vh.thumbnailView.setVisibility(View.VISIBLE);
} else {
vh.thumbnailView.setVisibility(View.GONE);
}
BigDecimal cost = item.getActualCost(Lbryio.LBCUSDRate);
vh.feeContainer.setVisibility(cost.doubleValue() > 0 && !hideFee ? View.VISIBLE : View.GONE);
vh.feeView.setText(cost.doubleValue() > 0 ? Helper.shortCurrencyFormat(cost.doubleValue()) : "Paid");
vh.alphaView.setText(item.getName().substring(0, Math.min(5, item.getName().length() - 1)));
vh.publisherView.setText(signingChannel != null ? signingChannel.getName() : context.getString(R.string.anonymous));
vh.publishTimeView.setText(DateUtils.getRelativeTimeSpanString(publishTime, System.currentTimeMillis(), 0, DateUtils.FORMAT_ABBREV_RELATIVE));
long duration = item.getDuration();
vh.durationView.setVisibility((duration > 0 || item.isLive() || Claim.TYPE_COLLECTION.equalsIgnoreCase(item.getValueType())) ? View.VISIBLE : View.GONE);
if (item.isLive() && !Claim.TYPE_COLLECTION.equalsIgnoreCase(item.getValueType())) {
vh.durationView.setBackgroundColor(ContextCompat.getColor(context, R.color.colorAccent));
vh.durationView.setText(context.getResources().getString(R.string.live).toUpperCase());
} else {
vh.durationView.setBackgroundColor(ContextCompat.getColor(context, android.R.color.black));
if (!Claim.TYPE_COLLECTION.equalsIgnoreCase(item.getValueType())) {
vh.durationView.setText(Helper.formatDuration(duration));
vh.durationView.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, 0, 0);
} else {
List<String> claimIds = item.getClaimIds() == null ? new ArrayList<>() : item.getClaimIds();
vh.durationView.setText(String.valueOf(claimIds.size()));
vh.durationView.setCompoundDrawablesRelativeWithIntrinsicBounds(R.drawable.ic_list_icon, 0, 0, 0);
vh.durationView.setCompoundDrawablePadding(8);
}
LbryFile claimFile = item.getFile();
boolean isDownloading = false;
int progress = 0;
String fileSizeString = claimFile == null ? null : Helper.formatBytes(claimFile.getTotalBytes(), false);
if (claimFile != null && !Helper.isNullOrEmpty(claimFile.getDownloadPath()) && !claimFile.isCompleted() && claimFile.getWrittenBytes() < claimFile.getTotalBytes()) {
isDownloading = true;
progress = claimFile.getTotalBytes() > 0 ? Double.valueOf(((double) claimFile.getWrittenBytes() / (double) claimFile.getTotalBytes()) * 100.0).intValue() : 0;
fileSizeString = String.format("%s / %s", Helper.formatBytes(claimFile.getWrittenBytes(), false), Helper.formatBytes(claimFile.getTotalBytes(), false));
}
Helper.setViewText(vh.fileSizeView, claimFile != null && !Helper.isNullOrEmpty(claimFile.getDownloadPath()) ? fileSizeString : null);
Helper.setViewVisibility(vh.downloadProgressView, isDownloading ? View.VISIBLE : View.INVISIBLE);
Helper.setViewProgress(vh.downloadProgressView, progress);
Helper.setViewText(vh.deviceView, item.getDevice());
lp.height = ViewGroup.LayoutParams.WRAP_CONTENT;
vh.itemView.setLayoutParams(lp);
vh.itemView.setVisibility(View.VISIBLE);
if (style != STYLE_SMALL_LIST_HORIZONTAL) {
lp.width = ViewGroup.LayoutParams.MATCH_PARENT;
}
}
} else {
vh.itemView.setVisibility(View.GONE);
lp.height = 0;
lp.width = 0;
vh.itemView.setLayoutParams(lp);
}
} else if (Claim.TYPE_CHANNEL.equalsIgnoreCase(item.getValueType())) {
if ((this.filterByChannel || !this.filterByFile) && (filterTimeframeFrom == 0 || publishTime >= filterTimeframeFrom)) {
if (!Helper.isNullOrEmpty(thumbnailUrl)) {
Glide.with(context.getApplicationContext()).load(thumbnailUrl).centerCrop().placeholder(R.drawable.bg_thumbnail_placeholder).apply(RequestOptions.circleCropTransform()).into(vh.thumbnailView);
}
vh.alphaView.setText(item.getName().substring(1, 2).toUpperCase());
vh.publisherView.setText(item.getName());
vh.publishTimeView.setText(DateUtils.getRelativeTimeSpanString(publishTime, System.currentTimeMillis(), 0, DateUtils.FORMAT_ABBREV_RELATIVE));
lp.height = ViewGroup.LayoutParams.WRAP_CONTENT;
lp.width = ViewGroup.LayoutParams.MATCH_PARENT;
vh.itemView.setLayoutParams(lp);
vh.itemView.setVisibility(View.VISIBLE);
} else {
vh.itemView.setVisibility(View.GONE);
lp.height = 0;
lp.width = 0;
vh.itemView.setLayoutParams(lp);
}
}
}
}
use of com.odysee.app.model.Claim in project odysee-android by OdyseeTeam.
the class ClaimListAdapter method setItem.
public void setItem(String claimId, Claim claim) {
if (claim != null) {
Claim r = this.items.stream().filter(o -> o.getClaimId() != null && o.getClaimId().equalsIgnoreCase(claimId)).findFirst().orElse(null);
if (r != null) {
int position = this.items.indexOf(r);
items.set(this.items.indexOf(r), claim);
notifyItemChanged(position, claim);
}
}
}
use of com.odysee.app.model.Claim in project odysee-android by OdyseeTeam.
the class ClaimListAdapter method clearFileForClaimOrUrl.
public void clearFileForClaimOrUrl(String outpoint, String url, boolean remove) {
int claimIndex = -1;
for (int i = 0; i < items.size(); i++) {
Claim claim = items.get(i);
if (outpoint.equalsIgnoreCase(claim.getOutpoint()) || url.equalsIgnoreCase(claim.getPermanentUrl())) {
claimIndex = i;
claim.setFile(null);
break;
}
}
if (remove && claimIndex > -1) {
Claim removed = items.remove(claimIndex);
selectedItems.remove(removed);
}
notifyDataSetChanged();
}
Aggregations