use of com.gh4a.utils.RxUtils in project gh4a by slapperwan.
the class SearchFragment method makeRepoSearchSingle.
private Single<Response<Page<Object>>> makeRepoSearchSingle(long page, boolean bypassCache) {
SearchService service = ServiceFactory.get(SearchService.class, bypassCache);
String params = mQuery + " fork:true";
return service.searchRepositories(params, null, null, page).compose(result -> RxUtils.<Repository, Object>searchPageAdapter(result, item -> item)).compose(RxUtils.mapFailureToValue(422, Response.success(new ApiHelpers.DummyPage<>())));
}
use of com.gh4a.utils.RxUtils in project gh4a by slapperwan.
the class UserPasswordLoginDialogFragment method makeRequestSingle.
private Single<LoginService.AuthorizationRequest> makeRequestSingle() {
String description = "Octodroid - " + Build.MANUFACTURER + " " + Build.MODEL;
String fingerprint = getHashedDeviceId();
LoginService service = getService();
String scopes = getArguments().getString("scopes");
return service.getAuthorizations().map(ApiHelpers::throwOnFailure).compose(RxUtils::doInBackground).retryWhen(handler -> handler.flatMap(error -> {
if (error instanceof ApiRequestException) {
ApiRequestException are = (ApiRequestException) error;
if (are.getStatus() == 401 && are.getResponse().message().contains("OTP code")) {
mWaitingForOtpCode = true;
mHandler.post(() -> updateContainerVisibility(false));
// getAuthorizations() doesn't trigger the OTP SMS for whatever reason,
// so make a dummy create request (which we know will fail) just to
// actually trigger SMS sending
LoginService.AuthorizationRequest dummyRequest = new LoginService.AuthorizationRequest("", "dummy", "");
service.createAuthorization(dummyRequest).compose(RxUtils::doInBackground).subscribe(ignoredResponse -> {
}, ignoredError -> {
});
}
}
if (!mWaitingForOtpCode) {
mRetryProcessor.onError(error);
}
return mRetryProcessor;
})).compose(RxUtils.filter(authorization -> {
String note = authorization.note();
return note != null && note.startsWith(description);
})).flatMap(existingAuthorizations -> {
Single<Void> deleteSingle = null;
Iterator<LoginService.AuthorizationResponse> iter = existingAuthorizations.iterator();
while (iter.hasNext()) {
LoginService.AuthorizationResponse auth = iter.next();
if (fingerprint.equals(auth.fingerprint())) {
deleteSingle = service.deleteAuthorization(auth.id()).map(ApiHelpers::throwOnFailure).compose(RxUtils::doInBackground);
iter.remove();
}
}
String finalDescription = description;
if (!existingAuthorizations.isEmpty()) {
finalDescription += " #" + (existingAuthorizations.size() + 1);
}
LoginService.AuthorizationRequest request = new LoginService.AuthorizationRequest(scopes, finalDescription, fingerprint);
if (deleteSingle != null) {
return deleteSingle.map(response -> request);
} else {
return Single.just(request);
}
});
}
use of com.gh4a.utils.RxUtils in project gh4a by slapperwan.
the class IssueListActivity method filterAssignee.
private void filterAssignee() {
if (mAssignees != null) {
showAssigneesDialog();
} else {
final IssueAssigneeService service = ServiceFactory.get(IssueAssigneeService.class, false);
registerTemporarySubscription(ApiHelpers.PageIterator.toSingle(page -> service.getAssignees(mRepoOwner, mRepoName, page)).compose(RxUtils::doInBackground).compose(RxUtils.wrapWithProgressDialog(this, R.string.loading_msg)).subscribe(assignees -> {
mAssignees = assignees;
showAssigneesDialog();
}, this::handleLoadFailure));
}
}
use of com.gh4a.utils.RxUtils in project gh4a by slapperwan.
the class IssueListActivity method filterLabel.
private void filterLabel() {
if (mLabels != null) {
showLabelsDialog();
} else {
final IssueLabelService service = ServiceFactory.get(IssueLabelService.class, false);
registerTemporarySubscription(ApiHelpers.PageIterator.toSingle(page -> service.getRepositoryLabels(mRepoOwner, mRepoName, page)).compose(RxUtils::doInBackground).compose(RxUtils.wrapWithProgressDialog(this, R.string.loading_msg)).subscribe(labels -> {
mLabels = labels;
showLabelsDialog();
}, this::handleLoadFailure));
}
}
use of com.gh4a.utils.RxUtils in project gh4a by slapperwan.
the class RepositoryActivity method loadOrShowRefSelection.
private void loadOrShowRefSelection() {
if (mBranches != null) {
showRefSelectionDialog();
} else {
final RepositoryBranchService branchService = ServiceFactory.get(RepositoryBranchService.class, false);
final RepositoryService repoService = ServiceFactory.get(RepositoryService.class, false);
Single<List<Branch>> branchSingle = ApiHelpers.PageIterator.toSingle(page -> branchService.getBranches(mRepoOwner, mRepoName, page));
Single<List<Branch>> tagSingle = ApiHelpers.PageIterator.toSingle(page -> repoService.getTags(mRepoOwner, mRepoName, page));
registerTemporarySubscription(Single.zip(branchSingle, tagSingle, Pair::create).compose(RxUtils::doInBackground).compose(RxUtils.wrapWithProgressDialog(this, R.string.loading_msg)).subscribe(result -> {
mBranches = result.first;
mTags = result.second;
showRefSelectionDialog();
}, this::handleLoadFailure));
}
}
Aggregations