use of com.odysee.app.model.Comment 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.model.Comment in project odysee-android by OdyseeTeam.
the class Helper method filterCommentsByBlockedChannels.
public static List<Comment> filterCommentsByBlockedChannels(List<Comment> comments, List<LbryUri> blockedChannels) {
List<Comment> filtered = new ArrayList<>();
List<String> blockedChannelClaimIds = new ArrayList<>();
for (LbryUri uri : blockedChannels) {
blockedChannelClaimIds.add(uri.getClaimId());
}
for (Comment comment : comments) {
if (comment.getPoster() == null || blockedChannelClaimIds.contains(comment.getPoster().getClaimId())) {
continue;
}
filtered.add(comment);
}
return filtered;
}
use of com.odysee.app.model.Comment in project odysee-android by OdyseeTeam.
the class FileViewFragment method buildPostComment.
private Comment buildPostComment() {
Claim actualClaim = collectionClaimItem != null ? collectionClaimItem : fileClaim;
Comment comment = new Comment();
Claim channel = (Claim) commentChannelSpinner.getSelectedItem();
comment.setClaimId(actualClaim.getClaimId());
comment.setChannelId(channel.getClaimId());
comment.setChannelName(channel.getName());
comment.setText(Helper.getValue(inputComment.getText()));
comment.setPoster(channel);
if (replyToComment != null) {
comment.setParentId(replyToComment.getId());
}
return comment;
}
use of com.odysee.app.model.Comment in project odysee-android by OdyseeTeam.
the class FileViewFragment method loadReactions.
private Map<String, Reactions> loadReactions(List<Comment> comments) {
List<String> commentIds = new ArrayList<>();
for (Comment c : comments) {
commentIds.add(c.getId());
}
ExecutorService executor = Executors.newSingleThreadExecutor();
Future<Map<String, Reactions>> future = executor.submit(() -> {
Comments.checkCommentsEndpointStatus();
JSONObject jsonParams = new JSONObject();
jsonParams.put("comment_ids", TextUtils.join(",", commentIds));
AccountManager am = AccountManager.get(getContext());
Account odyseeAccount = Helper.getOdyseeAccount(am.getAccounts());
if (odyseeAccount != null) {
jsonParams.put("auth_token", am.peekAuthToken(odyseeAccount, "auth_token_type"));
}
if (!Lbry.ownChannels.isEmpty()) {
jsonParams.put("channel_id", Lbry.ownChannels.get(0).getClaimId());
jsonParams.put("channel_name", Lbry.ownChannels.get(0).getName());
try {
JSONObject jsonChannelSign = Comments.channelSignName(jsonParams, jsonParams.getString("channel_id"), jsonParams.getString("channel_name"));
if (jsonChannelSign.has("signature") && jsonChannelSign.has("signing_ts")) {
jsonParams.put("signature", jsonChannelSign.getString("signature"));
jsonParams.put("signing_ts", jsonChannelSign.getString("signing_ts"));
}
} catch (ApiCallException | JSONException e) {
e.printStackTrace();
}
}
Map<String, Reactions> result = new HashMap<>();
try {
Response response = Comments.performRequest(jsonParams, "reaction.List");
String responseString = response.body().string();
response.close();
JSONObject jsonResponse = new JSONObject(responseString);
if (jsonResponse.has("result")) {
JSONObject jsonResult = jsonResponse.getJSONObject("result");
if (jsonResult.has("others_reactions")) {
JSONObject responseOthersReactions = jsonResult.getJSONObject("others_reactions");
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
responseOthersReactions.keys().forEachRemaining(key -> {
try {
result.put(key, getMyReactions(jsonResult, responseOthersReactions, key));
} catch (JSONException e) {
e.printStackTrace();
}
});
} else {
// Android versions prior to API 24 lack forEachRemaining()
Iterator<String> itr = responseOthersReactions.keys();
while (itr.hasNext()) {
try {
String nextKey = itr.next();
result.put(nextKey, getMyReactions(jsonResult, responseOthersReactions, nextKey));
} catch (JSONException e) {
Log.e(TAG, "loadReactions for Comment: ".concat(e.getLocalizedMessage()));
}
}
}
}
}
} catch (IOException e) {
e.printStackTrace();
}
return result;
});
try {
return future.get();
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
return null;
}
}
use of com.odysee.app.model.Comment in project odysee-android by OdyseeTeam.
the class ChannelCommentsFragment method ensureCommentListAdapterCreated.
private void ensureCommentListAdapterCreated(final List<Comment> comments) {
if (commentListAdapter == null) {
Context ctx = getContext();
View root = getView();
commentListAdapter = new CommentListAdapter(comments, ctx, claim, new CommentListAdapter.CommentListListener() {
@Override
public void onListChanged() {
checkNoComments();
}
@Override
public void onCommentReactClicked(Comment c, boolean liked) {
// Not used for now.
}
@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("@") && ctx instanceof MainActivity) {
((MainActivity) ctx).openChannelClaim(claim);
}
}
});
RecyclerView commentList = root.findViewById(R.id.channel_comments_list);
int marginInPx = Math.round(40 * ((float) ctx.getResources().getDisplayMetrics().densityDpi / DisplayMetrics.DENSITY_DEFAULT));
commentList.addItemDecoration(new CommentItemDecoration(marginInPx));
commentList.setAdapter(commentListAdapter);
commentListAdapter.notifyItemRangeInserted(0, comments.size());
commentListAdapter.setCollapsed(false);
checkNoComments();
resolveCommentPosters();
scrollToCommentHash();
}
}
Aggregations