use of com.fastaccess.data.dao.model.Comment in project FastHub by k0shk0sh.
the class CommitCommentsFragment method onActivityResult.
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK) {
if (requestCode == BundleConstant.REQUEST_CODE) {
if (data == null) {
onRefresh();
return;
}
Bundle bundle = data.getExtras();
if (bundle != null) {
boolean isNew = bundle.getBoolean(BundleConstant.EXTRA);
Comment commentsModel = bundle.getParcelable(BundleConstant.ITEM);
if (commentsModel == null) {
// shit happens, refresh()?
onRefresh();
return;
}
adapter.notifyDataSetChanged();
if (isNew) {
adapter.addItem(TimelineModel.constructComment(commentsModel));
recycler.smoothScrollToPosition(adapter.getItemCount());
} else {
int position = adapter.getItem(TimelineModel.constructComment(commentsModel));
if (position != -1) {
adapter.swapItem(TimelineModel.constructComment(commentsModel), position);
recycler.smoothScrollToPosition(position);
} else {
adapter.addItem(TimelineModel.constructComment(commentsModel));
recycler.smoothScrollToPosition(adapter.getItemCount());
}
}
} else {
// bundle size is too large? refresh the api
onRefresh();
}
}
}
}
use of com.fastaccess.data.dao.model.Comment in project FastHub by k0shk0sh.
the class CommitCommentsPresenter method onItemClick.
@Override
public void onItemClick(int position, View v, TimelineModel timelineModel) {
if (getView() != null) {
Comment item = timelineModel.getComment();
if (v.getId() == R.id.commentMenu) {
PopupMenu popupMenu = new PopupMenu(v.getContext(), v);
popupMenu.inflate(R.menu.comments_menu);
String username = Login.getUser().getLogin();
boolean isOwner = CommentsHelper.isOwner(username, login, item.getUser().getLogin()) || isCollaborator;
popupMenu.getMenu().findItem(R.id.delete).setVisible(isOwner);
popupMenu.getMenu().findItem(R.id.edit).setVisible(isOwner);
popupMenu.setOnMenuItemClickListener(item1 -> {
if (getView() == null)
return false;
if (item1.getItemId() == R.id.delete) {
getView().onShowDeleteMsg(item.getId());
} else if (item1.getItemId() == R.id.reply) {
getView().onReply(item.getUser(), item.getBody());
} else if (item1.getItemId() == R.id.edit) {
getView().onEditComment(item);
} else if (item1.getItemId() == R.id.share) {
ActivityHelper.shareUrl(v.getContext(), item.getHtmlUrl());
}
return true;
});
popupMenu.show();
} else {
onHandleReaction(v.getId(), item.getId());
}
}
}
use of com.fastaccess.data.dao.model.Comment in project FastHub by k0shk0sh.
the class PullRequestTimelineFragment method onActivityResult.
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK) {
if (data == null) {
onRefresh();
return;
}
Bundle bundle = data.getExtras();
if (bundle != null) {
boolean isNew = bundle.getBoolean(BundleConstant.EXTRA);
if (requestCode == BundleConstant.REQUEST_CODE) {
Comment commentsModel = bundle.getParcelable(BundleConstant.ITEM);
if (commentsModel == null) {
// bundle size is too large? refresh the api
onRefresh();
return;
}
if (isNew) {
adapter.addItem(TimelineModel.constructComment(commentsModel));
recycler.smoothScrollToPosition(adapter.getItemCount());
} else {
int position = adapter.getItem(TimelineModel.constructComment(commentsModel));
if (position != -1) {
adapter.swapItem(TimelineModel.constructComment(commentsModel), position);
recycler.smoothScrollToPosition(position);
} else {
adapter.addItem(TimelineModel.constructComment(commentsModel));
recycler.smoothScrollToPosition(adapter.getItemCount());
}
}
} else if (requestCode == BundleConstant.REVIEW_REQUEST_CODE) {
EditReviewCommentModel commentModel = bundle.getParcelable(BundleConstant.ITEM);
if (commentModel == null) {
// bundle size is too large? refresh the api
onRefresh();
return;
}
TimelineModel timelineModel = adapter.getItem(commentModel.getGroupPosition());
if (isNew) {
if (timelineModel.getGroupedReviewModel() != null && timelineModel.getGroupedReviewModel().getComments() != null) {
timelineModel.getGroupedReviewModel().getComments().add(commentModel.getCommentModel());
adapter.notifyItemChanged(commentModel.getGroupPosition());
} else {
onRefresh();
}
} else {
if (timelineModel.getGroupedReviewModel() != null && timelineModel.getGroupedReviewModel().getComments() != null) {
timelineModel.getGroupedReviewModel().getComments().set(commentModel.getCommentPosition(), commentModel.getCommentModel());
adapter.notifyItemChanged(commentModel.getGroupPosition());
} else {
onRefresh();
}
}
}
} else {
// bundle size is too large? refresh the api
onRefresh();
}
}
}
use of com.fastaccess.data.dao.model.Comment in project FastHub by k0shk0sh.
the class PullRequestTimelinePresenter method onHandleComment.
@Override
public void onHandleComment(@NonNull String text, @Nullable Bundle bundle) {
if (getView() == null)
return;
PullRequest pullRequest = getView().getPullRequest();
if (pullRequest != null) {
if (bundle == null) {
CommentRequestModel commentRequestModel = new CommentRequestModel();
commentRequestModel.setBody(text);
manageDisposable(RxHelper.getObservable(RestProvider.getIssueService(isEnterprise()).createIssueComment(pullRequest.getLogin(), pullRequest.getRepoId(), pullRequest.getNumber(), commentRequestModel)).doOnSubscribe(disposable -> sendToView(view -> view.showBlockingProgress(0))).subscribe(comment -> sendToView(view -> view.addComment(TimelineModel.constructComment(comment))), throwable -> {
onError(throwable);
sendToView(PullRequestTimelineMvp.View::onHideBlockingProgress);
}));
}
}
}
use of com.fastaccess.data.dao.model.Comment in project FastHub by k0shk0sh.
the class PullRequestTimelinePresenter method onItemLongClick.
@Override
public void onItemLongClick(int position, View v, TimelineModel item) {
if (getView() == null || getView().getPullRequest() == 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 {
PullRequest pullRequest = getView().getPullRequest();
String login = pullRequest.getLogin();
String repoId = pullRequest.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.getPullRequest().getNumber(), ReactionsProvider.HEADER);
} else {
getView().showReactionsPopup(type, login, repoId, item.getComment().getId(), ReactionsProvider.COMMENT);
}
} else {
onItemClick(position, v, item);
}
}
}
} else {
onItemClick(position, v, item);
}
}
Aggregations