Search in sources :

Example 11 with Comment

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();
    }
}
Also used : AttributeProviderContext(org.commonmark.renderer.html.AttributeProviderContext) Context(android.content.Context) Comment(com.odysee.app.model.Comment) ReactToComment(com.odysee.app.runnable.ReactToComment) CommentListAdapter(com.odysee.app.adapter.CommentListAdapter) MainActivity(com.odysee.app.MainActivity) CommentItemDecoration(com.odysee.app.adapter.CommentItemDecoration) SolidIconView(com.odysee.app.ui.controls.SolidIconView) PlayerView(com.google.android.exoplayer2.ui.PlayerView) NestedScrollView(androidx.core.widget.NestedScrollView) AdapterView(android.widget.AdapterView) RecyclerView(androidx.recyclerview.widget.RecyclerView) PhotoView(com.github.chrisbanes.photoview.PhotoView) ImageView(android.widget.ImageView) View(android.view.View) WebView(android.webkit.WebView) TextView(android.widget.TextView) ClaimListAdapter(com.odysee.app.adapter.ClaimListAdapter) SuppressLint(android.annotation.SuppressLint) RecyclerView(androidx.recyclerview.widget.RecyclerView) TrackSelectionOverride(com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride) Claim(com.odysee.app.model.Claim)

Example 12 with Comment

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;
}
Also used : Comment(com.odysee.app.model.Comment) ArrayList(java.util.ArrayList)

Example 13 with Comment

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;
}
Also used : Comment(com.odysee.app.model.Comment) ReactToComment(com.odysee.app.runnable.ReactToComment) Claim(com.odysee.app.model.Claim)

Example 14 with 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;
    }
}
Also used : Comment(com.odysee.app.model.Comment) ReactToComment(com.odysee.app.runnable.ReactToComment) Account(android.accounts.Account) ApiCallException(com.odysee.app.exceptions.ApiCallException) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Reactions(com.odysee.app.model.Reactions) JSONException(org.json.JSONException) IOException(java.io.IOException) Response(okhttp3.Response) JSONObject(org.json.JSONObject) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ExecutorService(java.util.concurrent.ExecutorService) AccountManager(android.accounts.AccountManager) ExecutionException(java.util.concurrent.ExecutionException) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap)

Example 15 with Comment

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();
    }
}
Also used : Context(android.content.Context) Comment(com.odysee.app.model.Comment) CommentListAdapter(com.odysee.app.adapter.CommentListAdapter) MainActivity(com.odysee.app.MainActivity) CommentItemDecoration(com.odysee.app.adapter.CommentItemDecoration) NestedScrollView(androidx.core.widget.NestedScrollView) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) ClaimListAdapter(com.odysee.app.adapter.ClaimListAdapter) RecyclerView(androidx.recyclerview.widget.RecyclerView) Claim(com.odysee.app.model.Claim)

Aggregations

Comment (com.odysee.app.model.Comment)19 ArrayList (java.util.ArrayList)9 Context (android.content.Context)8 MainActivity (com.odysee.app.MainActivity)8 Claim (com.odysee.app.model.Claim)8 Account (android.accounts.Account)7 AccountManager (android.accounts.AccountManager)7 View (android.view.View)7 ImageView (android.widget.ImageView)7 TextView (android.widget.TextView)7 RecyclerView (androidx.recyclerview.widget.RecyclerView)7 IOException (java.io.IOException)6 JSONException (org.json.JSONException)6 AdapterView (android.widget.AdapterView)5 NestedScrollView (androidx.core.widget.NestedScrollView)5 ApiCallException (com.odysee.app.exceptions.ApiCallException)5 Reactions (com.odysee.app.model.Reactions)5 Bundle (android.os.Bundle)4 ViewGroup (android.view.ViewGroup)4 TrackSelectionOverride (com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride)4