diff options
| author | knuthy <knuthy@gmail.com> | 2014-09-21 18:29:37 +0200 |
|---|---|---|
| committer | knuthy <knuthy@gmail.com> | 2014-09-21 18:29:37 +0200 |
| commit | 83b893bc8ca7359925c4be048aa149c59fbdb4af (patch) | |
| tree | 3f114753f3f219bb38ad66ec66a4757117f3f781 /app/src/main/java/com/zeapo/pwdstore/GitHandler.java | |
| parent | 08ce874009e1459dbf6b1f2f0b061381e011f7f2 (diff) | |
| download | HardenedPass-83b893bc8ca7359925c4be048aa149c59fbdb4af.tar.gz HardenedPass-83b893bc8ca7359925c4be048aa149c59fbdb4af.zip | |
took off duplicate code CloneAsyncTask into GitAsyncTask
Diffstat (limited to 'app/src/main/java/com/zeapo/pwdstore/GitHandler.java')
| -rw-r--r-- | app/src/main/java/com/zeapo/pwdstore/GitHandler.java | 110 |
1 files changed, 6 insertions, 104 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/GitHandler.java b/app/src/main/java/com/zeapo/pwdstore/GitHandler.java index ba42f867..cbb816c1 100644 --- a/app/src/main/java/com/zeapo/pwdstore/GitHandler.java +++ b/app/src/main/java/com/zeapo/pwdstore/GitHandler.java @@ -32,6 +32,8 @@ import org.eclipse.jgit.api.Git; import org.apache.commons.io.FileUtils; import org.eclipse.jgit.api.GitCommand; +import org.eclipse.jgit.api.PullCommand; +import org.eclipse.jgit.api.PushCommand; import org.eclipse.jgit.api.errors.InvalidRemoteException; import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.api.errors.TransportException; @@ -200,99 +202,6 @@ public class GitHandler extends Activity { return super.onOptionsItemSelected(item); } - /* The clone process has to be on a different thread than the main one */ - private class CloneTask extends AsyncTask<CloneCommand, Integer, Integer> { - private ProgressDialog dialog; - - public CloneTask(Activity activity) { - context = activity; - dialog = new ProgressDialog(context); - } - - protected void onPreExecute() { - this.dialog.setMessage("Cloning..."); - this.dialog.setCancelable(false); - // TODO: Handle a dialog leak when there is no error - this.dialog.show(); - } - - protected void onPostExecute(Integer result) { - switch (result) { - case -1: - new AlertDialog.Builder(activity). - setTitle("Please check that the repository path is correct."). - setMessage("Did you forget to specify the path after the hostname?"). - setPositiveButton("OK", new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int i) { - - } - }).show(); - break; - case -2: - new AlertDialog.Builder(activity). - setTitle("Communication error"). - setMessage("JGit said that the server didn't like our request. Either an authentication issue or the host is not reachable. Check the debug messages."). - setPositiveButton("OK", new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int i) { - - } - }).show(); - break; - case -99: - new AlertDialog.Builder(activity). - setTitle("JGit raised an internal exception"). - setMessage("OUPS, JGit didn't like what you did... Check that you provided it with a correct URI. Check also debug messages."). - setPositiveButton("OK", new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int i) { - - } - }).show(); - break; - default: - this.dialog.dismiss(); - setResult(RESULT_OK); - finish(); - return; - } - this.dialog.dismiss(); - - // if we were unable to finish the job - try { - FileUtils.deleteDirectory(localDir); - } catch (Exception e) { - e.printStackTrace(); - } - } - - - protected Integer doInBackground(CloneCommand... cmd) { - int count = cmd.length; - Integer totalSize = 0; - for (int i = 0; i < count; i++) { - try { - cmd[i].call(); - } catch (JGitInternalException e) { - e.printStackTrace(); - return -99; - } catch (InvalidRemoteException e) { - e.printStackTrace(); - return -1; - } catch (TransportException e) { - e.printStackTrace(); - return -2; - } catch (Exception e) { - e.printStackTrace(); - return -99; - } - totalSize++; - } - return totalSize; - } - } - protected class GitConfigSessionFactory extends JschConfigSessionFactory { protected void configure(OpenSshConfig.Host hc, Session session) { @@ -452,7 +361,7 @@ public class GitHandler extends Activity { setDirectory(localDir). setURI(hostname); - new CloneTask(activity).execute(cmd); + new GitAsyncTask(activity, true, false, CloneCommand.class).execute(cmd); } public void pullOperation(UsernamePasswordCredentialsProvider provider) { @@ -500,7 +409,7 @@ public class GitHandler extends Activity { .setRebase(true) .setRemote("origin"); - new GitAsyncTask(activity, true, false).execute(cmd); + new GitAsyncTask(activity, true, false, PullCommand.class).execute(cmd); } } @@ -550,7 +459,7 @@ public class GitHandler extends Activity { .setRemote("origin"); - new GitAsyncTask(activity, true, false).execute(cmd); + new GitAsyncTask(activity, true, false, PushCommand.class).execute(cmd); } } @@ -661,14 +570,7 @@ public class GitHandler extends Activity { } }).show(); } else { - CloneCommand cmd = Git.cloneRepository() - .setDirectory(localDir) - .setURI(hostname) - .setBare(false) - .setNoCheckout(false) - .setCloneAllBranches(true); - - new CloneTask(activity).execute(cmd); + // BUG: we do not support HTTP yet... } } } |
