aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorMohamed <mohamed@zenadi.com>2017-06-13 13:39:50 +0200
committerMohamed <mohamed@zenadi.com>2017-06-13 13:39:50 +0200
commit110b8c5abc1ce061c509f40d3234298951d4db0a (patch)
tree9ce2384e0828ad7a855bd5902c7d6546d4480b8e /app/src/main/java
parenta8f728267787cc3891aa0a8e50e239547a0b13c2 (diff)
re-enable locking for clone operation
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/git/CloneOperation.java2
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/git/GitAsyncTask.java39
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/git/GitOperation.java7
3 files changed, 36 insertions, 12 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 03c35c23..9d245e13 100644
--- a/app/src/main/java/com/zeapo/pwdstore/git/CloneOperation.java
+++ b/app/src/main/java/com/zeapo/pwdstore/git/CloneOperation.java
@@ -70,7 +70,7 @@ public class CloneOperation extends GitOperation {
if (this.provider != null) {
((CloneCommand) this.command).setCredentialsProvider(this.provider);
}
- new GitAsyncTask(callingActivity, true, false, this).execute(this.command);
+ new GitAsyncTask(callingActivity, finishOnEnd, false, this).execute(this.command);
}
@Override
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 06a9376e..cde2519f 100644
--- a/app/src/main/java/com/zeapo/pwdstore/git/GitAsyncTask.java
+++ b/app/src/main/java/com/zeapo/pwdstore/git/GitAsyncTask.java
@@ -5,6 +5,7 @@ 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;
@@ -18,29 +19,40 @@ import org.eclipse.jgit.api.StatusCommand;
public class GitAsyncTask extends AsyncTask<GitCommand, String, String> {
private Activity activity;
- private boolean finishOnEnd;
+ private boolean lockAndFinishActivity;
private boolean refreshListOnEnd;
private ProgressDialog dialog;
private GitOperation operation;
private Snackbar snack;
- public GitAsyncTask(Activity activity, boolean finishOnEnd, boolean refreshListOnEnd, GitOperation operation) {
+ public GitAsyncTask(Activity activity, boolean lockAndFinishActivity, boolean refreshListOnEnd, GitOperation operation) {
this.activity = activity;
- this.finishOnEnd = finishOnEnd;
+ this.lockAndFinishActivity = lockAndFinishActivity;
this.refreshListOnEnd = refreshListOnEnd;
this.operation = operation;
+
+ this.dialog = new ProgressDialog(this.activity);
}
protected void onPreExecute() {
- Toast.makeText(activity.getApplicationContext(),
- Html.fromHtml(String.format("<font color=\"#ffffff\">Running %s</font>", operation.getClass().getSimpleName())),
- Toast.LENGTH_LONG).show();
+ final Spanned message = Html.fromHtml(String.format("<font color=\"#ffffff\">Running %s</font>", operation.getClass().getSimpleName()));
+
+ if (lockAndFinishActivity) {
+ this.dialog.setMessage(message);
+ this.dialog.setCancelable(false);
+ this.dialog.show();
+ } else {
+ Toast.makeText(activity.getApplicationContext(), message, Toast.LENGTH_LONG).show();
+ }
}
protected void onProgressUpdate(String... progress) {
- Toast.makeText(activity.getApplicationContext(),
- Html.fromHtml(String.format("<font color=\"#ffffff\">Running jgit command: <strong>%s</strong></font>", progress[0])),
- Toast.LENGTH_LONG).show();
+ final Spanned message = Html.fromHtml(String.format("<font color=\"#ffffff\">Running jgit command: <strong>%s</strong></font>", progress[0]));
+ if (lockAndFinishActivity) {
+ this.dialog.setMessage(message);
+ } else {
+ Toast.makeText(activity.getApplicationContext(), message, Toast.LENGTH_LONG).show();
+ }
}
@Override
@@ -70,13 +82,20 @@ public class GitAsyncTask extends AsyncTask<GitCommand, String, String> {
}
protected void onPostExecute(String result) {
+ if (this.dialog != null)
+ try {
+ this.dialog.dismiss();
+ } catch (Exception e) {
+ // ignore
+ }
+
if (result == null)
result = "Unexpected error";
if (!result.isEmpty()) {
this.operation.onTaskEnded(result);
} else {
- if (finishOnEnd) {
+ if (lockAndFinishActivity) {
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 5a206f0c..2c42c6fa 100644
--- a/app/src/main/java/com/zeapo/pwdstore/git/GitOperation.java
+++ b/app/src/main/java/com/zeapo/pwdstore/git/GitOperation.java
@@ -99,7 +99,12 @@ public abstract class GitOperation {
* @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,
+ final boolean finishOnEnd) {
if (connectionMode.equalsIgnoreCase("ssh-key")) {
if (sshKey == null || !sshKey.exists()) {
new AlertDialog.Builder(callingActivity)