use of com.odysee.app.MainActivity in project odysee-android by OdyseeTeam.
the class FileViewFragment method ensureCommentListAdapterCreated.
private void ensureCommentListAdapterCreated(final List<Comment> comments) {
Claim actualClaim = collectionClaimItem != null ? collectionClaimItem : fileClaim;
if (commentListAdapter == null) {
final Context androidContext = getContext();
final View root = getView();
commentListAdapter = new CommentListAdapter(comments, getContext(), actualClaim, new CommentListAdapter.CommentListListener() {
@Override
public void onListChanged() {
checkNoComments();
}
@Override
public void onCommentReactClicked(Comment c, boolean liked) {
react(c, liked);
}
@Override
public void onReplyClicked(Comment comment) {
setReplyToComment(comment);
}
});
commentListAdapter.setListener(new ClaimListAdapter.ClaimListItemListener() {
@Override
public void onClaimClicked(Claim claim, int position) {
if (!Helper.isNullOrEmpty(claim.getName()) && claim.getName().startsWith("@") && androidContext instanceof MainActivity) {
removeNotificationAsSource();
((MainActivity) androidContext).openChannelClaim(claim);
}
}
});
RecyclerView commentsList = root.findViewById(R.id.file_view_comments_list);
// Indent reply-type items
int marginInPx = Math.round(40 * ((float) androidContext.getResources().getDisplayMetrics().densityDpi / DisplayMetrics.DENSITY_DEFAULT));
commentsList.addItemDecoration(new CommentItemDecoration(marginInPx));
commentsList.setAdapter(commentListAdapter);
commentListAdapter.notifyItemRangeInserted(0, comments.size());
scrollToCommentHash();
checkNoComments();
resolveCommentPosters();
}
}
use of com.odysee.app.MainActivity in project odysee-android by OdyseeTeam.
the class FileViewFragment method checkParams.
private void checkParams() {
boolean updateRequired = false;
Context context = getContext();
// claim.setClaimId(FileViewFragmentArgs.fromBundle(getArguments()).getClaimId());
try {
Map<String, Object> params = getParams();
Claim newClaim = null;
String newUrl = null;
if (params != null) {
if (params.containsKey("collection")) {
handlePlayCollection(params);
return;
}
if (params.containsKey("claim")) {
newClaim = (Claim) params.get("claim");
// Only update fragment if new claim is different than currently being played
if (newClaim != null && !newClaim.equals(this.fileClaim)) {
updateRequired = true;
}
}
if (params.containsKey("url")) {
LbryUri newLbryUri = LbryUri.tryParse(params.get("url").toString());
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 (fileClaim == null || !newUrl.equalsIgnoreCase(currentUrl)) {
updateRequired = true;
}
}
}
} else if (currentUrl != null) {
updateRequired = true;
} else if (context instanceof MainActivity) {
((MainActivity) context).onBackPressed();
}
boolean invalidRepost = false;
if (updateRequired) {
resetViewCount();
resetFee();
checkNewClaimAndUrl(newClaim, newUrl);
// This is required to recycle current fragment with new claim from related content
fileClaim = null;
if (newClaim != null) {
fileClaim = newClaim;
}
if (fileClaim == null && !Helper.isNullOrEmpty(newUrl)) {
// check if the claim is already cached
currentUrl = newUrl;
ClaimCacheKey key = new ClaimCacheKey();
key.setUrl(currentUrl);
onNewClaim(currentUrl);
if (Lbry.claimCache.containsKey(key)) {
fileClaim = Lbry.claimCache.get(key);
}
}
if (fileClaim != null && Claim.TYPE_REPOST.equalsIgnoreCase(fileClaim.getValueType())) {
fileClaim = fileClaim.getRepostedClaim();
if (fileClaim == null || Helper.isNullOrEmpty(fileClaim.getClaimId())) {
// Invalid repost, probably
invalidRepost = true;
renderNothingAtLocation();
} else if (fileClaim.getName().startsWith("@")) {
// this is a reposted channel, so launch the channel url
if (context instanceof MainActivity) {
MainActivity activity = (MainActivity) context;
// activity.onBackPressed(); // remove the reposted url page from the back stack
activity.getSupportFragmentManager().popBackStack();
activity.openChannelUrl(!Helper.isNullOrEmpty(fileClaim.getShortUrl()) ? fileClaim.getShortUrl() : fileClaim.getPermanentUrl());
}
return;
}
}
if (fileClaim == null) {
resolveUrl(currentUrl);
}
} else {
checkAndResetNowPlayingClaim();
}
if (!Helper.isNullOrEmpty(currentUrl)) {
Helper.saveUrlHistory(currentUrl, fileClaim != null ? fileClaim.getTitle() : null, UrlSuggestion.TYPE_FILE);
}
if (fileClaim != null && !invalidRepost) {
if (Claim.TYPE_COLLECTION.equalsIgnoreCase(fileClaim.getValueType()) && fileClaim.getClaimIds() != null && fileClaim.getClaimIds().size() > 0) {
resolvePlaylistClaimsAndPlayFirst();
return;
}
Claim actualClaim = collectionClaimItem != null ? collectionClaimItem : fileClaim;
if (!Claim.TYPE_COLLECTION.equalsIgnoreCase(actualClaim.getType())) {
// We don't want to save actual collections to the view history
Helper.saveViewHistory(currentUrl, actualClaim);
}
if (Helper.isClaimBlocked(actualClaim)) {
renderClaimBlocked();
} else {
checkAndLoadRelatedContent();
checkAndLoadComments();
renderClaim();
if (actualClaim.getFile() == null) {
loadFile();
} else {
// initialFileLoadDone = true;
}
}
}
checkIsFileComplete();
} catch (Exception ex) {
android.util.Log.e(TAG, ex.getMessage(), ex);
}
}
use of com.odysee.app.MainActivity in project odysee-android by OdyseeTeam.
the class FileViewFragment method relatedContentRequestSuccedded.
private void relatedContentRequestSuccedded(List<Claim> claims) {
Claim actualClaim = collectionClaimItem != null ? collectionClaimItem : fileClaim;
List<Claim> filteredClaims = new ArrayList<>();
for (Claim c : claims) {
if (!c.getClaimId().equalsIgnoreCase(actualClaim.getClaimId())) {
filteredClaims.add(c);
}
}
filteredClaims = Helper.filterClaimsByBlockedChannels(filteredClaims, Lbryio.blockedChannels);
Context ctx = getContext();
if (ctx != null) {
relatedContentAdapter.setItems(filteredClaims);
relatedContentAdapter.setListener(new ClaimListAdapter.ClaimListItemListener() {
@Override
public void onClaimClicked(Claim claim, int position) {
if (claim.isLoadingPlaceholder()) {
return;
}
if (ctx instanceof MainActivity) {
MainActivity activity = (MainActivity) ctx;
if (claim.getName().startsWith("@")) {
activity.openChannelClaim(claim);
} else {
Map<String, Object> params = new HashMap<>(1);
params.put("url", !Helper.isNullOrEmpty(claim.getShortUrl()) ? claim.getShortUrl() : claim.getPermanentUrl());
setParams(params);
checkParams();
}
}
}
});
View v = getView();
if (v != null) {
View root = getView();
RecyclerView relatedContentList = root.findViewById(R.id.file_view_related_content_list);
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);
}
// if related content loads before comment, this will affect the scroll position
// so just ensure that we are at the correct position
scrollToCommentHash();
}
}
use of com.odysee.app.MainActivity in project odysee-android by OdyseeTeam.
the class TransactionHistoryFragment method onStart.
@Override
public void onStart() {
super.onStart();
MainActivity activity = (MainActivity) getContext();
if (activity != null) {
activity.hideSearchBar();
activity.setActionBarTitle(R.string.transaction_history);
}
}
use of com.odysee.app.MainActivity in project odysee-android by OdyseeTeam.
the class TransactionHistoryFragment method onResume.
@Override
public void onResume() {
super.onResume();
Context context = getContext();
if (context instanceof MainActivity) {
MainActivity activity = (MainActivity) context;
LbryAnalytics.setCurrentScreen(activity, "Transaction History", "TransactionHistory");
}
if (adapter != null && adapter.getItemCount() > 0 && transactionList != null) {
transactionList.setAdapter(adapter);
}
loadTransactions();
}
Aggregations