Search in sources :

Example 1 with RenameBranchDialog

use of me.sheimi.sgit.dialogs.RenameBranchDialog in project MGit by maks.

the class BranchChooserActivity method onActionItemClicked.

@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
    switch(item.getItemId()) {
        case R.id.action_mode_rename_branch:
            Bundle pathArg = new Bundle();
            pathArg.putString(RenameBranchDialog.FROM_COMMIT, mChosenCommit);
            pathArg.putSerializable(Repo.TAG, mRepo);
            mode.finish();
            RenameBranchDialog rbd = new RenameBranchDialog();
            rbd.setArguments(pathArg);
            rbd.show(getFragmentManager(), "rename-dialog");
            return true;
        case R.id.action_mode_delete:
            AlertDialog.Builder alert = new AlertDialog.Builder(this).setIcon(android.R.drawable.ic_dialog_alert).setTitle(getString(R.string.dialog_branch_delete) + " " + mChosenCommit).setMessage(R.string.dialog_branch_delete_msg).setPositiveButton(R.string.label_delete, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    int commitType = Repo.getCommitType(mChosenCommit);
                    try {
                        switch(commitType) {
                            case Repo.COMMIT_TYPE_HEAD:
                                mRepo.getGit().branchDelete().setBranchNames(mChosenCommit).setForce(true).call();
                                break;
                            case Repo.COMMIT_TYPE_TAG:
                                mRepo.getGit().tagDelete().setTags(mChosenCommit).call();
                                break;
                        }
                    } catch (StopTaskException e) {
                        Log.e(LOGTAG, "can't delete " + mChosenCommit, e);
                        runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                Toast.makeText(BranchChooserActivity.this, getString(R.string.cannot_delete_branch, mChosenCommit), Toast.LENGTH_LONG).show();
                            }
                        });
                    } catch (CannotDeleteCurrentBranchException e) {
                        Log.e(LOGTAG, "can't delete " + mChosenCommit, e);
                        runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                Toast.makeText(BranchChooserActivity.this, getString(R.string.cannot_delete_current_branch, mChosenCommit), Toast.LENGTH_LONG).show();
                            }
                        });
                    } catch (GitAPIException e) {
                        Log.e(LOGTAG, "can't delete " + mChosenCommit, e);
                        runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                Toast.makeText(BranchChooserActivity.this, getString(R.string.cannot_delete_branch, mChosenCommit), Toast.LENGTH_LONG).show();
                            }
                        });
                    }
                    refreshList();
                }
            }).setNegativeButton(R.string.label_cancel, null);
            mode.finish();
            alert.show();
            return true;
        default:
            return false;
    }
}
Also used : AlertDialog(android.app.AlertDialog) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) RenameBranchDialog(me.sheimi.sgit.dialogs.RenameBranchDialog) DialogInterface(android.content.DialogInterface) Bundle(android.os.Bundle) StopTaskException(me.sheimi.sgit.exception.StopTaskException) CannotDeleteCurrentBranchException(org.eclipse.jgit.api.errors.CannotDeleteCurrentBranchException)

Aggregations

AlertDialog (android.app.AlertDialog)1 DialogInterface (android.content.DialogInterface)1 Bundle (android.os.Bundle)1 RenameBranchDialog (me.sheimi.sgit.dialogs.RenameBranchDialog)1 StopTaskException (me.sheimi.sgit.exception.StopTaskException)1 CannotDeleteCurrentBranchException (org.eclipse.jgit.api.errors.CannotDeleteCurrentBranchException)1 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)1