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);
}
}));
}
}
}
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);
}));
}
}
}
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);
}
}
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);
}
}));
}
}
}
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);
}
Aggregations