Search in sources :

Example 1 with CommentCreateTask

use of com.odysee.app.tasks.CommentCreateTask in project odysee-android by OdyseeTeam.

the class ChannelCommentsFragment method postComment.

private void postComment() {
    if (postingComment) {
        return;
    }
    Comment comment = buildPostComment();
    beforePostComment();
    AccountManager am = AccountManager.get(getContext());
    Account odyseeAccount = Helper.getOdyseeAccount(am.getAccounts());
    CommentCreateTask task = new CommentCreateTask(comment, am.peekAuthToken(odyseeAccount, "auth_token_type"), progressPostComment, new CommentCreateTask.CommentCreateWithTipHandler() {

        @Override
        public void onSuccess(Comment createdComment) {
            inputComment.setText(null);
            clearReplyToComment();
            ensureCommentListAdapterCreated(new ArrayList<Comment>());
            if (commentListAdapter != null) {
                createdComment.setPoster(comment.getPoster());
                if (!Helper.isNullOrEmpty(createdComment.getParentId())) {
                    commentListAdapter.addReply(createdComment);
                } else {
                    commentListAdapter.insert(0, createdComment);
                }
            }
            afterPostComment();
            checkNoComments();
            Bundle bundle = new Bundle();
            bundle.putString("claim_id", claim != null ? claim.getClaimId() : null);
            bundle.putString("claim_name", claim != null ? claim.getName() : null);
            LbryAnalytics.logEvent(LbryAnalytics.EVENT_COMMENT_CREATE, bundle);
            Context context = getContext();
            if (context instanceof MainActivity) {
                ((MainActivity) context).showMessage(R.string.comment_posted);
            }
        }

        @Override
        public void onError(Exception error) {
            try {
                showError(error != null ? error.getMessage() : getString(R.string.comment_error));
            } catch (IllegalStateException ex) {
            // pass
            }
            afterPostComment();
        }
    });
    task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : Context(android.content.Context) Comment(com.odysee.app.model.Comment) Account(android.accounts.Account) CommentCreateTask(com.odysee.app.tasks.CommentCreateTask) Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) AccountManager(android.accounts.AccountManager) MainActivity(com.odysee.app.MainActivity)

Example 2 with CommentCreateTask

use of com.odysee.app.tasks.CommentCreateTask in project odysee-android by OdyseeTeam.

the class FileViewFragment method postComment.

private void postComment() {
    if (postingComment) {
        return;
    }
    Comment comment = buildPostComment();
    beforePostComment();
    AccountManager am = AccountManager.get(getContext());
    Account odyseeAccount = Helper.getOdyseeAccount(am.getAccounts());
    CommentCreateTask task = new CommentCreateTask(comment, am.peekAuthToken(odyseeAccount, "auth_token_type"), progressPostComment, new CommentCreateTask.CommentCreateWithTipHandler() {

        @Override
        public void onSuccess(Comment createdComment) {
            inputComment.setText(null);
            clearReplyToComment();
            final boolean thisIsFirstComment = commentListAdapter == null;
            ensureCommentListAdapterCreated(new ArrayList<Comment>());
            if (commentListAdapter != null) {
                createdComment.setPoster(comment.getPoster());
                if (!Helper.isNullOrEmpty(createdComment.getParentId())) {
                    commentListAdapter.addReply(createdComment);
                } else {
                    commentListAdapter.insert(0, createdComment);
                }
            }
            afterPostComment();
            checkNoComments();
            if (thisIsFirstComment) {
                expandButton.performClick();
            }
            singleCommentRoot.setVisibility(View.GONE);
            Bundle bundle = new Bundle();
            bundle.putString("claim_id", fileClaim != null ? fileClaim.getClaimId() : null);
            bundle.putString("claim_name", fileClaim != null ? fileClaim.getName() : null);
            LbryAnalytics.logEvent(LbryAnalytics.EVENT_COMMENT_CREATE, bundle);
            Context context = getContext();
            if (context instanceof MainActivity) {
                ((MainActivity) context).showMessage(R.string.comment_posted);
            }
        }

        @Override
        public void onError(Exception error) {
            try {
                showError(error != null ? error.getMessage() : getString(R.string.comment_error));
            } catch (IllegalStateException ex) {
            // pass
            }
            afterPostComment();
        }
    });
    task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : AttributeProviderContext(org.commonmark.renderer.html.AttributeProviderContext) Context(android.content.Context) Comment(com.odysee.app.model.Comment) ReactToComment(com.odysee.app.runnable.ReactToComment) Account(android.accounts.Account) CommentCreateTask(com.odysee.app.tasks.CommentCreateTask) Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) AccountManager(android.accounts.AccountManager) MainActivity(com.odysee.app.MainActivity) TrackSelectionOverride(com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride) LbryRequestException(com.odysee.app.exceptions.LbryRequestException) JSONException(org.json.JSONException) LbryUriException(com.odysee.app.exceptions.LbryUriException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) LbryResponseException(com.odysee.app.exceptions.LbryResponseException) LbryioRequestException(com.odysee.app.exceptions.LbryioRequestException) LbryioResponseException(com.odysee.app.exceptions.LbryioResponseException) ApiCallException(com.odysee.app.exceptions.ApiCallException)

Aggregations

Account (android.accounts.Account)2 AccountManager (android.accounts.AccountManager)2 Context (android.content.Context)2 Bundle (android.os.Bundle)2 MainActivity (com.odysee.app.MainActivity)2 Comment (com.odysee.app.model.Comment)2 CommentCreateTask (com.odysee.app.tasks.CommentCreateTask)2 ArrayList (java.util.ArrayList)2 TrackSelectionOverride (com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride)1 ApiCallException (com.odysee.app.exceptions.ApiCallException)1 LbryRequestException (com.odysee.app.exceptions.LbryRequestException)1 LbryResponseException (com.odysee.app.exceptions.LbryResponseException)1 LbryUriException (com.odysee.app.exceptions.LbryUriException)1 LbryioRequestException (com.odysee.app.exceptions.LbryioRequestException)1 LbryioResponseException (com.odysee.app.exceptions.LbryioResponseException)1 ReactToComment (com.odysee.app.runnable.ReactToComment)1 IOException (java.io.IOException)1 ExecutionException (java.util.concurrent.ExecutionException)1 AttributeProviderContext (org.commonmark.renderer.html.AttributeProviderContext)1 JSONException (org.json.JSONException)1