Search in sources :

Example 1 with TimelineModel

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

the class IssuesTimelineAdapter method onBindView.

@Override
protected void onBindView(BaseViewHolder holder, int position) {
    TimelineModel model = getItem(position);
    if (model.getType() == TimelineModel.HEADER) {
        ((IssueDetailsViewHolder) holder).bind(model);
    } else if (model.getType() == TimelineModel.EVENT) {
        ((IssueTimelineViewHolder) holder).bind(model);
    } else if (model.getType() == TimelineModel.COMMENT) {
        ((TimelineCommentsViewHolder) holder).bind(model);
    } else if (model.getType() == TimelineModel.GROUP) {
        ((GroupedReviewsViewHolder) holder).bind(model);
    } else if (model.getType() == TimelineModel.REVIEW) {
        ((ReviewsViewHolder) holder).bind(model);
    } else if (model.getType() == TimelineModel.COMMIT_COMMENTS) {
        ((CommitThreadViewHolder) holder).bind(model);
    } else if (model.getType() == TimelineModel.STATUS && model.getStatus() != null) {
        ((PullStatusViewHolder) holder).bind(model.getStatus());
    }
    if (model.getType() != TimelineModel.COMMENT) {
        StaggeredGridLayoutManager.LayoutParams layoutParams = (StaggeredGridLayoutManager.LayoutParams) holder.itemView.getLayoutParams();
        layoutParams.setFullSpan(true);
    }
}
Also used : IssueDetailsViewHolder(com.fastaccess.ui.adapter.viewholder.IssueDetailsViewHolder) PullStatusViewHolder(com.fastaccess.ui.adapter.viewholder.PullStatusViewHolder) TimelineCommentsViewHolder(com.fastaccess.ui.adapter.viewholder.TimelineCommentsViewHolder) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) ReviewsViewHolder(com.fastaccess.ui.adapter.viewholder.ReviewsViewHolder) GroupedReviewsViewHolder(com.fastaccess.ui.adapter.viewholder.GroupedReviewsViewHolder) TimelineModel(com.fastaccess.data.dao.TimelineModel)

Example 2 with TimelineModel

use of com.fastaccess.data.dao.TimelineModel 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();
        }
    }
}
Also used : Comment(com.fastaccess.data.dao.model.Comment) Bundle(android.os.Bundle) EditReviewCommentModel(com.fastaccess.data.dao.EditReviewCommentModel) TimelineModel(com.fastaccess.data.dao.TimelineModel)

Example 3 with TimelineModel

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

the class PullRequestTimelineFragment method onFragmentCreated.

@Override
protected void onFragmentCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    if (getPullRequest() == null) {
        throw new NullPointerException("PullRequest went missing!!!");
    }
    boolean isMerged = getPresenter().isMerged(getPullRequest());
    adapter = new IssuesTimelineAdapter(getPresenter().getEvents(), this, true, this, isMerged, getPresenter(), getPullRequest().getLogin(), getPullRequest().getUser().getLogin());
    stateLayout.setEmptyText(R.string.no_events);
    recycler.setEmptyView(stateLayout, refresh);
    refresh.setOnRefreshListener(this);
    stateLayout.setOnReloadListener(this);
    adapter.setListener(getPresenter());
    recycler.setAdapter(adapter);
    fastScroller.setVisibility(View.VISIBLE);
    fastScroller.attachRecyclerView(recycler);
    recycler.addDivider(TimelineCommentsViewHolder.class);
    getLoadMore().initialize(getPresenter().getCurrentPage(), getPresenter().getPreviousTotal());
    recycler.addOnScrollListener(getLoadMore());
    if (savedInstanceState == null) {
        onSetHeader(new TimelineModel(getPullRequest()));
        onRefresh();
    } else if (getPresenter().getEvents().isEmpty() || getPresenter().getEvents().size() == 1) {
        onRefresh();
    }
}
Also used : IssuesTimelineAdapter(com.fastaccess.ui.adapter.IssuesTimelineAdapter) TimelineModel(com.fastaccess.data.dao.TimelineModel)

Example 4 with TimelineModel

use of com.fastaccess.data.dao.TimelineModel 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 5 with TimelineModel

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

the class IssueTimelinePresenter method loadComment.

private void loadComment(int page, long commentId, String login, String repoId, List<TimelineModel> timeline) {
    if (page == 1 && commentId > 0) {
        Observable<TimelineModel> observable = Observable.create(source -> {
            int index = -1;
            if (timeline != null) {
                for (int i = 0; i < timeline.size(); i++) {
                    TimelineModel timelineModel = timeline.get(i);
                    if (timelineModel.getComment() != null) {
                        if (timelineModel.getComment().getId() == commentId) {
                            index = i;
                            break;
                        }
                    }
                }
            }
            TimelineModel timelineModel = new TimelineModel();
            timelineModel.setPosition(index);
            source.onNext(timelineModel);
            source.onComplete();
        });
        manageObservable(observable.doOnNext(timelineModel -> sendToView(view -> {
            if (timelineModel.getComment() != null) {
                view.addComment(timelineModel, -1);
            } else {
                view.addComment(null, timelineModel.getPosition());
            }
        })));
    }
}
Also used : 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) Getter(lombok.Getter) 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) Issue(com.fastaccess.data.dao.model.Issue) 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) 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) BaseMvp(com.fastaccess.ui.base.mvp.BaseMvp) ReactionsProvider(com.fastaccess.provider.timeline.ReactionsProvider) List(java.util.List) R(com.fastaccess.R) FilterIssuesActivity(com.fastaccess.ui.modules.filter.issues.FilterIssuesActivity) TimelineConverter(com.fastaccess.provider.timeline.TimelineConverter) Nullable(android.support.annotation.Nullable) Activity(android.app.Activity) TimelineModel(com.fastaccess.data.dao.TimelineModel)

Aggregations

TimelineModel (com.fastaccess.data.dao.TimelineModel)8 Comment (com.fastaccess.data.dao.model.Comment)4 Bundle (android.os.Bundle)3 Activity (android.app.Activity)2 Uri (android.net.Uri)2 NonNull (android.support.annotation.NonNull)2 Nullable (android.support.annotation.Nullable)2 View (android.view.View)2 PopupMenu (android.widget.PopupMenu)2 R (com.fastaccess.R)2 CommentRequestModel (com.fastaccess.data.dao.CommentRequestModel)2 EditReviewCommentModel (com.fastaccess.data.dao.EditReviewCommentModel)2 ReactionsModel (com.fastaccess.data.dao.ReactionsModel)2 Issue (com.fastaccess.data.dao.model.Issue)2 Login (com.fastaccess.data.dao.model.Login)2 PullRequest (com.fastaccess.data.dao.model.PullRequest)2 GenericEvent (com.fastaccess.data.dao.timeline.GenericEvent)2 SourceModel (com.fastaccess.data.dao.timeline.SourceModel)2 ReactionTypes (com.fastaccess.data.dao.types.ReactionTypes)2 ActivityHelper (com.fastaccess.helper.ActivityHelper)2