Search in sources :

Example 1 with RepositoryContentService

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);
}
Also used : ApiRequestException(com.gh4a.ApiRequestException) ClientErrorResponse(com.meisolsson.githubsdk.model.ClientErrorResponse) RepositoryContentService(com.meisolsson.githubsdk.service.repositories.RepositoryContentService) ApiHelpers(com.gh4a.utils.ApiHelpers)

Example 2 with RepositoryContentService

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));
}
Also used : Content(com.meisolsson.githubsdk.model.Content) RepositoryContentService(com.meisolsson.githubsdk.service.repositories.RepositoryContentService)

Example 3 with RepositoryContentService

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);
}
Also used : Context(android.content.Context) Typeface(android.graphics.Typeface) ContributorListActivity(com.gh4a.activities.ContributorListActivity) HttpURLConnection(java.net.HttpURLConnection) Context(android.content.Context) LinearLayout(android.widget.LinearLayout) Repository(com.meisolsson.githubsdk.model.Repository) Bundle(android.os.Bundle) Intent(android.content.Intent) UserActivity(com.gh4a.activities.UserActivity) WikiListActivity(com.gh4a.activities.WikiListActivity) UiUtils(com.gh4a.utils.UiUtils) WatcherListActivity(com.gh4a.activities.WatcherListActivity) SpannableStringBuilder(android.text.SpannableStringBuilder) ForkListActivity(com.gh4a.activities.ForkListActivity) EmojiParser(com.vdurmont.emoji.EmojiParser) Permissions(com.meisolsson.githubsdk.model.Permissions) SearchService(com.meisolsson.githubsdk.service.search.SearchService) Locale(java.util.Locale) R(com.gh4a.R) View(android.view.View) IntentSpan(com.gh4a.widget.IntentSpan) HttpImageGetter(com.gh4a.utils.HttpImageGetter) StringUtils(com.gh4a.utils.StringUtils) HtmlUtils(com.gh4a.utils.HtmlUtils) ApiHelpers(com.gh4a.utils.ApiHelpers) LayoutInflater(android.view.LayoutInflater) ReleaseListActivity(com.gh4a.activities.ReleaseListActivity) ViewGroup(android.view.ViewGroup) RepositoryContentService(com.meisolsson.githubsdk.service.repositories.RepositoryContentService) TextView(android.widget.TextView) RepositoryActivity(com.gh4a.activities.RepositoryActivity) RxUtils(com.gh4a.utils.RxUtils) Optional(com.gh4a.utils.Optional) CollaboratorListActivity(com.gh4a.activities.CollaboratorListActivity) IssueListActivity(com.gh4a.activities.IssueListActivity) ServiceFactory(com.gh4a.ServiceFactory) SearchPage(com.meisolsson.githubsdk.model.SearchPage) OnClickListener(android.view.View.OnClickListener) RepositoryContentService(com.meisolsson.githubsdk.service.repositories.RepositoryContentService) ApiHelpers(com.gh4a.utils.ApiHelpers)

Example 4 with RepositoryContentService

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));
}
Also used : HttpURLConnection(java.net.HttpURLConnection) Bundle(android.os.Bundle) ImageView(android.widget.ImageView) IssueMilestoneService(com.meisolsson.githubsdk.service.issues.IssueMilestoneService) TextInputLayout(android.support.design.widget.TextInputLayout) MarkdownPreviewWebView(com.gh4a.widget.MarkdownPreviewWebView) IssueState(com.meisolsson.githubsdk.model.IssueState) Label(com.meisolsson.githubsdk.model.Label) Locale(java.util.Locale) ContentType(com.meisolsson.githubsdk.model.ContentType) Issue(com.meisolsson.githubsdk.model.Issue) View(android.view.View) StringUtils(com.gh4a.utils.StringUtils) FloatingActionButton(android.support.design.widget.FloatingActionButton) ContextCompat(android.support.v4.content.ContextCompat) IssueLabelService(com.meisolsson.githubsdk.service.issues.IssueLabelService) ViewGroup(android.view.ViewGroup) RepositoryContentService(com.meisolsson.githubsdk.service.repositories.RepositoryContentService) List(java.util.List) TextView(android.widget.TextView) RxUtils(com.gh4a.utils.RxUtils) Optional(com.gh4a.utils.Optional) Nullable(android.support.annotation.Nullable) Typeface(android.graphics.Typeface) Context(android.content.Context) AppBarLayout(android.support.design.widget.AppBarLayout) CoordinatorLayout(android.support.design.widget.CoordinatorLayout) MarkdownButtonsBar(com.gh4a.widget.MarkdownButtonsBar) BasePagerActivity(com.gh4a.BasePagerActivity) Intent(android.content.Intent) Response(retrofit2.Response) Single(io.reactivex.Single) UiUtils(com.gh4a.utils.UiUtils) ArrayList(java.util.ArrayList) User(com.meisolsson.githubsdk.model.User) AvatarHandler(com.gh4a.utils.AvatarHandler) Milestone(com.meisolsson.githubsdk.model.Milestone) Content(com.meisolsson.githubsdk.model.Content) R(com.gh4a.R) IssueRequest(com.meisolsson.githubsdk.model.request.issue.IssueRequest) IssueService(com.meisolsson.githubsdk.service.issues.IssueService) RepositoryCollaboratorService(com.meisolsson.githubsdk.service.repositories.RepositoryCollaboratorService) DialogInterface(android.content.DialogInterface) ApiHelpers(com.gh4a.utils.ApiHelpers) LayoutInflater(android.view.LayoutInflater) PagerAdapter(android.support.v4.view.PagerAdapter) IdRes(android.support.annotation.IdRes) AlertDialog(android.support.v7.app.AlertDialog) Gh4Application(com.gh4a.Gh4Application) ObjectsCompat(android.support.v4.util.ObjectsCompat) SingleFactory(com.gh4a.utils.SingleFactory) ServiceFactory(com.gh4a.ServiceFactory) EditText(android.widget.EditText) RepositoryContentService(com.meisolsson.githubsdk.service.repositories.RepositoryContentService) ApiHelpers(com.gh4a.utils.ApiHelpers)

Example 5 with RepositoryContentService

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);
}
Also used : PathBreadcrumbs(com.gh4a.widget.PathBreadcrumbs) HttpURLConnection(java.net.HttpURLConnection) Context(android.content.Context) Repository(com.meisolsson.githubsdk.model.Repository) Bundle(android.os.Bundle) FileViewerActivity(com.gh4a.activities.FileViewerActivity) Uri(android.net.Uri) HashMap(java.util.HashMap) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) Stack(java.util.Stack) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) Commit(com.meisolsson.githubsdk.model.Commit) SwipeRefreshLayout(com.gh4a.widget.SwipeRefreshLayout) RxLoader(com.philosophicalhacker.lib.RxLoader) Content(com.meisolsson.githubsdk.model.Content) Map(java.util.Map) R(com.gh4a.R) ContentType(com.meisolsson.githubsdk.model.ContentType) View(android.view.View) Schedulers(io.reactivex.schedulers.Schedulers) StringUtils(com.gh4a.utils.StringUtils) ApiHelpers(com.gh4a.utils.ApiHelpers) LayoutInflater(android.view.LayoutInflater) Fragment(android.support.v4.app.Fragment) Set(java.util.Set) TextUtils(android.text.TextUtils) ViewGroup(android.view.ViewGroup) RepositoryContentService(com.meisolsson.githubsdk.service.repositories.RepositoryContentService) FragmentManager(android.support.v4.app.FragmentManager) List(java.util.List) RepositoryActivity(com.gh4a.activities.RepositoryActivity) RxUtils(com.gh4a.utils.RxUtils) Optional(com.gh4a.utils.Optional) Nullable(android.support.annotation.Nullable) ServiceFactory(com.gh4a.ServiceFactory) FragmentTransaction(android.support.v4.app.FragmentTransaction) BaseActivity(com.gh4a.BaseActivity) Content(com.meisolsson.githubsdk.model.Content) RepositoryContentService(com.meisolsson.githubsdk.service.repositories.RepositoryContentService) ApiHelpers(com.gh4a.utils.ApiHelpers)

Aggregations

RepositoryContentService (com.meisolsson.githubsdk.service.repositories.RepositoryContentService)5 ApiHelpers (com.gh4a.utils.ApiHelpers)4 Context (android.content.Context)3 Bundle (android.os.Bundle)3 LayoutInflater (android.view.LayoutInflater)3 View (android.view.View)3 ViewGroup (android.view.ViewGroup)3 R (com.gh4a.R)3 ServiceFactory (com.gh4a.ServiceFactory)3 Optional (com.gh4a.utils.Optional)3 RxUtils (com.gh4a.utils.RxUtils)3 StringUtils (com.gh4a.utils.StringUtils)3 Content (com.meisolsson.githubsdk.model.Content)3 HttpURLConnection (java.net.HttpURLConnection)3 Intent (android.content.Intent)2 Typeface (android.graphics.Typeface)2 Nullable (android.support.annotation.Nullable)2 TextView (android.widget.TextView)2 RepositoryActivity (com.gh4a.activities.RepositoryActivity)2 UiUtils (com.gh4a.utils.UiUtils)2