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);
}
}
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();
}
}
}
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();
}
}
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;
}
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());
}
})));
}
}
Aggregations