use of com.odysee.app.model.Claim in project odysee-android by OdyseeTeam.
the class ChannelFragment method onCreateView.
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_channel, container, false);
layoutLoadingState = root.findViewById(R.id.channel_view_loading_state);
layoutNothingAtLocation = root.findViewById(R.id.container_nothing_at_location);
layoutDisplayArea = root.findViewById(R.id.channel_view_claim_display_area);
layoutResolving = root.findViewById(R.id.channel_view_loading_container);
imageCover = root.findViewById(R.id.channel_view_cover_image);
imageThumbnail = root.findViewById(R.id.channel_view_thumbnail);
noThumbnailView = root.findViewById(R.id.channel_view_no_thumbnail);
textAlpha = root.findViewById(R.id.channel_view_icon_alpha);
textTitle = root.findViewById(R.id.channel_view_title);
textFollowerCount = root.findViewById(R.id.channel_view_follower_count);
buttonEdit = root.findViewById(R.id.channel_view_edit);
buttonDelete = root.findViewById(R.id.channel_view_delete);
buttonShare = root.findViewById(R.id.channel_view_share);
buttonTip = root.findViewById(R.id.channel_view_tip);
buttonReport = root.findViewById(R.id.channel_view_report);
buttonFollowUnfollow = root.findViewById(R.id.channel_view_follow_unfollow);
textFollow = root.findViewById(R.id.channel_view_text_follow);
iconFollow = root.findViewById(R.id.channel_view_icon_follow);
iconUnfollow = root.findViewById(R.id.channel_view_icon_unfollow);
buttonBell = root.findViewById(R.id.channel_view_subscribe_notify);
iconBell = root.findViewById(R.id.channel_view_icon_bell);
blockUnblock = root.findViewById(R.id.channel_view_block_unblock);
blockUnblockText = root.findViewById(R.id.channel_view_block_unblock_text);
blockUnblock.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
boolean blocked = Lbryio.isChannelBlocked(claim);
Context context = getContext();
if (context instanceof MainActivity) {
if (blocked) {
// handle unblock
((MainActivity) context).handleUnblockChannel(claim);
} else {
((MainActivity) context).handleBlockChannel(claim);
}
}
}
});
tabPager = root.findViewById(R.id.channel_view_pager);
tabLayout = root.findViewById(R.id.channel_view_tabs);
tabPager.setSaveEnabled(false);
buttonEdit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (claim != null) {
Context context = getContext();
if (context instanceof MainActivity) {
((MainActivity) context).openChannelForm(claim);
}
}
}
});
buttonDelete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (claim != null) {
Context c = getContext();
if (c != null) {
AlertDialog.Builder builder = new AlertDialog.Builder(c).setTitle(R.string.delete_channel).setMessage(R.string.confirm_delete_channel).setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
deleteCurrentClaim();
}
}).setNegativeButton(R.string.no, null);
builder.show();
}
}
}
});
buttonShare.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (claim != null) {
try {
String shareUrl = LbryUri.parse(!Helper.isNullOrEmpty(claim.getCanonicalUrl()) ? claim.getCanonicalUrl() : (!Helper.isNullOrEmpty(claim.getShortUrl()) ? claim.getShortUrl() : claim.getPermanentUrl())).toOdyseeString();
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT, shareUrl);
MainActivity.startingShareActivity = true;
Intent shareUrlIntent = Intent.createChooser(shareIntent, getString(R.string.share_lbry_content));
shareUrlIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(shareUrlIntent);
} catch (LbryUriException ex) {
// pass
}
}
}
});
buttonTip.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
MainActivity activity = (MainActivity) getActivity();
if (activity != null && activity.isSignedIn()) {
if (claim != null) {
CreateSupportDialogFragment dialog = CreateSupportDialogFragment.newInstance(claim, (amount, isTip) -> {
double sentAmount = amount.doubleValue();
View view1 = getView();
if (view1 != null) {
String message = getResources().getQuantityString(isTip ? R.plurals.you_sent_a_tip : R.plurals.you_sent_a_support, sentAmount == 1.0 ? 1 : 2, new DecimalFormat("#,###.##").format(sentAmount));
Snackbar.make(view1, message, Snackbar.LENGTH_LONG).show();
}
});
Context context = getContext();
if (context instanceof MainActivity) {
dialog.show(((MainActivity) context).getSupportFragmentManager(), CreateSupportDialogFragment.TAG);
}
}
} else {
if (activity != null) {
activity.simpleSignIn(0);
}
}
}
});
buttonReport.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (claim != null) {
Context context = getContext();
CustomTabColorSchemeParams.Builder ctcspb = new CustomTabColorSchemeParams.Builder();
ctcspb.setToolbarColor(ContextCompat.getColor(context, R.color.colorPrimary));
CustomTabColorSchemeParams ctcsp = ctcspb.build();
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder().setDefaultColorSchemeParams(ctcsp);
CustomTabsIntent intent = builder.build();
intent.launchUrl(context, Uri.parse(String.format("https://odysee.com/$/report_content?claimId=%s", claim.getClaimId())));
}
}
});
buttonBell.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (claim != null) {
boolean isNotificationsDisabled = Lbryio.isNotificationsDisabled(claim);
final Subscription subscription = Subscription.fromClaim(claim);
subscription.setNotificationsDisabled(!isNotificationsDisabled);
view.setEnabled(false);
Context context = getContext();
new ChannelSubscribeTask(context, claim.getClaimId(), subscription, false, new ChannelSubscribeTask.ChannelSubscribeHandler() {
@Override
public void onSuccess() {
view.setEnabled(true);
Lbryio.updateSubscriptionNotificationsDisabled(subscription);
Context context = getContext();
if (context instanceof MainActivity) {
((MainActivity) context).showMessage(subscription.isNotificationsDisabled() ? R.string.receive_no_notifications : R.string.receive_all_notifications);
}
checkIsFollowing();
if (context != null) {
context.sendBroadcast(new Intent(MainActivity.ACTION_SAVE_SHARED_USER_STATE));
}
}
@Override
public void onError(Exception exception) {
view.setEnabled(true);
}
}).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
});
buttonFollowUnfollow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
MainActivity activity = (MainActivity) getActivity();
if (activity != null && activity.isSignedIn()) {
if (claim != null) {
if (subscribing) {
return;
}
boolean isFollowing = Lbryio.isFollowing(claim);
if (isFollowing) {
Context context = getContext();
if (context != null) {
AlertDialog.Builder builder = new AlertDialog.Builder(context).setTitle(R.string.confirm_unfollow).setMessage(R.string.confirm_unfollow_message).setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
doFollowUnfollow(isFollowing, view);
}
}).setNegativeButton(R.string.no, null);
builder.show();
}
} else {
doFollowUnfollow(isFollowing, view);
}
}
} else {
if (activity != null) {
activity.simpleSignIn(0);
}
}
}
});
return root;
}
use of com.odysee.app.model.Claim in project odysee-android by OdyseeTeam.
the class ChannelFragment method resolveUrl.
private void resolveUrl() {
Helper.setViewVisibility(layoutDisplayArea, View.INVISIBLE);
Helper.setViewVisibility(layoutLoadingState, View.VISIBLE);
ResolveTask task = new ResolveTask(currentUrl, Lbry.API_CONNECTION_STRING, layoutResolving, new ClaimListResultHandler() {
@Override
public void onSuccess(List<Claim> claims) {
if (claims.size() > 0 && !Helper.isNullOrEmpty(claims.get(0).getClaimId())) {
claim = claims.get(0);
if (!Helper.isNullOrEmpty(currentUrl)) {
Helper.saveUrlHistory(currentUrl, claim.getTitle(), UrlSuggestion.TYPE_CHANNEL);
}
renderClaim();
checkOwnChannel();
} else {
renderNothingAtLocation();
}
}
@Override
public void onError(Exception error) {
renderNothingAtLocation();
}
});
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
use of com.odysee.app.model.Claim 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.Claim in project odysee-android by OdyseeTeam.
the class ChannelManagerFragment method handleDeleteSelectedClaims.
private void handleDeleteSelectedClaims(List<Claim> selectedClaims) {
List<String> claimIds = new ArrayList<>();
for (Claim claim : selectedClaims) {
claimIds.add(claim.getClaimId());
}
if (actionMode != null) {
actionMode.finish();
}
Helper.setViewVisibility(channelList, View.INVISIBLE);
Helper.setViewVisibility(fabNewChannel, View.INVISIBLE);
AbandonChannelTask task = new AbandonChannelTask(claimIds, bigLoading, Lbryio.AUTH_TOKEN, new AbandonHandler() {
@Override
public void onComplete(List<String> successfulClaimIds, List<String> failedClaimIds, List<Exception> errors) {
View root = getView();
if (root != null) {
if (failedClaimIds.size() > 0) {
Snackbar.make(root, R.string.one_or_more_channels_failed_abandon, Snackbar.LENGTH_LONG).setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show();
} else if (successfulClaimIds.size() == claimIds.size()) {
try {
String message = getResources().getQuantityString(R.plurals.channels_deleted, successfulClaimIds.size());
Snackbar.make(root, message, Snackbar.LENGTH_LONG).show();
} catch (IllegalStateException ex) {
// pass
}
}
}
Lbry.abandonedClaimIds.addAll(successfulClaimIds);
if (adapter != null) {
adapter.setItems(Helper.filterDeletedClaims(adapter.getItems()));
}
Helper.setViewVisibility(channelList, View.VISIBLE);
Helper.setViewVisibility(fabNewChannel, View.VISIBLE);
checkNoChannels();
}
});
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
use of com.odysee.app.model.Claim in project odysee-android by OdyseeTeam.
the class ChannelManagerFragment method onActionItemClicked.
@Override
public boolean onActionItemClicked(androidx.appcompat.view.ActionMode actionMode, MenuItem menuItem) {
if (R.id.action_edit == menuItem.getItemId()) {
if (adapter != null && adapter.getSelectedCount() > 0) {
Claim claim = adapter.getSelectedItems().get(0);
// start channel editor with the claim
Context context = getContext();
if (context instanceof MainActivity) {
Map<String, Object> params = new HashMap<>();
params.put("claim", claim);
((MainActivity) context).openFragment(ChannelFormFragment.class, true, params);
}
actionMode.finish();
return true;
}
}
if (R.id.action_delete == menuItem.getItemId()) {
if (adapter != null && adapter.getSelectedCount() > 0) {
final List<Claim> selectedClaims = new ArrayList<>(adapter.getSelectedItems());
String message = getResources().getQuantityString(R.plurals.confirm_delete_channels, selectedClaims.size());
Context c = getContext();
if (c != null) {
AlertDialog.Builder builder = new AlertDialog.Builder(c).setTitle(R.string.delete_selection).setMessage(message).setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
handleDeleteSelectedClaims(selectedClaims);
}
}).setNegativeButton(R.string.no, null);
builder.show();
}
return true;
}
}
return false;
}
Aggregations