use of com.meisolsson.githubsdk.service.repositories.RepositoryContentService in project gh4a by slapperwan.
the class FileViewerActivity method loadFile.
private void loadFile(boolean force) {
RepositoryContentService service = ServiceFactory.get(RepositoryContentService.class, force);
service.getContents(mRepoOwner, mRepoName, mPath, mRef).map(ApiHelpers::throwOnFailure).map(Optional::of).onErrorResumeNext(error -> {
if (error instanceof ApiRequestException) {
ClientErrorResponse response = ((ApiRequestException) error).getResponse();
List<ClientErrorResponse.FieldError> errors = response != null ? response.errors() : null;
if (errors != null) {
for (ClientErrorResponse.FieldError fe : errors) {
if (fe.reason() == ClientErrorResponse.FieldError.Reason.TooLarge) {
openUnsuitableFileAndFinish();
return Single.just(Optional.absent());
}
}
}
}
return Single.error(error);
}).compose(makeLoaderSingle(ID_LOADER_FILE, force)).subscribe(result -> {
if (result.isPresent()) {
mContent = result.get();
onDataReady();
setContentEmpty(false);
} else {
setContentEmpty(true);
setContentShown(true);
}
}, this::handleLoadFailure);
}
use of com.meisolsson.githubsdk.service.repositories.RepositoryContentService in project gh4a by slapperwan.
the class ContentListFragment method onCreateDataSingle.
@Override
protected Single<List<Content>> onCreateDataSingle(boolean bypassCache) {
ArrayList<Content> contents = getArguments().getParcelableArrayList("contents");
if (contents != null && !contents.isEmpty()) {
return Single.just(contents);
}
RepositoryContentService contentService = ServiceFactory.get(RepositoryContentService.class, bypassCache);
String repoOwner = mRepository.owner().login();
String repoName = mRepository.name();
String ref = mRef != null ? mRef : mRepository.defaultBranch();
return ApiHelpers.PageIterator.toSingle(page -> contentService.getDirectoryContents(repoOwner, repoName, mPath, ref, page)).compose(RxUtils.mapFailureToValue(HttpURLConnection.HTTP_NOT_FOUND, new ArrayList<Content>())).compose(RxUtils.sortList(COMPARATOR));
}
use of com.meisolsson.githubsdk.service.repositories.RepositoryContentService 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);
}
use of com.meisolsson.githubsdk.service.repositories.RepositoryContentService in project gh4a by slapperwan.
the class IssueEditActivity method loadIssueTemplate.
private void loadIssueTemplate() {
RepositoryContentService service = ServiceFactory.get(RepositoryContentService.class, false);
registerTemporarySubscription(getIssueTemplateContentSingle("/.github").flatMap(opt -> opt.orOptionalSingle(() -> getIssueTemplateContentSingle(""))).flatMap(opt -> opt.orOptionalSingle(() -> getIssueTemplateContentSingle("/docs"))).flatMap(opt -> opt.flatMap(c -> {
// noinspection CodeBlock2Expr
return service.getContents(mRepoOwner, mRepoName, c.path(), null).map(ApiHelpers::throwOnFailure).compose(RxUtils::doInBackground);
})).map(opt -> opt.map(c -> StringUtils.fromBase64(c.content()))).compose(RxUtils.wrapWithProgressDialog(this, R.string.loading_msg)).subscribe(result -> {
mDescView.setHint(null);
mDescView.setEnabled(true);
mDescView.setText(result.orNull());
}, this::handleLoadFailure));
}
use of com.meisolsson.githubsdk.service.repositories.RepositoryContentService in project gh4a by slapperwan.
the class ContentListContainerFragment method loadModuleMap.
private void loadModuleMap() {
RepositoryContentService service = ServiceFactory.get(RepositoryContentService.class, false);
String repoOwner = mRepository.owner().login();
String repoName = mRepository.name();
service.getContents(repoOwner, repoName, ".gitmodules", mSelectedRef).map(ApiHelpers::throwOnFailure).map(Optional::of).compose(RxUtils.mapFailureToValue(HttpURLConnection.HTTP_NOT_FOUND, Optional.<Content>absent())).map(contentOpt -> contentOpt.map(content -> StringUtils.fromBase64(content.content()))).map(this::parseModuleMap).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).compose(mRxLoader.makeSingleTransformer(ID_LOADER_MODULEMAP, true)).subscribe(resultOpt -> {
mGitModuleMap = resultOpt.orNull();
if (mContentListFragment != null) {
mContentListFragment.onSubModuleNamesChanged(getSubModuleNames(mContentListFragment));
}
}, ((BaseActivity) getActivity())::handleLoadFailure);
}
Aggregations