diff options
author | zeapo <mohamed@zenadi.com> | 2014-12-17 23:42:05 +0100 |
---|---|---|
committer | zeapo <mohamed@zenadi.com> | 2015-01-04 14:53:58 +0100 |
commit | dbbb2305f739c70144ed1cb593837af54a1d893d (patch) | |
tree | dee9e0b1bc81ada5dfb09d916cb85f01ece65893 | |
parent | 7b1204373dc44d16e4e443067825eb946905857a (diff) |
DRY refactoring
-rw-r--r-- | app/src/main/java/com/zeapo/pwdstore/git/GitActivity.java | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/git/GitActivity.java b/app/src/main/java/com/zeapo/pwdstore/git/GitActivity.java index b841a42a..36fb96ad 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/GitActivity.java +++ b/app/src/main/java/com/zeapo/pwdstore/git/GitActivity.java @@ -11,6 +11,7 @@ import android.preference.PreferenceManager; import android.support.v7.app.ActionBarActivity; import android.text.Editable; import android.text.TextWatcher; +import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.View; @@ -38,6 +39,7 @@ import java.util.regex.Pattern; // TODO move the messages to strings.xml public class GitActivity extends ActionBarActivity { + private static final String TAG = "GitAct"; private Activity activity; private Context context; @@ -604,33 +606,31 @@ public class GitActivity extends ActionBarActivity { } if (resultCode == RESULT_OK) { + GitOperation op; switch (requestCode) { case REQUEST_PULL: - try { - new PullOperation(localDir, activity) - .setCommand(hostname) - .executeAfterAuthentication(connectionMode, settings.getString("git_remote_username", "git"), new File(getFilesDir() + "/.ssh_key")); - } catch (Exception e) { - e.printStackTrace(); - } + op = new PullOperation(localDir, activity).setCommand(hostname); break; + case REQUEST_PUSH: - try { - new PushOperation(localDir, activity) - .setCommand(hostname) - .executeAfterAuthentication(connectionMode, settings.getString("git_remote_username", "git"), new File(getFilesDir() + "/.ssh_key")); - } catch (Exception e) { - e.printStackTrace(); - } break; + op = new PushOperation(localDir, activity).setCommand(hostname); + break; + case GitOperation.GET_SSH_KEY_FROM_CLONE: - try { - new CloneOperation(localDir, activity) - .setCommand(hostname) - .executeAfterAuthentication(connectionMode, settings.getString("git_remote_username", "git"), new File(getFilesDir() + "/.ssh_key")); - } catch (Exception e) { - e.printStackTrace(); - } + op = new CloneOperation(localDir, activity).setCommand(hostname); + break; + default: + Log.e(TAG, "Operation not recognized : " + resultCode); + setResult(RESULT_CANCELED); + finish(); + return; + } + + try { + op.executeAfterAuthentication(connectionMode, settings.getString("git_remote_username", "git"), new File(getFilesDir() + "/.ssh_key")); + } catch (Exception e) { + e.printStackTrace(); } } |