Search in sources :

Example 1 with Branch

use of com.meisolsson.githubsdk.model.Branch in project gh4a by slapperwan.

the class RepositoryActivity method showRefSelectionDialog.

private void showRefSelectionDialog() {
    final BranchAndTagAdapter adapter = new BranchAndTagAdapter();
    int current = -1, master = -1, count = adapter.getCount();
    for (int i = 0; i < count; i++) {
        Branch item = adapter.getItem(i);
        if (item.name().equals(mSelectedRef) || item.commit().sha().equals(mSelectedRef)) {
            current = i;
        }
        if (item.name().equals(mRepository.defaultBranch())) {
            master = i;
        }
    }
    if (mSelectedRef == null && current == -1) {
        current = master;
    }
    new AlertDialog.Builder(this).setCancelable(true).setTitle(R.string.repo_select_ref_dialog_title).setSingleChoiceItems(adapter, current, (dialog, which) -> {
        setSelectedRef(adapter.getItem(which).name());
        dialog.dismiss();
    }).setNegativeButton(R.string.cancel, null).show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) Branch(com.meisolsson.githubsdk.model.Branch)

Example 2 with Branch

use of com.meisolsson.githubsdk.model.Branch 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

AlertDialog (android.support.v7.app.AlertDialog)2 Branch (com.meisolsson.githubsdk.model.Branch)2 Context (android.content.Context)1 Intent (android.content.Intent)1 Uri (android.net.Uri)1 Bundle (android.os.Bundle)1 Fragment (android.support.v4.app.Fragment)1 Pair (android.support.v4.util.Pair)1 ActionBar (android.support.v7.app.ActionBar)1 TextUtils (android.text.TextUtils)1 LayoutInflater (android.view.LayoutInflater)1 Menu (android.view.Menu)1 MenuInflater (android.view.MenuInflater)1 MenuItem (android.view.MenuItem)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 BaseAdapter (android.widget.BaseAdapter)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 BaseFragmentPagerActivity (com.gh4a.BaseFragmentPagerActivity)1