Search in sources :

Example 1 with R

use of com.gh4a.R in project gh4a by slapperwan.

the class PullRequestActivity method loadPendingReview.

private void loadPendingReview(boolean force) {
    String ownLogin = Gh4Application.get().getAuthLogin();
    PullRequestReviewService service = ServiceFactory.get(PullRequestReviewService.class, force);
    ApiHelpers.PageIterator.toSingle(page -> service.getReviews(mRepoOwner, mRepoName, mPullRequestNumber, page)).compose(RxUtils.filterAndMapToFirst(r -> {
        return r.state() == ReviewState.Pending && ApiHelpers.loginEquals(r.user(), ownLogin);
    })).compose(makeLoaderSingle(1, force)).doOnSubscribe(disposable -> {
        mPendingReviewLoaded = false;
        supportInvalidateOptionsMenu();
    }).subscribe(result -> {
        mPendingReview = result.orNull();
        mPendingReviewLoaded = true;
        supportInvalidateOptionsMenu();
    }, this::handleLoadFailure);
}
Also used : Bundle(android.os.Bundle) PullRequestReviewService(com.meisolsson.githubsdk.service.pull_request.PullRequestReviewService) CommitCompareFragment(com.gh4a.fragment.CommitCompareFragment) PullRequestFragment(com.gh4a.fragment.PullRequestFragment) Uri(android.net.Uri) BottomSheetCompatibleScrollingViewBehavior(com.gh4a.widget.BottomSheetCompatibleScrollingViewBehavior) PullRequest(com.meisolsson.githubsdk.model.PullRequest) MergeRequest(com.meisolsson.githubsdk.model.request.pull_request.MergeRequest) IssueState(com.meisolsson.githubsdk.model.IssueState) Locale(java.util.Locale) Issue(com.meisolsson.githubsdk.model.Issue) View(android.view.View) IssueStateTrackingFloatingActionButton(com.gh4a.widget.IssueStateTrackingFloatingActionButton) AdapterView(android.widget.AdapterView) IntentUtils(com.gh4a.utils.IntentUtils) Review(com.meisolsson.githubsdk.model.Review) Fragment(android.support.v4.app.Fragment) ViewGroup(android.view.ViewGroup) TextView(android.widget.TextView) RxUtils(com.gh4a.utils.RxUtils) Triplet(com.gh4a.utils.Triplet) PullRequestFilesFragment(com.gh4a.fragment.PullRequestFilesFragment) ReviewState(com.meisolsson.githubsdk.model.ReviewState) Nullable(android.support.annotation.Nullable) Context(android.content.Context) AppBarLayout(android.support.design.widget.AppBarLayout) CoordinatorLayout(android.support.design.widget.CoordinatorLayout) Intent(android.content.Intent) StringRes(android.support.annotation.StringRes) NonNull(android.support.annotation.NonNull) Single(io.reactivex.Single) MenuItem(android.view.MenuItem) UiUtils(com.gh4a.utils.UiUtils) User(com.meisolsson.githubsdk.model.User) PullRequestService(com.meisolsson.githubsdk.service.pull_request.PullRequestService) Menu(android.view.Menu) R(com.gh4a.R) IssueService(com.meisolsson.githubsdk.service.issues.IssueService) ApiHelpers(com.gh4a.utils.ApiHelpers) BaseFragmentPagerActivity(com.gh4a.BaseFragmentPagerActivity) LayoutInflater(android.view.LayoutInflater) PullRequestMarker(com.meisolsson.githubsdk.model.PullRequestMarker) EditPullRequest(com.meisolsson.githubsdk.model.request.pull_request.EditPullRequest) Spinner(android.widget.Spinner) ArrayAdapter(android.widget.ArrayAdapter) AlertDialog(android.support.v7.app.AlertDialog) Gh4Application(com.gh4a.Gh4Application) SingleFactory(com.gh4a.utils.SingleFactory) ServiceFactory(com.gh4a.ServiceFactory) Activity(android.app.Activity) EditText(android.widget.EditText) PullRequestReviewService(com.meisolsson.githubsdk.service.pull_request.PullRequestReviewService)

Example 2 with R

use of com.gh4a.R in project gh4a by slapperwan.

the class PullRequestFragment method onCreateDataSingle.

@Override
protected Single<List<TimelineItem>> onCreateDataSingle(boolean bypassCache) {
    final int issueNumber = mIssue.number();
    final IssueEventService eventService = ServiceFactory.get(IssueEventService.class, bypassCache);
    final IssueCommentService commentService = ServiceFactory.get(IssueCommentService.class, bypassCache);
    final PullRequestService prService = ServiceFactory.get(PullRequestService.class, bypassCache);
    final PullRequestReviewService reviewService = ServiceFactory.get(PullRequestReviewService.class, bypassCache);
    final PullRequestReviewCommentService prCommentService = ServiceFactory.get(PullRequestReviewCommentService.class, bypassCache);
    Single<List<TimelineItem>> issueCommentItemSingle = ApiHelpers.PageIterator.toSingle(page -> commentService.getIssueComments(mRepoOwner, mRepoName, issueNumber, page)).compose(RxUtils.mapList(TimelineItem.TimelineComment::new));
    Single<List<TimelineItem>> eventItemSingle = ApiHelpers.PageIterator.toSingle(page -> eventService.getIssueEvents(mRepoOwner, mRepoName, issueNumber, page)).compose(RxUtils.filter(event -> INTERESTING_EVENTS.contains(event.event()))).compose((RxUtils.mapList(TimelineItem.TimelineEvent::new)));
    Single<Map<String, GitHubFile>> filesByNameSingle = ApiHelpers.PageIterator.toSingle(page -> prService.getPullRequestFiles(mRepoOwner, mRepoName, issueNumber, page)).map(files -> {
        Map<String, GitHubFile> filesByName = new HashMap<>();
        for (GitHubFile file : files) {
            filesByName.put(file.filename(), file);
        }
        return filesByName;
    }).cache();
    Single<List<Review>> reviewSingle = ApiHelpers.PageIterator.toSingle(page -> reviewService.getReviews(mRepoOwner, mRepoName, issueNumber, page)).cache();
    Single<List<ReviewComment>> prCommentSingle = ApiHelpers.PageIterator.toSingle(page -> prCommentService.getPullRequestComments(mRepoOwner, mRepoName, issueNumber, page)).compose(RxUtils.sortList(ApiHelpers.COMMENT_COMPARATOR)).cache();
    Single<LongSparseArray<List<ReviewComment>>> reviewCommentsByIdSingle = reviewSingle.compose(RxUtils.filter(r -> r.state() == ReviewState.Pending)).toObservable().flatMap(reviews -> {
        List<Observable<Pair<Long, List<ReviewComment>>>> obsList = new ArrayList<>();
        for (Review r : reviews) {
            Single<List<ReviewComment>> single = ApiHelpers.PageIterator.toSingle(page -> reviewService.getReviewComments(mRepoOwner, mRepoName, issueNumber, r.id()));
            obsList.add(Single.zip(Single.just(r.id()), single, Pair::create).toObservable());
        }
        return Observable.concat(obsList);
    }).toList().map(list -> {
        LongSparseArray<List<ReviewComment>> result = new LongSparseArray<>();
        for (Pair<Long, List<ReviewComment>> pair : list) {
            result.put(pair.first, pair.second);
        }
        return result;
    });
    Single<List<TimelineItem.TimelineReview>> reviewTimelineSingle = Single.zip(reviewSingle, filesByNameSingle, prCommentSingle, reviewCommentsByIdSingle, (prReviews, filesByName, commitComments, pendingCommentsById) -> {
        LongSparseArray<TimelineItem.TimelineReview> reviewsById = new LongSparseArray<>();
        List<TimelineItem.TimelineReview> reviews = new ArrayList<>();
        for (Review review : prReviews) {
            TimelineItem.TimelineReview timelineReview = new TimelineItem.TimelineReview(review);
            reviewsById.put(review.id(), timelineReview);
            reviews.add(timelineReview);
            if (review.state() == ReviewState.Pending) {
                for (ReviewComment pendingComment : pendingCommentsById.get(review.id())) {
                    GitHubFile commitFile = filesByName.get(pendingComment.path());
                    timelineReview.addComment(pendingComment, commitFile, true);
                }
            }
        }
        Map<String, TimelineItem.TimelineReview> reviewsBySpecialId = new HashMap<>();
        for (ReviewComment commitComment : commitComments) {
            GitHubFile file = filesByName.get(commitComment.path());
            if (commitComment.pullRequestReviewId() != null) {
                String id = TimelineItem.Diff.getDiffHunkId(commitComment);
                TimelineItem.TimelineReview review = reviewsBySpecialId.get(id);
                if (review == null) {
                    review = reviewsById.get(commitComment.pullRequestReviewId());
                    reviewsBySpecialId.put(id, review);
                }
                review.addComment(commitComment, file, true);
            }
        }
        return reviews;
    }).compose(RxUtils.filter(item -> {
        // noinspection CodeBlock2Expr
        return item.review().state() != ReviewState.Commented || !TextUtils.isEmpty(item.review().body()) || !item.getDiffHunks().isEmpty();
    }));
    Single<List<TimelineItem.TimelineComment>> commitCommentWithoutReviewSingle = Single.zip(prCommentSingle.compose(RxUtils.filter(comment -> comment.pullRequestReviewId() == 0)), filesByNameSingle, (comments, files) -> {
        List<TimelineItem.TimelineComment> items = new ArrayList<>();
        for (ReviewComment comment : comments) {
            items.add(new TimelineItem.TimelineComment(comment, files.get(comment.path())));
        }
        return items;
    });
    return Single.zip(issueCommentItemSingle, eventItemSingle, reviewTimelineSingle, commitCommentWithoutReviewSingle, (comments, events, reviewItems, commentsWithoutReview) -> {
        ArrayList<TimelineItem> result = new ArrayList<>();
        result.addAll(comments);
        result.addAll(events);
        result.addAll(reviewItems);
        result.addAll(commentsWithoutReview);
        Collections.sort(result, TimelineItem.COMPARATOR);
        return result;
    });
}
Also used : HttpURLConnection(java.net.HttpURLConnection) IssueCommentService(com.meisolsson.githubsdk.service.issues.IssueCommentService) Bundle(android.os.Bundle) PullRequestReviewService(com.meisolsson.githubsdk.service.pull_request.PullRequestReviewService) Status(com.meisolsson.githubsdk.model.Status) GitHubFile(com.meisolsson.githubsdk.model.GitHubFile) RepositoryStatusService(com.meisolsson.githubsdk.service.repositories.RepositoryStatusService) PullRequest(com.meisolsson.githubsdk.model.PullRequest) PullRequestReviewCommentService(com.meisolsson.githubsdk.service.pull_request.PullRequestReviewCommentService) IssueState(com.meisolsson.githubsdk.model.IssueState) Map(java.util.Map) Issue(com.meisolsson.githubsdk.model.Issue) View(android.view.View) AttrRes(android.support.annotation.AttrRes) PullRequestBranchInfoView(com.gh4a.widget.PullRequestBranchInfoView) IntentUtils(com.gh4a.utils.IntentUtils) Review(com.meisolsson.githubsdk.model.Review) Set(java.util.Set) EditPullRequestCommentActivity(com.gh4a.activities.EditPullRequestCommentActivity) List(java.util.List) RxUtils(com.gh4a.utils.RxUtils) GitService(com.meisolsson.githubsdk.service.git.GitService) Optional(com.gh4a.utils.Optional) EditIssueCommentActivity(com.gh4a.activities.EditIssueCommentActivity) TimelineItem(com.gh4a.model.TimelineItem) ReviewState(com.meisolsson.githubsdk.model.ReviewState) Repository(com.meisolsson.githubsdk.model.Repository) LongSparseArray(android.support.v4.util.LongSparseArray) Pair(android.util.Pair) GitHubCommentBase(com.meisolsson.githubsdk.model.GitHubCommentBase) Intent(android.content.Intent) HashMap(java.util.HashMap) GitReference(com.meisolsson.githubsdk.model.git.GitReference) Response(retrofit2.Response) Single(io.reactivex.Single) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) PullRequestService(com.meisolsson.githubsdk.service.pull_request.PullRequestService) MenuInflater(android.view.MenuInflater) CommitStatusBox(com.gh4a.widget.CommitStatusBox) IssueEventService(com.meisolsson.githubsdk.service.issues.IssueEventService) Menu(android.view.Menu) R(com.gh4a.R) Observable(io.reactivex.Observable) CreateGitReference(com.meisolsson.githubsdk.model.request.git.CreateGitReference) ApiHelpers(com.gh4a.utils.ApiHelpers) Iterator(java.util.Iterator) PullRequestMarker(com.meisolsson.githubsdk.model.PullRequestMarker) ReviewComment(com.meisolsson.githubsdk.model.ReviewComment) TextUtils(android.text.TextUtils) AlertDialog(android.support.v7.app.AlertDialog) ServiceFactory(com.gh4a.ServiceFactory) Comparator(java.util.Comparator) Collections(java.util.Collections) IssueCommentService(com.meisolsson.githubsdk.service.issues.IssueCommentService) LongSparseArray(android.support.v4.util.LongSparseArray) ArrayList(java.util.ArrayList) Review(com.meisolsson.githubsdk.model.Review) PullRequestService(com.meisolsson.githubsdk.service.pull_request.PullRequestService) GitHubFile(com.meisolsson.githubsdk.model.GitHubFile) List(java.util.List) ArrayList(java.util.ArrayList) IssueEventService(com.meisolsson.githubsdk.service.issues.IssueEventService) PullRequestReviewCommentService(com.meisolsson.githubsdk.service.pull_request.PullRequestReviewCommentService) Pair(android.util.Pair) TimelineItem(com.gh4a.model.TimelineItem) ReviewComment(com.meisolsson.githubsdk.model.ReviewComment) Observable(io.reactivex.Observable) Map(java.util.Map) HashMap(java.util.HashMap) PullRequestReviewService(com.meisolsson.githubsdk.service.pull_request.PullRequestReviewService)

Aggregations

Intent (android.content.Intent)2 Bundle (android.os.Bundle)2 AlertDialog (android.support.v7.app.AlertDialog)2 Menu (android.view.Menu)2 MenuItem (android.view.MenuItem)2 View (android.view.View)2 R (com.gh4a.R)2 ServiceFactory (com.gh4a.ServiceFactory)2 ApiHelpers (com.gh4a.utils.ApiHelpers)2 IntentUtils (com.gh4a.utils.IntentUtils)2 RxUtils (com.gh4a.utils.RxUtils)2 Issue (com.meisolsson.githubsdk.model.Issue)2 IssueState (com.meisolsson.githubsdk.model.IssueState)2 PullRequest (com.meisolsson.githubsdk.model.PullRequest)2 Activity (android.app.Activity)1 Context (android.content.Context)1 Uri (android.net.Uri)1 AttrRes (android.support.annotation.AttrRes)1 NonNull (android.support.annotation.NonNull)1 Nullable (android.support.annotation.Nullable)1