Search in sources :

Example 1 with GitReference

use of com.meisolsson.githubsdk.model.git.GitReference in project PocketHub by pockethub.

the class RepositoryCodeFragment method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch(item.getItemId()) {
        case R.id.m_refresh:
            if (tree != null) {
                GitReference ref = GitReference.builder().ref(tree.reference.ref()).build();
                refreshTree(ref);
            } else {
                refreshTree(null);
            }
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
Also used : GitReference(com.meisolsson.githubsdk.model.git.GitReference)

Example 2 with GitReference

use of com.meisolsson.githubsdk.model.git.GitReference in project PocketHub by pockethub.

the class RefreshTreeTask method subscribe.

@Override
public void subscribe(ObservableEmitter<FullTree> emitter) throws Exception {
    GitReference ref = reference;
    String branch = RefUtils.getPath(ref);
    if (branch == null) {
        branch = repo.defaultBranch();
        if (TextUtils.isEmpty(branch)) {
            branch = ServiceGenerator.createService(context, RepositoryService.class).getRepository(repo.owner().login(), repo.name()).blockingGet().defaultBranch();
            if (TextUtils.isEmpty(branch)) {
                emitter.onError(new IOException("Repository does not have master branch"));
            }
        }
    }
    GitService gitService = ServiceGenerator.createService(context, GitService.class);
    if (!isValidRef(ref)) {
        branch = branch.replace("heads/", "");
        ref = gitService.getGitReference(repo.owner().login(), repo.name(), branch).blockingGet();
        if (!isValidRef(ref)) {
            emitter.onError(new IOException("Reference does not have associated commit SHA-1"));
            return;
        }
    }
    GitCommit commit = gitService.getGitCommit(repo.owner().login(), repo.name(), ref.object().sha()).blockingGet();
    if (commit == null || commit.tree() == null || TextUtils.isEmpty(commit.tree().sha())) {
        emitter.onError(new IOException("Commit does not have associated tree SHA-1"));
        return;
    }
    GitTree tree = gitService.getGitTreeRecursive(repo.owner().login(), repo.name(), commit.tree().sha()).blockingGet();
    emitter.onNext(new FullTree(tree, ref));
}
Also used : GitTree(com.meisolsson.githubsdk.model.git.GitTree) GitCommit(com.meisolsson.githubsdk.model.git.GitCommit) GitService(com.meisolsson.githubsdk.service.git.GitService) IOException(java.io.IOException) GitReference(com.meisolsson.githubsdk.model.git.GitReference)

Example 3 with GitReference

use of com.meisolsson.githubsdk.model.git.GitReference in project PocketHub by pockethub.

the class RefDialog method load.

private void load(final GitReference selectedRef) {
    getPageAndNext(1).subscribe(new ProgressObserverAdapter<Page<GitReference>>(activity, R.string.loading_refs) {

        List<GitReference> allRefs = new ArrayList<>();

        @Override
        public void onNext(Page<GitReference> page) {
            super.onNext(page);
            allRefs.addAll(page.items());
        }

        @Override
        public void onComplete() {
            super.onComplete();
            Map<String, GitReference> loadedRefs = new TreeMap<>(CASE_INSENSITIVE_ORDER);
            for (GitReference ref : allRefs) {
                if (RefUtils.isValid(ref)) {
                    loadedRefs.put(ref.ref(), ref);
                }
            }
            refs = loadedRefs;
            show(selectedRef);
        }

        @Override
        public void onError(Throwable e) {
            super.onError(e);
            Log.d(TAG, "Exception loading references", e);
            ToastUtils.show(activity, e, R.string.error_refs_load);
        }
    }.start());
}
Also used : ProgressObserverAdapter(com.github.pockethub.android.rx.ProgressObserverAdapter) ArrayList(java.util.ArrayList) List(java.util.List) Page(com.meisolsson.githubsdk.model.Page) TreeMap(java.util.TreeMap) GitReference(com.meisolsson.githubsdk.model.git.GitReference)

Example 4 with GitReference

use of com.meisolsson.githubsdk.model.git.GitReference in project PocketHub by pockethub.

the class RefDialogFragment method onCreateDialog.

@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
    Activity activity = getActivity();
    Bundle arguments = getArguments();
    final MaterialDialog.Builder dialogBuilder = createDialogBuilder().negativeText(R.string.cancel).onNegative(new MaterialDialog.SingleButtonCallback() {

        @Override
        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
            RefDialogFragment.this.onClick(dialog, BUTTON_NEGATIVE);
        }
    });
    LayoutInflater inflater = activity.getLayoutInflater();
    ListView view = (ListView) inflater.inflate(R.layout.dialog_list_view, null);
    view.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            onClick(getDialog(), position);
        }
    });
    ArrayList<GitReference> choices = getChoices();
    int selected = arguments.getInt(ARG_SELECTED_CHOICE);
    RefListAdapter adapter = new RefListAdapter(inflater, choices.toArray(new GitReference[choices.size()]), selected);
    view.setAdapter(adapter);
    if (selected >= 0) {
        view.setSelection(selected);
    }
    dialogBuilder.customView(view, false);
    return dialogBuilder.build();
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) Bundle(android.os.Bundle) BaseActivity(com.github.pockethub.android.ui.BaseActivity) Activity(android.app.Activity) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) ListView(android.widget.ListView) DialogAction(com.afollestad.materialdialogs.DialogAction) LayoutInflater(android.view.LayoutInflater) GitReference(com.meisolsson.githubsdk.model.git.GitReference)

Example 5 with GitReference

use of com.meisolsson.githubsdk.model.git.GitReference in project PocketHub by pockethub.

the class CommitListFragment method switchRefs.

private void switchRefs() {
    if (ref == null) {
        return;
    }
    if (dialog == null) {
        dialog = new RefDialog((BaseActivity) getActivity(), REF_UPDATE, repository);
    }
    GitReference reference = GitReference.builder().ref(ref).build();
    dialog.show(reference);
}
Also used : RefDialog(com.github.pockethub.android.ui.ref.RefDialog) BaseActivity(com.github.pockethub.android.ui.BaseActivity) GitReference(com.meisolsson.githubsdk.model.git.GitReference)

Aggregations

GitReference (com.meisolsson.githubsdk.model.git.GitReference)5 BaseActivity (com.github.pockethub.android.ui.BaseActivity)2 Activity (android.app.Activity)1 Bundle (android.os.Bundle)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 OnItemClickListener (android.widget.AdapterView.OnItemClickListener)1 ListView (android.widget.ListView)1 DialogAction (com.afollestad.materialdialogs.DialogAction)1 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)1 ProgressObserverAdapter (com.github.pockethub.android.rx.ProgressObserverAdapter)1 RefDialog (com.github.pockethub.android.ui.ref.RefDialog)1 Page (com.meisolsson.githubsdk.model.Page)1 GitCommit (com.meisolsson.githubsdk.model.git.GitCommit)1 GitTree (com.meisolsson.githubsdk.model.git.GitTree)1 GitService (com.meisolsson.githubsdk.service.git.GitService)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1