Search in sources :

Example 11 with Comment

use of com.fastaccess.data.dao.model.Comment in project FastHub by k0shk0sh.

the class IssueTimelinePresenter method onHandleDeletion.

@Override
public void onHandleDeletion(@Nullable Bundle bundle) {
    if (bundle != null) {
        long commId = bundle.getLong(BundleConstant.EXTRA, 0);
        if (commId != 0) {
            if (getView() == null || getView().getIssue() == null)
                return;
            Issue issue = getView().getIssue();
            makeRestCall(RestProvider.getIssueService(isEnterprise()).deleteIssueComment(issue.getLogin(), issue.getRepoId(), commId), booleanResponse -> sendToView(view -> {
                if (booleanResponse.code() == 204) {
                    Comment comment = new Comment();
                    comment.setId(commId);
                    view.onRemove(TimelineModel.constructComment(comment));
                } else {
                    view.showMessage(R.string.error, R.string.error_deleting_comment);
                }
            }));
        }
    }
}
Also used : Comment(com.fastaccess.data.dao.model.Comment) GenericEvent(com.fastaccess.data.dao.timeline.GenericEvent) Bundle(android.os.Bundle) SourceModel(com.fastaccess.data.dao.timeline.SourceModel) ActivityHelper(com.fastaccess.helper.ActivityHelper) Getter(lombok.Getter) TimelineModel(com.fastaccess.data.dao.TimelineModel) CommentsHelper(com.fastaccess.provider.timeline.CommentsHelper) Uri(android.net.Uri) InputHelper(com.fastaccess.helper.InputHelper) NonNull(android.support.annotation.NonNull) Issue(com.fastaccess.data.dao.model.Issue) CreateIssueActivity(com.fastaccess.ui.modules.repos.issues.create.CreateIssueActivity) SchemeParser(com.fastaccess.provider.scheme.SchemeParser) ArrayList(java.util.ArrayList) RxHelper(com.fastaccess.helper.RxHelper) PopupMenu(android.widget.PopupMenu) View(android.view.View) Observable(io.reactivex.Observable) ReactionTypes(com.fastaccess.data.dao.types.ReactionTypes) BasePresenter(com.fastaccess.ui.base.mvp.presenter.BasePresenter) BundleConstant(com.fastaccess.helper.BundleConstant) CommentRequestModel(com.fastaccess.data.dao.CommentRequestModel) Login(com.fastaccess.data.dao.model.Login) RestProvider(com.fastaccess.provider.rest.RestProvider) BaseMvp(com.fastaccess.ui.base.mvp.BaseMvp) ReactionsProvider(com.fastaccess.provider.timeline.ReactionsProvider) List(java.util.List) R(com.fastaccess.R) FilterIssuesActivity(com.fastaccess.ui.modules.filter.issues.FilterIssuesActivity) TimelineConverter(com.fastaccess.provider.timeline.TimelineConverter) Nullable(android.support.annotation.Nullable) Activity(android.app.Activity) Comment(com.fastaccess.data.dao.model.Comment) Issue(com.fastaccess.data.dao.model.Issue)

Example 12 with Comment

use of com.fastaccess.data.dao.model.Comment in project FastHub by k0shk0sh.

the class IssueTimelinePresenter method onHandleComment.

@Override
public void onHandleComment(@NonNull String text, @Nullable Bundle bundle) {
    if (getView() == null)
        return;
    Issue issue = getView().getIssue();
    if (issue != null) {
        if (bundle == null) {
            CommentRequestModel commentRequestModel = new CommentRequestModel();
            commentRequestModel.setBody(text);
            manageDisposable(RxHelper.getObservable(RestProvider.getIssueService(isEnterprise()).createIssueComment(issue.getLogin(), issue.getRepoId(), issue.getNumber(), commentRequestModel)).doOnSubscribe(disposable -> sendToView(view -> view.showBlockingProgress(0))).subscribe(comment -> sendToView(view -> view.addNewComment(TimelineModel.constructComment(comment))), throwable -> {
                onError(throwable);
                sendToView(IssueTimelineMvp.View::onHideBlockingProgress);
            }));
        }
    }
}
Also used : Comment(com.fastaccess.data.dao.model.Comment) GenericEvent(com.fastaccess.data.dao.timeline.GenericEvent) Bundle(android.os.Bundle) SourceModel(com.fastaccess.data.dao.timeline.SourceModel) ActivityHelper(com.fastaccess.helper.ActivityHelper) Getter(lombok.Getter) TimelineModel(com.fastaccess.data.dao.TimelineModel) CommentsHelper(com.fastaccess.provider.timeline.CommentsHelper) Uri(android.net.Uri) InputHelper(com.fastaccess.helper.InputHelper) NonNull(android.support.annotation.NonNull) Issue(com.fastaccess.data.dao.model.Issue) CreateIssueActivity(com.fastaccess.ui.modules.repos.issues.create.CreateIssueActivity) SchemeParser(com.fastaccess.provider.scheme.SchemeParser) ArrayList(java.util.ArrayList) RxHelper(com.fastaccess.helper.RxHelper) PopupMenu(android.widget.PopupMenu) View(android.view.View) Observable(io.reactivex.Observable) ReactionTypes(com.fastaccess.data.dao.types.ReactionTypes) BasePresenter(com.fastaccess.ui.base.mvp.presenter.BasePresenter) BundleConstant(com.fastaccess.helper.BundleConstant) CommentRequestModel(com.fastaccess.data.dao.CommentRequestModel) Login(com.fastaccess.data.dao.model.Login) RestProvider(com.fastaccess.provider.rest.RestProvider) BaseMvp(com.fastaccess.ui.base.mvp.BaseMvp) ReactionsProvider(com.fastaccess.provider.timeline.ReactionsProvider) List(java.util.List) R(com.fastaccess.R) FilterIssuesActivity(com.fastaccess.ui.modules.filter.issues.FilterIssuesActivity) TimelineConverter(com.fastaccess.provider.timeline.TimelineConverter) Nullable(android.support.annotation.Nullable) Activity(android.app.Activity) Issue(com.fastaccess.data.dao.model.Issue) CommentRequestModel(com.fastaccess.data.dao.CommentRequestModel)

Example 13 with Comment

use of com.fastaccess.data.dao.model.Comment in project FastHub by k0shk0sh.

the class IssueTimelinePresenter method onItemLongClick.

@Override
public void onItemLongClick(int position, View v, TimelineModel item) {
    if (getView() == null)
        return;
    if (item.getType() == TimelineModel.COMMENT || item.getType() == TimelineModel.HEADER) {
        if (v.getId() == R.id.commentMenu && item.getType() == TimelineModel.COMMENT) {
            Comment comment = item.getComment();
            if (getView() != null)
                getView().onReply(comment.getUser(), comment.getBody());
        } else {
            if (getView().getIssue() == null)
                return;
            Issue issue = getView().getIssue();
            String login = issue.getLogin();
            String repoId = issue.getRepoId();
            if (!InputHelper.isEmpty(login) && !InputHelper.isEmpty(repoId)) {
                ReactionTypes type = ReactionTypes.get(v.getId());
                if (type != null) {
                    if (item.getType() == TimelineModel.HEADER) {
                        getView().showReactionsPopup(type, login, repoId, item.getIssue().getNumber(), true);
                    } else {
                        getView().showReactionsPopup(type, login, repoId, item.getComment().getId(), false);
                    }
                } else {
                    onItemClick(position, v, item);
                }
            }
        }
    } else {
        onItemClick(position, v, item);
    }
}
Also used : Comment(com.fastaccess.data.dao.model.Comment) Issue(com.fastaccess.data.dao.model.Issue) ReactionTypes(com.fastaccess.data.dao.types.ReactionTypes)

Example 14 with Comment

use of com.fastaccess.data.dao.model.Comment in project FastHub by k0shk0sh.

the class PullRequestTimelinePresenter method onHandleDeletion.

@Override
public void onHandleDeletion(@Nullable Bundle bundle) {
    if (getView() == null || getView().getPullRequest() == null)
        return;
    if (bundle != null) {
        PullRequest pullRequest = getView().getPullRequest();
        String login = pullRequest.getLogin();
        String repoId = pullRequest.getRepoId();
        long commId = bundle.getLong(BundleConstant.EXTRA, 0);
        boolean isReviewComment = bundle.getBoolean(BundleConstant.YES_NO_EXTRA);
        if (commId != 0 && !isReviewComment) {
            makeRestCall(RestProvider.getIssueService(isEnterprise()).deleteIssueComment(login, repoId, commId), booleanResponse -> sendToView(view -> {
                if (booleanResponse.code() == 204) {
                    Comment comment = new Comment();
                    comment.setId(commId);
                    view.onRemove(TimelineModel.constructComment(comment));
                } else {
                    view.showMessage(R.string.error, R.string.error_deleting_comment);
                }
            }));
        } else {
            int groupPosition = bundle.getInt(BundleConstant.EXTRA_TWO);
            int commentPosition = bundle.getInt(BundleConstant.EXTRA_THREE);
            makeRestCall(RestProvider.getReviewService(isEnterprise()).deleteComment(login, repoId, commId), booleanResponse -> sendToView(view -> {
                if (booleanResponse.code() == 204) {
                    view.onRemoveReviewComment(groupPosition, commentPosition);
                } else {
                    view.showMessage(R.string.error, R.string.error_deleting_comment);
                }
            }));
        }
    }
}
Also used : PullRequestStatusModel(com.fastaccess.data.dao.PullRequestStatusModel) Comment(com.fastaccess.data.dao.model.Comment) GenericEvent(com.fastaccess.data.dao.timeline.GenericEvent) Bundle(android.os.Bundle) SourceModel(com.fastaccess.data.dao.timeline.SourceModel) ActivityHelper(com.fastaccess.helper.ActivityHelper) TimelineModel(com.fastaccess.data.dao.TimelineModel) CommentsHelper(com.fastaccess.provider.timeline.CommentsHelper) Uri(android.net.Uri) InputHelper(com.fastaccess.helper.InputHelper) NonNull(android.support.annotation.NonNull) CreateIssueActivity(com.fastaccess.ui.modules.repos.issues.create.CreateIssueActivity) SchemeParser(com.fastaccess.provider.scheme.SchemeParser) ArrayList(java.util.ArrayList) RxHelper(com.fastaccess.helper.RxHelper) PopupMenu(android.widget.PopupMenu) EditReviewCommentModel(com.fastaccess.data.dao.EditReviewCommentModel) View(android.view.View) Observable(io.reactivex.Observable) ReactionTypes(com.fastaccess.data.dao.types.ReactionTypes) BasePresenter(com.fastaccess.ui.base.mvp.presenter.BasePresenter) BundleConstant(com.fastaccess.helper.BundleConstant) CommentRequestModel(com.fastaccess.data.dao.CommentRequestModel) Login(com.fastaccess.data.dao.model.Login) RestProvider(com.fastaccess.provider.rest.RestProvider) GroupedReviewModel(com.fastaccess.data.dao.GroupedReviewModel) BaseMvp(com.fastaccess.ui.base.mvp.BaseMvp) ReactionsProvider(com.fastaccess.provider.timeline.ReactionsProvider) SparseArray(android.util.SparseArray) List(java.util.List) PullRequest(com.fastaccess.data.dao.model.PullRequest) IssueEventType(com.fastaccess.data.dao.types.IssueEventType) R(com.fastaccess.R) FilterIssuesActivity(com.fastaccess.ui.modules.filter.issues.FilterIssuesActivity) ReviewCommentModel(com.fastaccess.data.dao.ReviewCommentModel) TimelineConverter(com.fastaccess.provider.timeline.TimelineConverter) Nullable(android.support.annotation.Nullable) Activity(android.app.Activity) Collections(java.util.Collections) Comment(com.fastaccess.data.dao.model.Comment) PullRequest(com.fastaccess.data.dao.model.PullRequest)

Example 15 with Comment

use of com.fastaccess.data.dao.model.Comment in project FastHub by k0shk0sh.

the class TimelineCommentsViewHolder method bind.

@Override
public void bind(@NonNull TimelineModel timelineModel) {
    Comment commentsModel = timelineModel.getComment();
    if (commentsModel.getUser() != null) {
        avatar.setUrl(commentsModel.getUser().getAvatarUrl(), commentsModel.getUser().getLogin(), false, LinkParserHelper.isEnterprise(commentsModel.getHtmlUrl()));
        name.setText(commentsModel.getUser() != null ? commentsModel.getUser().getLogin() : "Anonymous");
        if (commentsModel.getAuthorAssociation() != null && !"none".equalsIgnoreCase(commentsModel.getAuthorAssociation())) {
            owner.setText(commentsModel.getAuthorAssociation().toLowerCase());
            owner.setVisibility(View.VISIBLE);
        } else {
            boolean isRepoOwner = TextUtils.equals(commentsModel.getUser().getLogin(), repoOwner);
            if (isRepoOwner) {
                owner.setVisibility(View.VISIBLE);
                owner.setText(R.string.owner);
            } else {
                boolean isPoster = TextUtils.equals(commentsModel.getUser().getLogin(), poster);
                if (isPoster) {
                    owner.setVisibility(View.VISIBLE);
                    owner.setText(R.string.original_poster);
                } else {
                    owner.setText("");
                    owner.setVisibility(View.GONE);
                }
            }
        }
    } else {
        avatar.setUrl(null, null, false, false);
        name.setText("");
    }
    if (!InputHelper.isEmpty(commentsModel.getPath()) && commentsModel.getPosition() > 0) {
        pathText.setVisibility(View.VISIBLE);
        pathText.setText(String.format("Commented on %s#L%s", commentsModel.getPath(), commentsModel.getLine() > 0 ? commentsModel.getLine() : commentsModel.getPosition()));
    } else {
        pathText.setText("");
        pathText.setVisibility(View.GONE);
    }
    if (!InputHelper.isEmpty(commentsModel.getBodyHtml())) {
        String body = commentsModel.getBodyHtml();
        int width = adapter != null ? adapter.getRowWidth() : 0;
        HtmlHelper.htmlIntoTextView(comment, body, width > 0 ? width : viewGroup.getWidth());
    } else {
        comment.setText("");
    }
    if (commentsModel.getCreatedAt().before(commentsModel.getUpdatedAt())) {
        date.setText(String.format("%s %s", ParseDateFormat.getTimeAgo(commentsModel.getCreatedAt()), itemView.getResources().getString(R.string.edited)));
    } else {
        date.setText(ParseDateFormat.getTimeAgo(commentsModel.getCreatedAt()));
    }
    if (showEmojies) {
        if (commentsModel.getReactions() != null) {
            ReactionsModel reaction = commentsModel.getReactions();
            appendEmojies(reaction);
        }
    }
    emojiesList.setVisibility(showEmojies ? View.VISIBLE : View.GONE);
    if (onToggleView != null)
        onToggle(onToggleView.isCollapsed(getAdapterPosition()), false);
}
Also used : Comment(com.fastaccess.data.dao.model.Comment) ReactionsModel(com.fastaccess.data.dao.ReactionsModel)

Aggregations

Comment (com.fastaccess.data.dao.model.Comment)19 Bundle (android.os.Bundle)11 PopupMenu (android.widget.PopupMenu)8 NonNull (android.support.annotation.NonNull)7 Nullable (android.support.annotation.Nullable)7 View (android.view.View)7 R (com.fastaccess.R)7 CommentRequestModel (com.fastaccess.data.dao.CommentRequestModel)7 TimelineModel (com.fastaccess.data.dao.TimelineModel)7 Login (com.fastaccess.data.dao.model.Login)7 ReactionTypes (com.fastaccess.data.dao.types.ReactionTypes)7 BundleConstant (com.fastaccess.helper.BundleConstant)7 RxHelper (com.fastaccess.helper.RxHelper)7 RestProvider (com.fastaccess.provider.rest.RestProvider)7 BasePresenter (com.fastaccess.ui.base.mvp.presenter.BasePresenter)7 ArrayList (java.util.ArrayList)7 BaseMvp (com.fastaccess.ui.base.mvp.BaseMvp)6 ActivityHelper (com.fastaccess.helper.ActivityHelper)5 CommentsHelper (com.fastaccess.provider.timeline.CommentsHelper)5 ReactionsProvider (com.fastaccess.provider.timeline.ReactionsProvider)5