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);
}
}
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));
}
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());
}
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();
}
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);
}
Aggregations