use of com.gh4a.utils.Optional in project gh4a by slapperwan.
the class ReleaseInfoActivity method loadBody.
private void loadBody() {
final Single<Optional<String>> htmlSingle;
if (TextUtils.isEmpty(mRelease.body())) {
htmlSingle = Single.just(Optional.absent());
} else {
MarkdownService service = ServiceFactory.get(MarkdownService.class, false);
RequestMarkdown request = RequestMarkdown.builder().context(mRepoOwner + "/" + mRepoName).mode("gfm").text(mRelease.body()).build();
htmlSingle = service.renderMarkdown(request).map(ApiHelpers::throwOnFailure).map(Optional::of);
}
mBodySubscription = htmlSingle.compose(makeLoaderSingle(ID_LOADER_BODY, false)).subscribe(this::fillNotes, this::handleLoadFailure);
}
use of com.gh4a.utils.Optional in project gh4a by slapperwan.
the class CommitCommentLoadTask method load.
public static Single<Optional<Intent>> load(Context context, String repoOwner, String repoName, String commitSha, IntentUtils.InitialCommentMarker marker) {
RepositoryCommitService commitService = ServiceFactory.get(RepositoryCommitService.class, false);
RepositoryCommentService commentService = ServiceFactory.get(RepositoryCommentService.class, false);
Single<Commit> commitSingle = commitService.getCommit(repoOwner, repoName, commitSha).map(ApiHelpers::throwOnFailure);
Single<List<GitComment>> commentSingle = ApiHelpers.PageIterator.toSingle(page -> commentService.getCommitComments(repoOwner, repoName, commitSha, page)).cache();
Single<Optional<GitHubFile>> fileSingle = commentSingle.compose(RxUtils.filterAndMapToFirst(c -> marker.matches(c.id(), c.createdAt()))).zipWith(commitSingle, (comment, commit) -> {
if (comment.isPresent()) {
for (GitHubFile commitFile : commit.files()) {
if (commitFile.filename().equals(comment.get().path())) {
return Optional.of(commitFile);
}
}
}
return Optional.absent();
});
return Single.zip(commitSingle, commentSingle, fileSingle, (commit, comments, fileOpt) -> {
GitHubFile file = fileOpt.orNull();
if (file != null && !FileUtils.isImage(file.filename())) {
return Optional.of(CommitDiffViewerActivity.makeIntent(context, repoOwner, repoName, commitSha, file.filename(), file.patch(), comments, -1, -1, false, marker));
} else if (file == null) {
return Optional.of(CommitActivity.makeIntent(context, repoOwner, repoName, commitSha, marker));
}
return Optional.absent();
});
}
use of com.gh4a.utils.Optional in project gh4a by slapperwan.
the class PullRequestReviewDiffLoadTask method getSingle.
@Override
protected Single<Optional<Intent>> getSingle() {
final PullRequestReviewCommentService service = ServiceFactory.get(PullRequestReviewCommentService.class, false);
final PullRequestReviewService reviewService = ServiceFactory.get(PullRequestReviewService.class, false);
long diffCommentId = Long.parseLong(mDiffId.fileHash);
return ApiHelpers.PageIterator.toSingle(page -> service.getPullRequestComments(mRepoOwner, mRepoName, mPullRequestNumber, page)).compose(RxUtils.filterAndMapToFirst(c -> c.id() == diffCommentId)).flatMap(commentOpt -> commentOpt.flatMap(comment -> {
long reviewId = comment.pullRequestReviewId();
return reviewService.getReview(mRepoOwner, mRepoName, mPullRequestNumber, reviewId).map(ApiHelpers::throwOnFailure);
})).map(reviewOpt -> reviewOpt.map(review -> ReviewActivity.makeIntent(mActivity, mRepoOwner, mRepoName, mPullRequestNumber, review, new IntentUtils.InitialCommentMarker(diffCommentId))));
}
use of com.gh4a.utils.Optional in project gh4a by slapperwan.
the class ReactionBar method toggleReaction.
private static Single<Optional<Reaction>> toggleReaction(String content, long id, List<Reaction> existingDetails, Callback callback, Item item, ReactionDetailsCache cache) {
final Single<Optional<Reaction>> resultSingle;
if (id == 0) {
resultSingle = callback.addReaction(item, content).map(Optional::of);
} else {
ReactionService service = ServiceFactory.get(ReactionService.class, false);
resultSingle = service.deleteReaction(id).map(response -> Optional.absent());
}
return resultSingle.compose(RxUtils::doInBackground).doOnSuccess(reactionOpt -> {
if (reactionOpt.isPresent()) {
existingDetails.add(reactionOpt.get());
} else {
for (int i = 0; i < existingDetails.size(); i++) {
Reaction reaction = existingDetails.get(i);
if (reaction.id() == id) {
existingDetails.remove(i);
break;
}
}
}
cache.putEntry(item, existingDetails);
});
}
use of com.gh4a.utils.Optional in project gh4a by slapperwan.
the class RepositoryFragment method loadReadme.
private void loadReadme(boolean force) {
Context context = getActivity();
Long id = mRepository.id();
String repoOwner = mRepository.owner().login();
String repoName = mRepository.name();
RepositoryContentService service = ServiceFactory.get(RepositoryContentService.class, force);
service.getReadmeHtml(repoOwner, repoName, mRef).map(ApiHelpers::throwOnFailure).map(Optional::of).compose(RxUtils.mapFailureToValue(HttpURLConnection.HTTP_NOT_FOUND, Optional.<String>absent())).map(htmlOpt -> {
if (htmlOpt.isPresent()) {
String html = HtmlUtils.rewriteRelativeUrls(htmlOpt.get(), repoOwner, repoName, mRef != null ? mRef : mRepository.defaultBranch());
mImageGetter.encode(context, id, html);
return Optional.of(html);
}
return Optional.<String>absent();
}).compose(makeLoaderSingle(ID_LOADER_README, force)).doOnSubscribe(disposable -> {
mIsReadmeLoaded = false;
updateReadmeVisibility();
}).subscribe(readmeOpt -> {
if (readmeOpt.isPresent()) {
mReadmeView.setMovementMethod(UiUtils.CHECKING_LINK_METHOD);
mImageGetter.bind(mReadmeView, readmeOpt.get(), id);
} else {
mReadmeView.setText(R.string.repo_no_readme);
mReadmeView.setTypeface(Typeface.DEFAULT, Typeface.ITALIC);
}
mIsReadmeLoaded = true;
updateReadmeVisibility();
}, this::handleLoadFailure);
}
Aggregations