From 110b8c5abc1ce061c509f40d3234298951d4db0a Mon Sep 17 00:00:00 2001 From: Mohamed Date: Tue, 13 Jun 2017 13:39:50 +0200 Subject: re-enable locking for clone operation --- .../com/zeapo/pwdstore/git/CloneOperation.java | 2 +- .../java/com/zeapo/pwdstore/git/GitAsyncTask.java | 39 ++++++++++++++++------ .../java/com/zeapo/pwdstore/git/GitOperation.java | 7 +++- 3 files changed, 36 insertions(+), 12 deletions(-) (limited to 'app') 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 { 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("Running %s", operation.getClass().getSimpleName())), - Toast.LENGTH_LONG).show(); + final Spanned message = Html.fromHtml(String.format("Running %s", 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("Running jgit command: %s", progress[0])), - Toast.LENGTH_LONG).show(); + final Spanned message = Html.fromHtml(String.format("Running jgit command: %s", 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 { } 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) -- cgit v1.2.3