aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/com/zeapo/pwdstore/git
diff options
context:
space:
mode:
authorMohamed Zenadi <mohamed@zenadi.com>2017-06-24 12:24:28 +0200
committerMohamed Zenadi <mohamed@zenadi.com>2017-06-24 12:24:28 +0200
commit7b8ad7ca0f575113359bacadf151303f5b4c53a4 (patch)
tree14cc8b5c87a2aaa13064dad19b2c217ebc42ef4d /app/src/main/java/com/zeapo/pwdstore/git
parentfca7f8267b2602f3d4b7b671278cad181f64eb63 (diff)
downloadHardenedPass-7b8ad7ca0f575113359bacadf151303f5b4c53a4.tar.gz
HardenedPass-7b8ad7ca0f575113359bacadf151303f5b4c53a4.zip
revert auto-sync and background git activity
too buggy, no time to work on it correclty
Diffstat (limited to 'app/src/main/java/com/zeapo/pwdstore/git')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/git/CloneOperation.java4
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/git/GitActivity.java10
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/git/GitAsyncTask.java42
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/git/GitOperation.java29
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/git/PullOperation.java4
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/git/PushOperation.java4
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/git/SyncOperation.java4
7 files changed, 31 insertions, 66 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/git/CloneOperation.java b/app/src/main/java/com/zeapo/pwdstore/git/CloneOperation.java
index 9d245e13..25dba1fc 100644
--- a/app/src/main/java/com/zeapo/pwdstore/git/CloneOperation.java
+++ b/app/src/main/java/com/zeapo/pwdstore/git/CloneOperation.java
@@ -66,11 +66,11 @@ public class CloneOperation extends GitOperation {
}
@Override
- public void execute(boolean finishOnEnd) {
+ public void execute() {
if (this.provider != null) {
((CloneCommand) this.command).setCredentialsProvider(this.provider);
}
- new GitAsyncTask(callingActivity, finishOnEnd, false, this).execute(this.command);
+ new GitAsyncTask(callingActivity, true, false, this).execute(this.command);
}
@Override
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 45da34fb..66e308b9 100644
--- a/app/src/main/java/com/zeapo/pwdstore/git/GitActivity.java
+++ b/app/src/main/java/com/zeapo/pwdstore/git/GitActivity.java
@@ -536,7 +536,7 @@ public class GitActivity extends AppCompatActivity {
try {
new CloneOperation(localDir, activity)
.setCommand(hostname)
- .executeAfterAuthentication(connectionMode, settings.getString("git_remote_username", "git"), new File(getFilesDir() + "/.ssh_key"), true);
+ .executeAfterAuthentication(connectionMode, settings.getString("git_remote_username", "git"), new File(getFilesDir() + "/.ssh_key"));
} catch (Exception e) {
//This is what happens when jgit fails :(
//TODO Handle the diffent cases of exceptions
@@ -574,7 +574,7 @@ public class GitActivity extends AppCompatActivity {
}
new CloneOperation(localDir, activity)
.setCommand(hostname)
- .executeAfterAuthentication(connectionMode, settings.getString("git_remote_username", "git"), new File(getFilesDir() + "/.ssh_key"), true);
+ .executeAfterAuthentication(connectionMode, settings.getString("git_remote_username", "git"), new File(getFilesDir() + "/.ssh_key"));
} catch (Exception e) {
//This is what happens when jgit fails :(
//TODO Handle the diffent cases of exceptions
@@ -632,9 +632,7 @@ public class GitActivity extends AppCompatActivity {
}
try {
- op.executeAfterAuthentication(connectionMode,
- settings.getString("git_remote_username", "git"),
- new File(getFilesDir() + "/.ssh_key"), false);
+ op.executeAfterAuthentication(connectionMode, settings.getString("git_remote_username", "git"), new File(getFilesDir() + "/.ssh_key"));
} catch (Exception e) {
e.printStackTrace();
}
@@ -676,7 +674,7 @@ public class GitActivity extends AppCompatActivity {
}
try {
- op.executeAfterAuthentication(connectionMode, settings.getString("git_remote_username", "git"), new File(getFilesDir() + "/.ssh_key"), true);
+ op.executeAfterAuthentication(connectionMode, settings.getString("git_remote_username", "git"), new File(getFilesDir() + "/.ssh_key"));
} catch (Exception e) {
e.printStackTrace();
}
diff --git a/app/src/main/java/com/zeapo/pwdstore/git/GitAsyncTask.java b/app/src/main/java/com/zeapo/pwdstore/git/GitAsyncTask.java
index fa323bf4..26af4c89 100644
--- a/app/src/main/java/com/zeapo/pwdstore/git/GitAsyncTask.java
+++ b/app/src/main/java/com/zeapo/pwdstore/git/GitAsyncTask.java
@@ -3,11 +3,7 @@ package com.zeapo.pwdstore.git;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.AsyncTask;
-import android.support.design.widget.Snackbar;
-import android.text.Html;
-import android.text.Spanned;
import android.util.Log;
-import android.widget.Toast;
import com.zeapo.pwdstore.PasswordStore;
import com.zeapo.pwdstore.R;
@@ -17,43 +13,26 @@ import org.eclipse.jgit.api.GitCommand;
import org.eclipse.jgit.api.StatusCommand;
-public class GitAsyncTask extends AsyncTask<GitCommand, String, String> {
+public class GitAsyncTask extends AsyncTask<GitCommand, Integer, String> {
private Activity activity;
- private boolean lockAndFinishActivity;
+ private boolean finishOnEnd;
private boolean refreshListOnEnd;
private ProgressDialog dialog;
private GitOperation operation;
- private Snackbar snack;
- public GitAsyncTask(Activity activity, boolean lockAndFinishActivity, boolean refreshListOnEnd, GitOperation operation) {
+ public GitAsyncTask(Activity activity, boolean finishOnEnd, boolean refreshListOnEnd, GitOperation operation) {
this.activity = activity;
- this.lockAndFinishActivity = lockAndFinishActivity;
+ this.finishOnEnd = finishOnEnd;
this.refreshListOnEnd = refreshListOnEnd;
this.operation = operation;
- this.dialog = new ProgressDialog(this.activity);
+ dialog = new ProgressDialog(this.activity);
}
protected void onPreExecute() {
- if (lockAndFinishActivity) {
- final Spanned message = Html.fromHtml(String.format("Running %s", operation.getClass().getSimpleName()));
- this.dialog.setMessage(message);
- this.dialog.setCancelable(false);
- this.dialog.show();
- } else {
- final Spanned message = Html.fromHtml(String.format("<font color=\"#ffffff\">Running %s</font>", operation.getClass().getSimpleName()));
- Toast.makeText(activity.getApplicationContext(), message, Toast.LENGTH_LONG).show();
- }
- }
-
- protected void onProgressUpdate(String... progress) {
- if (lockAndFinishActivity) {
- final Spanned message = Html.fromHtml(String.format("Running jgit command: <strong>%s</strong>", progress[0]));
- this.dialog.setMessage(message);
- } else {
- final Spanned message = Html.fromHtml(String.format("<font color=\"#ffffff\">Running jgit command: <strong>%s</strong></font>", progress[0]));
- Toast.makeText(activity.getApplicationContext(), message, Toast.LENGTH_LONG).show();
- }
+ this.dialog.setMessage(activity.getResources().getString(R.string.running_dialog_text));
+ this.dialog.setCancelable(false);
+ this.dialog.show();
}
@Override
@@ -73,8 +52,7 @@ public class GitAsyncTask extends AsyncTask<GitCommand, String, String> {
} else {
command.call();
}
- String opName = command.getClass().getSimpleName();
- publishProgress(opName);
+
} catch (Exception e) {
e.printStackTrace();
return e.getMessage() + "\nCaused by:\n" + e.getCause();
@@ -97,7 +75,7 @@ public class GitAsyncTask extends AsyncTask<GitCommand, String, String> {
if (!result.isEmpty()) {
this.operation.onTaskEnded(result);
} else {
- if (lockAndFinishActivity) {
+ if (finishOnEnd) {
this.activity.setResult(Activity.RESULT_OK);
this.activity.finish();
}
diff --git a/app/src/main/java/com/zeapo/pwdstore/git/GitOperation.java b/app/src/main/java/com/zeapo/pwdstore/git/GitOperation.java
index 4dc39293..f6b05f4c 100644
--- a/app/src/main/java/com/zeapo/pwdstore/git/GitOperation.java
+++ b/app/src/main/java/com/zeapo/pwdstore/git/GitOperation.java
@@ -76,10 +76,8 @@ public abstract class GitOperation {
/**
* Executes the GitCommand in an async task
- *
- * @param finishOnEnd
*/
- public abstract void execute(boolean finishOnEnd);
+ public abstract void execute();
/**
* Executes the GitCommand in an async task after creating the authentication
@@ -87,10 +85,9 @@ public abstract class GitOperation {
* @param connectionMode the server-connection mode
* @param username the username
* @param sshKey the ssh-key file
- * @param finishOnEnd
*/
- public void executeAfterAuthentication(final String connectionMode, final String username, @Nullable final File sshKey, boolean finishOnEnd) {
- executeAfterAuthentication(connectionMode, username, sshKey, false, finishOnEnd);
+ public void executeAfterAuthentication(final String connectionMode, final String username, @Nullable final File sshKey) {
+ executeAfterAuthentication(connectionMode, username, sshKey, false);
}
/**
@@ -100,14 +97,8 @@ public abstract class GitOperation {
* @param username the username
* @param sshKey the ssh-key file
* @param showError show the passphrase edit text in red
- * @param finishOnEnd
*/
- private void executeAfterAuthentication(
- final String connectionMode,
- final String username,
- @Nullable final File sshKey,
- final boolean showError,
- final boolean finishOnEnd) {
+ private void executeAfterAuthentication(final String connectionMode, final String username, @Nullable final File sshKey, final boolean showError) {
if (connectionMode.equalsIgnoreCase("ssh-key")) {
if (sshKey == null || !sshKey.exists()) {
new AlertDialog.Builder(callingActivity)
@@ -170,21 +161,19 @@ public abstract class GitOperation {
public void onClick(DialogInterface dialog, int whichButton) {
if (keyPair.decrypt(passphrase.getText().toString())) {
// Authenticate using the ssh-key and then execute the command
- setAuthentication(sshKey, username, passphrase.getText().toString()).execute(finishOnEnd);
- callingActivity.finish();
+ setAuthentication(sshKey, username, passphrase.getText().toString()).execute();
} else {
// call back the method
- executeAfterAuthentication(connectionMode, username, sshKey, true, finishOnEnd);
+ executeAfterAuthentication(connectionMode, username, sshKey, true);
}
}
}).setNegativeButton(callingActivity.getResources().getString(R.string.dialog_cancel), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
- callingActivity.finish();
+ // Do nothing.
}
}).show();
} else {
- setAuthentication(sshKey, username, "").execute(finishOnEnd);
- callingActivity.finish();
+ setAuthentication(sshKey, username, "").execute();
}
} catch (JSchException e) {
new AlertDialog.Builder(callingActivity)
@@ -211,7 +200,7 @@ public abstract class GitOperation {
.setPositiveButton(callingActivity.getResources().getString(R.string.dialog_ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// authenticate using the user/pwd and then execute the command
- setAuthentication(username, password.getText().toString()).execute(finishOnEnd);
+ setAuthentication(username, password.getText().toString()).execute();
}
}).setNegativeButton(callingActivity.getResources().getString(R.string.dialog_cancel), new DialogInterface.OnClickListener() {
diff --git a/app/src/main/java/com/zeapo/pwdstore/git/PullOperation.java b/app/src/main/java/com/zeapo/pwdstore/git/PullOperation.java
index d6859e9f..6ca8bf49 100644
--- a/app/src/main/java/com/zeapo/pwdstore/git/PullOperation.java
+++ b/app/src/main/java/com/zeapo/pwdstore/git/PullOperation.java
@@ -36,11 +36,11 @@ public class PullOperation extends GitOperation {
}
@Override
- public void execute(boolean finishOnEnd) {
+ public void execute() {
if (this.provider != null) {
((PullCommand) this.command).setCredentialsProvider(this.provider);
}
- new GitAsyncTask(callingActivity, finishOnEnd, false, this).execute(this.command);
+ new GitAsyncTask(callingActivity, true, false, this).execute(this.command);
}
@Override
diff --git a/app/src/main/java/com/zeapo/pwdstore/git/PushOperation.java b/app/src/main/java/com/zeapo/pwdstore/git/PushOperation.java
index d66eb359..2774af90 100644
--- a/app/src/main/java/com/zeapo/pwdstore/git/PushOperation.java
+++ b/app/src/main/java/com/zeapo/pwdstore/git/PushOperation.java
@@ -36,11 +36,11 @@ public class PushOperation extends GitOperation {
}
@Override
- public void execute(boolean finishOnEnd) {
+ public void execute() {
if (this.provider != null) {
((PushCommand) this.command).setCredentialsProvider(this.provider);
}
- new GitAsyncTask(callingActivity, finishOnEnd, false, this).execute(this.command);
+ new GitAsyncTask(callingActivity, true, false, this).execute(this.command);
}
@Override
diff --git a/app/src/main/java/com/zeapo/pwdstore/git/SyncOperation.java b/app/src/main/java/com/zeapo/pwdstore/git/SyncOperation.java
index 21e59e61..0094b22c 100644
--- a/app/src/main/java/com/zeapo/pwdstore/git/SyncOperation.java
+++ b/app/src/main/java/com/zeapo/pwdstore/git/SyncOperation.java
@@ -48,12 +48,12 @@ public class SyncOperation extends GitOperation {
}
@Override
- public void execute(boolean finishOnEnd) {
+ public void execute() {
if (this.provider != null) {
this.pullCommand.setCredentialsProvider(this.provider);
this.pushCommand.setCredentialsProvider(this.provider);
}
- new GitAsyncTask(callingActivity, finishOnEnd, false, this).execute(this.addCommand, this.statusCommand, this.commitCommand, this.pullCommand, this.pushCommand);
+ new GitAsyncTask(callingActivity, true, false, this).execute(this.addCommand, this.statusCommand, this.commitCommand, this.pullCommand, this.pushCommand);
}
@Override