Search in sources :

Example 1 with PullRequestStatusModel

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

the class PullRequestTimelinePresenter method onCallApi.

@Override
public boolean onCallApi(int page, @Nullable PullRequest parameter) {
    if (parameter == null) {
        sendToView(BaseMvp.FAView::hideProgress);
        return false;
    }
    String login = parameter.getLogin();
    String repoId = parameter.getRepoId();
    int number = parameter.getNumber();
    if (page <= 1) {
        lastPage = Integer.MAX_VALUE;
        sendToView(view -> view.getLoadMore().reset());
        pages.clear();
    }
    if (page > lastPage || lastPage == 0) {
        sendToView(PullRequestTimelineMvp.View::hideProgress);
        return false;
    }
    if (page == 1) {
        manageObservable(RestProvider.getRepoService(isEnterprise()).isCollaborator(login, repoId, Login.getUser().getLogin()).doOnNext(booleanResponse -> isCollaborator = booleanResponse.code() == 204));
    }
    setCurrentPage(page);
    if (parameter.getHead() != null) {
        Observable<List<TimelineModel>> observable = Observable.zip(RestProvider.getIssueService(isEnterprise()).getTimeline(login, repoId, number, page), RestProvider.getReviewService(isEnterprise()).getPrReviewComments(login, repoId, number), RestProvider.getPullRequestService(isEnterprise()).getPullStatus(login, repoId, parameter.getHead().getSha()).onErrorReturn(throwable -> RestProvider.getPullRequestService(isEnterprise()).getPullStatus(login, repoId, parameter.getBase().getSha()).blockingFirst(new PullRequestStatusModel())), (response, comments, status) -> {
            if (response != null) {
                lastPage = response.getLast();
                List<TimelineModel> models = TimelineConverter.INSTANCE.convert(response.getItems(), comments);
                if (page == 1 && status != null) {
                    status.setMergable(parameter.isMergeable());
                    status.setMergeableState(parameter.getMergeableState());
                    if (status.getState() != null) {
                        models.add(0, new TimelineModel(status));
                    }
                }
                return models;
            } else {
                return Collections.emptyList();
            }
        });
        makeRestCall(observable, timeline -> sendToView(view -> view.onNotifyAdapter(timeline, page)));
        return true;
    }
    return false;
}
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) PullRequestStatusModel(com.fastaccess.data.dao.PullRequestStatusModel) ArrayList(java.util.ArrayList) List(java.util.List) View(android.view.View) TimelineModel(com.fastaccess.data.dao.TimelineModel)

Example 2 with PullRequestStatusModel

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

the class PullStatusViewHolder method bind.

@Override
public void bind(@NonNull PullRequestStatusModel pullRequestStatusModel) {
    if (pullRequestStatusModel.getState() != null) {
        StatusStateType stateType = pullRequestStatusModel.getState();
        stateImage.setImageResource(stateType.getDrawableRes());
        String mergeableState = pullRequestStatusModel.getMergeableState();
        boolean isBlocked = "blocked".equalsIgnoreCase(mergeableState);
        if (stateType == StatusStateType.failure) {
            stateImage.tintDrawableColor(red);
            if (pullRequestStatusModel.isMergable()) {
                status.setText(R.string.checks_failed);
            } else {
                status.setText(SpannableBuilder.builder().append(status.getResources().getString(R.string.checks_failed)).append("\n").append(status.getResources().getString(R.string.can_not_merge_pr)));
            }
        } else if (stateType == StatusStateType.pending) {
            if (pullRequestStatusModel.isMergable()) {
                stateImage.setImageResource(R.drawable.ic_check_small);
                stateImage.tintDrawableColor(green);
                status.setText(!isBlocked ? R.string.commit_can_be_merged : R.string.can_not_merge_pr);
            } else {
                stateImage.setImageResource(stateType.getDrawableRes());
                stateImage.tintDrawableColor(indigo);
                status.setText(R.string.checks_pending);
            }
        } else {
            stateImage.tintDrawableColor(green);
            if (pullRequestStatusModel.isMergable()) {
                status.setText(!isBlocked ? R.string.commit_can_be_merged : R.string.can_not_merge_pr);
            } else {
                status.setText(R.string.checks_passed);
            }
        }
    }
    if (pullRequestStatusModel.getStatuses() != null && !pullRequestStatusModel.getStatuses().isEmpty()) {
        SpannableBuilder builder = SpannableBuilder.builder();
        Stream.of(pullRequestStatusModel.getStatuses()).filter(statusesModel -> statusesModel != null && statusesModel.getState() != null && statusesModel.getTargetUrl() != null).forEach(statusesModel -> {
            if (!InputHelper.isEmpty(statusesModel.getTargetUrl())) {
                builder.append(ContextCompat.getDrawable(statuses.getContext(), statusesModel.getState().getDrawableRes()));
                builder.append(" ").append(statusesModel.getContext() != null ? statusesModel.getContext() + " " : "").url(statusesModel.getDescription(), v -> SchemeParser.launchUri(v.getContext(), statusesModel.getTargetUrl())).append("\n");
            }
        });
        if (!InputHelper.isEmpty(builder)) {
            statuses.setMovementMethod(LinkMovementMethod.getInstance());
            statuses.setText(builder);
            statuses.setVisibility(View.VISIBLE);
        } else {
            statuses.setVisibility(View.GONE);
        }
    } else {
        statuses.setVisibility(View.GONE);
    }
}
Also used : PullRequestStatusModel(com.fastaccess.data.dao.PullRequestStatusModel) BaseViewHolder(com.fastaccess.ui.widgets.recyclerview.BaseViewHolder) Stream(com.annimon.stream.Stream) ContextCompat(android.support.v4.content.ContextCompat) InputHelper(com.fastaccess.helper.InputHelper) BindColor(butterknife.BindColor) NonNull(android.support.annotation.NonNull) LinkMovementMethod(android.text.method.LinkMovementMethod) ViewGroup(android.view.ViewGroup) SchemeParser(com.fastaccess.provider.scheme.SchemeParser) SpannableBuilder(com.fastaccess.ui.widgets.SpannableBuilder) BindView(butterknife.BindView) StatusStateType(com.fastaccess.data.dao.types.StatusStateType) ForegroundImageView(com.fastaccess.ui.widgets.ForegroundImageView) R(com.fastaccess.R) FontTextView(com.fastaccess.ui.widgets.FontTextView) View(android.view.View) StatusStateType(com.fastaccess.data.dao.types.StatusStateType) SpannableBuilder(com.fastaccess.ui.widgets.SpannableBuilder)

Aggregations

NonNull (android.support.annotation.NonNull)2 View (android.view.View)2 R (com.fastaccess.R)2 PullRequestStatusModel (com.fastaccess.data.dao.PullRequestStatusModel)2 InputHelper (com.fastaccess.helper.InputHelper)2 SchemeParser (com.fastaccess.provider.scheme.SchemeParser)2 Activity (android.app.Activity)1 Uri (android.net.Uri)1 Bundle (android.os.Bundle)1 Nullable (android.support.annotation.Nullable)1 ContextCompat (android.support.v4.content.ContextCompat)1 LinkMovementMethod (android.text.method.LinkMovementMethod)1 SparseArray (android.util.SparseArray)1 ViewGroup (android.view.ViewGroup)1 PopupMenu (android.widget.PopupMenu)1 BindColor (butterknife.BindColor)1 BindView (butterknife.BindView)1 Stream (com.annimon.stream.Stream)1 CommentRequestModel (com.fastaccess.data.dao.CommentRequestModel)1 EditReviewCommentModel (com.fastaccess.data.dao.EditReviewCommentModel)1