Search in sources :

Example 1 with SourceModel

use of com.fastaccess.data.dao.timeline.SourceModel in project FastHub by k0shk0sh.

the class TimelineProvider method getStyledEvents.

@NonNull
public static SpannableBuilder getStyledEvents(@NonNull GenericEvent issueEventModel, @NonNull Context context, boolean isMerged) {
    IssueEventType event = issueEventModel.getEvent();
    SpannableBuilder spannableBuilder = SpannableBuilder.builder();
    Date date = issueEventModel.getCreatedAt() != null ? issueEventModel.getCreatedAt() : issueEventModel.getAuthor() != null ? issueEventModel.getAuthor().getDate() : null;
    if (event != null) {
        String to = context.getString(R.string.to);
        String from = context.getString(R.string.from);
        String thisString = context.getString(R.string.this_value);
        String in = context.getString(R.string.in_value);
        if (event == IssueEventType.labeled || event == IssueEventType.unlabeled) {
            spannableBuilder.bold(issueEventModel.getActor() != null ? issueEventModel.getActor().getLogin() : "anonymous");
            spannableBuilder.append(" ").append(event.name().replaceAll("_", " "));
            LabelModel labelModel = issueEventModel.getLabel();
            int color = Color.parseColor("#" + labelModel.getColor());
            spannableBuilder.append(" ").append(" " + labelModel.getName() + " ", new CodeSpan(color, ViewHelper.generateTextColor(color), 5));
            spannableBuilder.append(" ").append(getDate(issueEventModel.getCreatedAt()));
        } else if (event == IssueEventType.committed) {
            spannableBuilder.append(issueEventModel.getMessage().replaceAll("\n", " ")).append(" ").url(substring(issueEventModel.getSha()));
        } else {
            User user = null;
            if (issueEventModel.getAssignee() != null && issueEventModel.getAssigner() != null) {
                user = issueEventModel.getAssigner();
            } else if (issueEventModel.getActor() != null) {
                user = issueEventModel.getActor();
            } else if (issueEventModel.getAuthor() != null) {
                user = issueEventModel.getAuthor();
            }
            if (user != null) {
                spannableBuilder.bold(user.getLogin());
            }
            if ((event == IssueEventType.review_requested || (event == IssueEventType.review_dismissed || event == IssueEventType.review_request_removed)) && user != null) {
                appendReviews(issueEventModel, event, spannableBuilder, from, issueEventModel.getReviewRequester());
            } else if (event == IssueEventType.closed || event == IssueEventType.reopened) {
                if (isMerged) {
                    spannableBuilder.append(" ").append(IssueEventType.merged.name());
                } else {
                    spannableBuilder.append(" ").append(event.name().replaceAll("_", " ")).append(" ").append(thisString);
                }
                if (issueEventModel.getCommitId() != null) {
                    spannableBuilder.append(" ").append(in).append(" ").url(substring(issueEventModel.getCommitId()));
                }
            } else if (event == IssueEventType.assigned || event == IssueEventType.unassigned) {
                spannableBuilder.append(" ");
                if ((user != null && issueEventModel.getAssignee() != null) && user.getLogin().equalsIgnoreCase(issueEventModel.getAssignee().getLogin())) {
                    spannableBuilder.append(event == IssueEventType.assigned ? "self-assigned this" : "removed their assignment");
                } else {
                    spannableBuilder.append(event == IssueEventType.assigned ? "assigned" : "unassigned");
                    spannableBuilder.append(" ").bold(issueEventModel.getAssignee() != null ? issueEventModel.getAssignee().getLogin() : "");
                }
            } else if (event == IssueEventType.locked || event == IssueEventType.unlocked) {
                spannableBuilder.append(" ").append(event == IssueEventType.locked ? "locked and limited conversation to collaborators" : "unlocked this " + "conversation");
            } else if (event == IssueEventType.head_ref_deleted || event == IssueEventType.head_ref_restored) {
                spannableBuilder.append(" ").append(event.name().replaceAll("_", " "), new BackgroundColorSpan(HtmlHelper.getWindowBackground(PrefGetter.getThemeType())));
            } else if (event == IssueEventType.milestoned || event == IssueEventType.demilestoned) {
                spannableBuilder.append(" ").append(event == IssueEventType.milestoned ? "added this to the" : "removed this from the").append(" ").bold(issueEventModel.getMilestone().getTitle()).append(" ").append("milestone");
            } else if (event == IssueEventType.deployed) {
                spannableBuilder.append(" ").bold("deployed");
            } else {
                spannableBuilder.append(" ").append(event.name().replaceAll("_", " "));
            }
            if (event == IssueEventType.renamed) {
                spannableBuilder.append(" ").append(from).append(" ").bold(issueEventModel.getRename().getFromValue()).append(" ").append(to).append(" ").bold(issueEventModel.getRename().getToValue());
            } else if (event == IssueEventType.referenced || event == IssueEventType.merged) {
                spannableBuilder.append(" ").append("commit").append(" ").url(substring(issueEventModel.getCommitId()));
            } else if (event == IssueEventType.cross_referenced) {
                SourceModel sourceModel = issueEventModel.getSource();
                if (sourceModel != null) {
                    String type = sourceModel.getType();
                    SpannableBuilder title = SpannableBuilder.builder();
                    if (sourceModel.getPullRequest() != null) {
                        if (sourceModel.getIssue() != null)
                            title.url("#" + sourceModel.getIssue().getNumber());
                        type = "pull request";
                    } else if (sourceModel.getIssue() != null) {
                        title.url("#" + sourceModel.getIssue().getNumber());
                    } else if (sourceModel.getCommit() != null) {
                        title.url(substring(sourceModel.getCommit().getSha()));
                    } else if (sourceModel.getRepository() != null) {
                        title.url(sourceModel.getRepository().getName());
                    }
                    if (!InputHelper.isEmpty(title)) {
                        spannableBuilder.append(" ").append(thisString).append(" in ").append(type).append(" ").append(title);
                    }
                }
            }
            spannableBuilder.append(" ").append(getDate(date));
        }
    }
    return spannableBuilder;
}
Also used : SourceModel(com.fastaccess.data.dao.timeline.SourceModel) IssueEventType(com.fastaccess.data.dao.types.IssueEventType) User(com.fastaccess.data.dao.model.User) LabelModel(com.fastaccess.data.dao.LabelModel) SpannableBuilder(com.fastaccess.ui.widgets.SpannableBuilder) CodeSpan(com.zzhoujay.markdown.style.CodeSpan) Date(java.util.Date) BackgroundColorSpan(android.text.style.BackgroundColorSpan) NonNull(android.support.annotation.NonNull)

Example 2 with SourceModel

use of com.fastaccess.data.dao.timeline.SourceModel in project FastHub by k0shk0sh.

the class PullRequestTimelinePresenter method onItemClick.

@Override
public void onItemClick(int position, View v, TimelineModel item) {
    if (getView() == null)
        return;
    PullRequest pullRequest = getView().getPullRequest();
    if (pullRequest != null) {
        if (item.getType() == TimelineModel.COMMENT) {
            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, pullRequest.getLogin(), item.getComment().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.getComment().getId());
                    } else if (item1.getItemId() == R.id.reply) {
                        getView().onReply(item.getComment().getUser(), item.getComment().getBodyHtml());
                    } else if (item1.getItemId() == R.id.edit) {
                        getView().onEditComment(item.getComment());
                    } else if (item1.getItemId() == R.id.share) {
                        ActivityHelper.shareUrl(v.getContext(), item.getComment().getHtmlUrl());
                    }
                    return true;
                });
                popupMenu.show();
            } else {
                onHandleReaction(v.getId(), item.getComment().getId(), ReactionsProvider.COMMENT);
            }
        } else if (item.getType() == TimelineModel.EVENT) {
            GenericEvent issueEventModel = item.getGenericEvent();
            if (issueEventModel.getCommitUrl() != null) {
                SchemeParser.launchUri(v.getContext(), Uri.parse(issueEventModel.getCommitUrl()));
            } else if (issueEventModel.getLabel() != null) {
                FilterIssuesActivity.startActivity(v, pullRequest.getLogin(), pullRequest.getRepoId(), false, true, isEnterprise(), "label:\"" + issueEventModel.getLabel().getName() + "\"");
            } else if (issueEventModel.getMilestone() != null) {
                FilterIssuesActivity.startActivity(v, pullRequest.getLogin(), pullRequest.getRepoId(), false, true, isEnterprise(), "milestone:\"" + issueEventModel.getMilestone().getTitle() + "\"");
            } else if (issueEventModel.getAssignee() != null) {
                FilterIssuesActivity.startActivity(v, pullRequest.getLogin(), pullRequest.getRepoId(), false, true, isEnterprise(), "assignee:\"" + issueEventModel.getAssignee().getLogin() + "\"");
            } else if (issueEventModel.getEvent() == IssueEventType.committed) {
                SchemeParser.launchUri(v.getContext(), issueEventModel.getUrl().replace("git/", ""));
            } else {
                SourceModel sourceModel = issueEventModel.getSource();
                if (sourceModel != null) {
                    if (sourceModel.getCommit() != null) {
                        SchemeParser.launchUri(v.getContext(), sourceModel.getCommit().getUrl());
                    } else if (sourceModel.getPullRequest() != null) {
                        SchemeParser.launchUri(v.getContext(), sourceModel.getPullRequest().getUrl());
                    } else if (sourceModel.getIssue() != null) {
                        SchemeParser.launchUri(v.getContext(), sourceModel.getIssue().getHtmlUrl());
                    } else if (sourceModel.getRepository() != null) {
                        SchemeParser.launchUri(v.getContext(), sourceModel.getRepository().getUrl());
                    }
                }
            }
        } else if (item.getType() == TimelineModel.HEADER) {
            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, item.getPullRequest().getLogin(), item.getPullRequest().getUser().getLogin()) || isCollaborator;
                popupMenu.getMenu().findItem(R.id.edit).setVisible(isOwner);
                popupMenu.setOnMenuItemClickListener(item1 -> {
                    if (getView() == null)
                        return false;
                    if (item1.getItemId() == R.id.reply) {
                        getView().onReply(item.getPullRequest().getUser(), item.getPullRequest().getBodyHtml());
                    } else if (item1.getItemId() == R.id.edit) {
                        Activity activity = ActivityHelper.getActivity(v.getContext());
                        if (activity == null)
                            return false;
                        CreateIssueActivity.startForResult(activity, item.getPullRequest().getLogin(), item.getPullRequest().getRepoId(), item.getPullRequest(), isEnterprise());
                    } else if (item1.getItemId() == R.id.share) {
                        ActivityHelper.shareUrl(v.getContext(), item.getPullRequest().getHtmlUrl());
                    }
                    return true;
                });
                popupMenu.show();
            } else {
                onHandleReaction(v.getId(), item.getPullRequest().getNumber(), ReactionsProvider.HEADER);
            }
        } else if (item.getType() == TimelineModel.GROUP) {
            GroupedReviewModel reviewModel = item.getGroupedReviewModel();
            if (v.getId() == R.id.addCommentPreview) {
                if (getView() != null) {
                    EditReviewCommentModel model = new EditReviewCommentModel();
                    model.setCommentPosition(-1);
                    model.setGroupPosition(position);
                    model.setInReplyTo(reviewModel.getId());
                    getView().onReplyOrCreateReview(null, null, position, -1, model);
                }
            }
        }
    }
}
Also used : SourceModel(com.fastaccess.data.dao.timeline.SourceModel) GenericEvent(com.fastaccess.data.dao.timeline.GenericEvent) EditReviewCommentModel(com.fastaccess.data.dao.EditReviewCommentModel) PullRequest(com.fastaccess.data.dao.model.PullRequest) CreateIssueActivity(com.fastaccess.ui.modules.repos.issues.create.CreateIssueActivity) FilterIssuesActivity(com.fastaccess.ui.modules.filter.issues.FilterIssuesActivity) Activity(android.app.Activity) GroupedReviewModel(com.fastaccess.data.dao.GroupedReviewModel) PopupMenu(android.widget.PopupMenu)

Example 3 with SourceModel

use of com.fastaccess.data.dao.timeline.SourceModel in project FastHub by k0shk0sh.

the class IssueTimelinePresenter method onItemClick.

@Override
public void onItemClick(int position, View v, TimelineModel item) {
    if (getView() != null) {
        Issue issue = getView().getIssue();
        if (issue == null)
            return;
        if (item.getType() == TimelineModel.COMMENT) {
            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, issue.getLogin(), item.getComment().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.getComment().getId());
                    } else if (item1.getItemId() == R.id.reply) {
                        getView().onReply(item.getComment().getUser(), item.getComment().getBody());
                    } else if (item1.getItemId() == R.id.edit) {
                        getView().onEditComment(item.getComment());
                    } else if (item1.getItemId() == R.id.share) {
                        ActivityHelper.shareUrl(v.getContext(), item.getComment().getHtmlUrl());
                    }
                    return true;
                });
                popupMenu.show();
            } else {
                onHandleReaction(v.getId(), item.getComment().getId(), ReactionsProvider.COMMENT);
            }
        } else if (item.getType() == TimelineModel.EVENT) {
            GenericEvent issueEventModel = item.getGenericEvent();
            if (issueEventModel.getCommitUrl() != null) {
                SchemeParser.launchUri(v.getContext(), Uri.parse(issueEventModel.getCommitUrl()));
            } else if (issueEventModel.getLabel() != null) {
                FilterIssuesActivity.startActivity(v, issue.getLogin(), issue.getRepoId(), true, true, isEnterprise(), "label:\"" + issueEventModel.getLabel().getName() + "\"");
            } else if (issueEventModel.getMilestone() != null) {
                FilterIssuesActivity.startActivity(v, issue.getLogin(), issue.getRepoId(), true, true, isEnterprise(), "milestone:\"" + issueEventModel.getMilestone().getTitle() + "\"");
            } else if (issueEventModel.getAssignee() != null) {
                FilterIssuesActivity.startActivity(v, issue.getLogin(), issue.getRepoId(), true, true, isEnterprise(), "assignee:\"" + issueEventModel.getAssignee().getLogin() + "\"");
            } else {
                SourceModel sourceModel = issueEventModel.getSource();
                if (sourceModel != null) {
                    if (sourceModel.getCommit() != null) {
                        SchemeParser.launchUri(v.getContext(), sourceModel.getCommit().getUrl());
                    } else if (sourceModel.getPullRequest() != null) {
                        SchemeParser.launchUri(v.getContext(), sourceModel.getPullRequest().getUrl());
                    } else if (sourceModel.getIssue() != null) {
                        SchemeParser.launchUri(v.getContext(), sourceModel.getIssue().getHtmlUrl());
                    } else if (sourceModel.getRepository() != null) {
                        SchemeParser.launchUri(v.getContext(), sourceModel.getRepository().getUrl());
                    }
                }
            }
        } else if (item.getType() == TimelineModel.HEADER) {
            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, item.getIssue().getLogin(), item.getIssue().getUser().getLogin()) || isCollaborator;
                popupMenu.getMenu().findItem(R.id.edit).setVisible(isOwner);
                popupMenu.setOnMenuItemClickListener(item1 -> {
                    if (getView() == null)
                        return false;
                    if (item1.getItemId() == R.id.reply) {
                        getView().onReply(item.getIssue().getUser(), item.getIssue().getBody());
                    } else if (item1.getItemId() == R.id.edit) {
                        Activity activity = ActivityHelper.getActivity(v.getContext());
                        if (activity == null)
                            return false;
                        CreateIssueActivity.startForResult(activity, item.getIssue().getLogin(), item.getIssue().getRepoId(), item.getIssue(), isEnterprise());
                    } else if (item1.getItemId() == R.id.share) {
                        ActivityHelper.shareUrl(v.getContext(), item.getIssue().getHtmlUrl());
                    }
                    return true;
                });
                popupMenu.show();
            } else {
                onHandleReaction(v.getId(), item.getIssue().getNumber(), ReactionsProvider.HEADER);
            }
        }
    }
}
Also used : SourceModel(com.fastaccess.data.dao.timeline.SourceModel) Issue(com.fastaccess.data.dao.model.Issue) GenericEvent(com.fastaccess.data.dao.timeline.GenericEvent) CreateIssueActivity(com.fastaccess.ui.modules.repos.issues.create.CreateIssueActivity) FilterIssuesActivity(com.fastaccess.ui.modules.filter.issues.FilterIssuesActivity) Activity(android.app.Activity) PopupMenu(android.widget.PopupMenu)

Aggregations

SourceModel (com.fastaccess.data.dao.timeline.SourceModel)3 Activity (android.app.Activity)2 PopupMenu (android.widget.PopupMenu)2 GenericEvent (com.fastaccess.data.dao.timeline.GenericEvent)2 FilterIssuesActivity (com.fastaccess.ui.modules.filter.issues.FilterIssuesActivity)2 CreateIssueActivity (com.fastaccess.ui.modules.repos.issues.create.CreateIssueActivity)2 NonNull (android.support.annotation.NonNull)1 BackgroundColorSpan (android.text.style.BackgroundColorSpan)1 EditReviewCommentModel (com.fastaccess.data.dao.EditReviewCommentModel)1 GroupedReviewModel (com.fastaccess.data.dao.GroupedReviewModel)1 LabelModel (com.fastaccess.data.dao.LabelModel)1 Issue (com.fastaccess.data.dao.model.Issue)1 PullRequest (com.fastaccess.data.dao.model.PullRequest)1 User (com.fastaccess.data.dao.model.User)1 IssueEventType (com.fastaccess.data.dao.types.IssueEventType)1 SpannableBuilder (com.fastaccess.ui.widgets.SpannableBuilder)1 CodeSpan (com.zzhoujay.markdown.style.CodeSpan)1 Date (java.util.Date)1