Search in sources :

Example 16 with PullRequest

use of com.fastaccess.data.dao.model.PullRequest 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 17 with PullRequest

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

the class CreateIssueActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (savedInstanceState == null) {
        Bundle bundle = getIntent().getExtras();
        login = bundle.getString(BundleConstant.EXTRA);
        repoId = bundle.getString(BundleConstant.ID);
        isFeedback = bundle.getBoolean(BundleConstant.EXTRA_TWO);
        if (bundle.getParcelable(BundleConstant.ITEM) != null) {
            if (bundle.getParcelable(BundleConstant.ITEM) instanceof Issue) {
                issue = bundle.getParcelable(BundleConstant.ITEM);
                setTitle(getString(R.string.update_issue));
            } else if (bundle.getParcelable(BundleConstant.ITEM) instanceof PullRequest) {
                pullRequest = bundle.getParcelable(BundleConstant.ITEM);
                setTitle(getString(R.string.update_pull_request));
            }
        }
        if (issue != null) {
            Logger.e(issue.getLabels(), issue.getMilestone(), issue.getAssignees());
            if (issue.getLabels() != null) {
                onSelectedLabels(new ArrayList<>(issue.getLabels()));
            }
            if (issue.getAssignees() != null) {
                onSelectedAssignees(new ArrayList<>(issue.getAssignees()), false);
            }
            if (issue.getMilestone() != null) {
                milestoneModel = issue.getMilestone();
                onMilestoneSelected(milestoneModel);
            }
            if (!InputHelper.isEmpty(issue.getTitle())) {
                if (title.getEditText() != null)
                    title.getEditText().setText(issue.getTitle());
            }
            if (!InputHelper.isEmpty(issue.getBody())) {
                onSetCode(issue.getBody());
            }
        }
        if (pullRequest != null) {
            if (pullRequest.getLabels() != null) {
                onSelectedLabels(new ArrayList<>(pullRequest.getLabels()));
            }
            if (pullRequest.getAssignees() != null) {
                users.addAll(pullRequest.getAssignees());
                onSelectedAssignees(new ArrayList<>(pullRequest.getAssignees()), false);
            }
            if (pullRequest.getMilestone() != null) {
                milestoneModel = pullRequest.getMilestone();
                onMilestoneSelected(milestoneModel);
            }
            if (!InputHelper.isEmpty(pullRequest.getTitle())) {
                if (title.getEditText() != null)
                    title.getEditText().setText(pullRequest.getTitle());
            }
            if (!InputHelper.isEmpty(pullRequest.getBody())) {
                onSetCode(pullRequest.getBody());
            }
        }
    }
    getPresenter().checkAuthority(login, repoId);
    if (isFeedback || ("k0shk0sh".equalsIgnoreCase(login) && repoId.equalsIgnoreCase("FastHub"))) {
        Toasty.info(App.getInstance(), getString(R.string.report_issue_warning), Toast.LENGTH_LONG).show();
        setTitle(R.string.submit_feedback);
        getPresenter().onCheckAppVersion();
    }
    if (BuildConfig.DEBUG && isFeedback) {
        alertDialog = new AlertDialog.Builder(this).setTitle("You are currently using a debug build").setMessage("If you have found a bug, please report it on slack." + "\n" + "Feature requests can be submitted here." + "\n" + "Happy Testing").setPositiveButton(android.R.string.ok, null).show();
    }
    if (toolbar != null)
        toolbar.setSubtitle(login + "/" + repoId);
    setTaskName(login + "/" + repoId + " - " + (isFeedback ? getString(R.string.submit_feedback) : getString(R.string.create_issue)));
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) Issue(com.fastaccess.data.dao.model.Issue) Bundle(android.os.Bundle) PullRequest(com.fastaccess.data.dao.model.PullRequest)

Example 18 with PullRequest

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

the class FeedsViewHolder method appendPullRequestReviewCommentEvent.

private void appendPullRequestReviewCommentEvent(SpannableBuilder spannableBuilder, Event eventsModel) {
    PullRequest pullRequest = eventsModel.getPayload().getPullRequest();
    Comment comment = eventsModel.getPayload().getComment();
    spannableBuilder.bold("reviewed").append(" ").bold("pull request").append(" ").bold("in").append(" ").append(eventsModel.getRepo().getName()).bold("#").bold(String.valueOf(pullRequest.getNumber()));
    if (comment.getBody() != null) {
        MarkDownProvider.stripMdText(description, comment.getBody().replaceAll("\\r?\\n|\\r", " "));
        description.setVisibility(View.VISIBLE);
    } else {
        description.setText("");
        description.setVisibility(View.GONE);
    }
}
Also used : Comment(com.fastaccess.data.dao.model.Comment) PullRequest(com.fastaccess.data.dao.model.PullRequest)

Example 19 with PullRequest

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

the class FeedsViewHolder method appendPullRequestEvent.

private void appendPullRequestEvent(SpannableBuilder spannableBuilder, Event eventsModel) {
    PullRequest issue = eventsModel.getPayload().getPullRequest();
    String action = eventsModel.getPayload().getAction();
    if ("synchronize".equals(action)) {
        action = "updated";
    }
    if (eventsModel.getPayload().getPullRequest().isMerged()) {
        action = "merged";
    }
    spannableBuilder.bold(action).append(" ").bold("pull request").append(" ").append(eventsModel.getRepo().getName()).bold("#").bold(String.valueOf(issue.getNumber()));
    if ("opened".equals(action) || "closed".equals(action)) {
        if (issue.getTitle() != null) {
            MarkDownProvider.stripMdText(description, issue.getTitle().replaceAll("\\r?\\n|\\r", " "));
            description.setVisibility(View.VISIBLE);
        } else {
            description.setText("");
            description.setVisibility(View.GONE);
        }
    }
}
Also used : PullRequest(com.fastaccess.data.dao.model.PullRequest)

Example 20 with PullRequest

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

the class IssueDetailsViewHolder method addReactionCount.

private void addReactionCount(View v) {
    if (adapter != null) {
        TimelineModel timelineModel = (TimelineModel) adapter.getItem(getAdapterPosition());
        if (timelineModel == null)
            return;
        ReactionsModel reactionsModel = null;
        PullRequest pullRequest = timelineModel.getPullRequest();
        Issue issue = timelineModel.getIssue();
        int number = 0;
        if (pullRequest != null) {
            reactionsModel = pullRequest.getReactions();
            number = pullRequest.getNumber();
        } else if (issue != null) {
            reactionsModel = issue.getReactions();
            number = issue.getNumber();
        }
        if (reactionsModel == null)
            reactionsModel = new ReactionsModel();
        boolean isReacted = reactionsCallback == null || reactionsCallback.isPreviouslyReacted(number, v.getId());
        boolean isCallingApi = reactionsCallback != null && reactionsCallback.isCallingApi(number, v.getId());
        switch(v.getId()) {
            case R.id.heart:
            case R.id.heartReaction:
                reactionsModel.setHeart(!isReacted ? reactionsModel.getHeart() + 1 : reactionsModel.getHeart() - 1);
                break;
            case R.id.sad:
            case R.id.sadReaction:
                reactionsModel.setConfused(!isReacted ? reactionsModel.getConfused() + 1 : reactionsModel.getConfused() - 1);
                break;
            case R.id.thumbsDown:
            case R.id.thumbsDownReaction:
                reactionsModel.setMinusOne(!isReacted ? reactionsModel.getMinusOne() + 1 : reactionsModel.getMinusOne() - 1);
                break;
            case R.id.thumbsUp:
            case R.id.thumbsUpReaction:
                reactionsModel.setPlusOne(!isReacted ? reactionsModel.getPlusOne() + 1 : reactionsModel.getPlusOne() - 1);
                break;
            case R.id.laugh:
            case R.id.laughReaction:
                reactionsModel.setLaugh(!isReacted ? reactionsModel.getLaugh() + 1 : reactionsModel.getLaugh() - 1);
                break;
            case R.id.hurray:
            case R.id.hurrayReaction:
                reactionsModel.setHooray(!isReacted ? reactionsModel.getHooray() + 1 : reactionsModel.getHooray() - 1);
                break;
        }
        if (pullRequest != null) {
            pullRequest.setReactions(reactionsModel);
            appendEmojies(reactionsModel);
            timelineModel.setPullRequest(pullRequest);
        } else if (issue != null) {
            issue.setReactions(reactionsModel);
            appendEmojies(reactionsModel);
            timelineModel.setIssue(issue);
        }
    }
}
Also used : Issue(com.fastaccess.data.dao.model.Issue) PullRequest(com.fastaccess.data.dao.model.PullRequest) ReactionsModel(com.fastaccess.data.dao.ReactionsModel) TimelineModel(com.fastaccess.data.dao.TimelineModel)

Aggregations

PullRequest (com.fastaccess.data.dao.model.PullRequest)20 Bundle (android.os.Bundle)7 NonNull (android.support.annotation.NonNull)6 Nullable (android.support.annotation.Nullable)6 R (com.fastaccess.R)6 Login (com.fastaccess.data.dao.model.Login)6 BundleConstant (com.fastaccess.helper.BundleConstant)6 InputHelper (com.fastaccess.helper.InputHelper)6 RxHelper (com.fastaccess.helper.RxHelper)6 RestProvider (com.fastaccess.provider.rest.RestProvider)6 BaseMvp (com.fastaccess.ui.base.mvp.BaseMvp)6 BasePresenter (com.fastaccess.ui.base.mvp.presenter.BasePresenter)6 Observable (io.reactivex.Observable)6 ArrayList (java.util.ArrayList)6 Activity (android.app.Activity)5 CommentRequestModel (com.fastaccess.data.dao.CommentRequestModel)5 Comment (com.fastaccess.data.dao.model.Comment)5 PopupMenu (android.widget.PopupMenu)4 EditReviewCommentModel (com.fastaccess.data.dao.EditReviewCommentModel)4 GroupedReviewModel (com.fastaccess.data.dao.GroupedReviewModel)4