Search in sources :

Example 1 with RepositoryBranchService

use of com.meisolsson.githubsdk.service.repositories.RepositoryBranchService in project gh4a by slapperwan.

the class RefPathDisambiguationTask method resolve.

// returns ref, path
private Single<Optional<Pair<String, String>>> resolve() throws ApiRequestException {
    // first check whether the path redirects to HEAD
    if (mRefAndPath.startsWith("HEAD")) {
        return Single.just(Optional.of(Pair.create("HEAD", mRefAndPath.startsWith("HEAD/") ? mRefAndPath.substring(5) : null)));
    }
    final RepositoryBranchService branchService = ServiceFactory.get(RepositoryBranchService.class, false);
    final RepositoryService repoService = ServiceFactory.get(RepositoryService.class, false);
    // then look for matching branches
    return ApiHelpers.PageIterator.toSingle(page -> branchService.getBranches(mRepoOwner, mRepoName, page)).compose(this::matchBranch).flatMap(result -> result.orOptionalSingle(() -> ApiHelpers.PageIterator.toSingle(page -> repoService.getTags(mRepoOwner, mRepoName, page)).compose(this::matchBranch))).map(resultOpt -> resultOpt.orOptional(() -> {
        // at this point, the first item may still be a SHA1 - check with a simple regex
        int slashPos = mRefAndPath.indexOf('/');
        String potentialSha = slashPos > 0 ? mRefAndPath.substring(0, slashPos) : mRefAndPath;
        if (SHA1_PATTERN.matcher(potentialSha).matches()) {
            return Optional.of(Pair.create(potentialSha, slashPos > 0 ? mRefAndPath.substring(slashPos + 1) : ""));
        }
        return Optional.absent();
    }));
}
Also used : RepositoryBranchService(com.meisolsson.githubsdk.service.repositories.RepositoryBranchService) FileViewerActivity(com.gh4a.activities.FileViewerActivity) ApiHelpers(com.gh4a.utils.ApiHelpers) Pair(android.util.Pair) RepositoryService(com.meisolsson.githubsdk.service.repositories.RepositoryService) Intent(android.content.Intent) TextUtils(android.text.TextUtils) Single(io.reactivex.Single) VisibleForTesting(android.support.annotation.VisibleForTesting) List(java.util.List) RepositoryActivity(com.gh4a.activities.RepositoryActivity) FragmentActivity(android.support.v4.app.FragmentActivity) Optional(com.gh4a.utils.Optional) Branch(com.meisolsson.githubsdk.model.Branch) ApiRequestException(com.gh4a.ApiRequestException) Pattern(java.util.regex.Pattern) ServiceFactory(com.gh4a.ServiceFactory) RepositoryBranchService(com.meisolsson.githubsdk.service.repositories.RepositoryBranchService) RepositoryService(com.meisolsson.githubsdk.service.repositories.RepositoryService)

Example 2 with RepositoryBranchService

use of com.meisolsson.githubsdk.service.repositories.RepositoryBranchService 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));
    }
}
Also used : HttpURLConnection(java.net.HttpURLConnection) Context(android.content.Context) ContentListContainerFragment(com.gh4a.fragment.ContentListContainerFragment) Repository(com.meisolsson.githubsdk.model.Repository) Bundle(android.os.Bundle) StarringService(com.meisolsson.githubsdk.service.activity.StarringService) Uri(android.net.Uri) ImageView(android.widget.ImageView) RepositoryEventListFragment(com.gh4a.fragment.RepositoryEventListFragment) Intent(android.content.Intent) RepositoryFragment(com.gh4a.fragment.RepositoryFragment) Response(retrofit2.Response) Single(io.reactivex.Single) MenuItem(android.view.MenuItem) UiUtils(com.gh4a.utils.UiUtils) ArrayList(java.util.ArrayList) Commit(com.meisolsson.githubsdk.model.Commit) MenuInflater(android.view.MenuInflater) Menu(android.view.Menu) R(com.gh4a.R) View(android.view.View) ActionBar(android.support.v7.app.ActionBar) IntentUtils(com.gh4a.utils.IntentUtils) Subscription(com.meisolsson.githubsdk.model.Subscription) RepositoryBranchService(com.meisolsson.githubsdk.service.repositories.RepositoryBranchService) ApiHelpers(com.gh4a.utils.ApiHelpers) BaseFragmentPagerActivity(com.gh4a.BaseFragmentPagerActivity) LayoutInflater(android.view.LayoutInflater) Fragment(android.support.v4.app.Fragment) RepositoryService(com.meisolsson.githubsdk.service.repositories.RepositoryService) TextUtils(android.text.TextUtils) WatchingService(com.meisolsson.githubsdk.service.activity.WatchingService) ViewGroup(android.view.ViewGroup) List(java.util.List) AlertDialog(android.support.v7.app.AlertDialog) TextView(android.widget.TextView) RxUtils(com.gh4a.utils.RxUtils) BaseAdapter(android.widget.BaseAdapter) Gh4Application(com.gh4a.Gh4Application) CommitListFragment(com.gh4a.fragment.CommitListFragment) Pair(android.support.v4.util.Pair) Branch(com.meisolsson.githubsdk.model.Branch) ServiceFactory(com.gh4a.ServiceFactory) BookmarksProvider(com.gh4a.db.BookmarksProvider) SubscriptionRequest(com.meisolsson.githubsdk.model.request.activity.SubscriptionRequest) ArrayList(java.util.ArrayList) List(java.util.List) RepositoryBranchService(com.meisolsson.githubsdk.service.repositories.RepositoryBranchService) RepositoryService(com.meisolsson.githubsdk.service.repositories.RepositoryService) Pair(android.support.v4.util.Pair)

Aggregations

Intent (android.content.Intent)2 TextUtils (android.text.TextUtils)2 ServiceFactory (com.gh4a.ServiceFactory)2 ApiHelpers (com.gh4a.utils.ApiHelpers)2 Branch (com.meisolsson.githubsdk.model.Branch)2 RepositoryBranchService (com.meisolsson.githubsdk.service.repositories.RepositoryBranchService)2 RepositoryService (com.meisolsson.githubsdk.service.repositories.RepositoryService)2 Single (io.reactivex.Single)2 List (java.util.List)2 Context (android.content.Context)1 Uri (android.net.Uri)1 Bundle (android.os.Bundle)1 VisibleForTesting (android.support.annotation.VisibleForTesting)1 Fragment (android.support.v4.app.Fragment)1 FragmentActivity (android.support.v4.app.FragmentActivity)1 Pair (android.support.v4.util.Pair)1 ActionBar (android.support.v7.app.ActionBar)1 AlertDialog (android.support.v7.app.AlertDialog)1 Pair (android.util.Pair)1 LayoutInflater (android.view.LayoutInflater)1