From d6017be4eca37fafc7fb02ef7616fba6f086e106 Mon Sep 17 00:00:00 2001 From: zeapo Date: Fri, 11 Aug 2017 09:31:36 +0200 Subject: [PATCH] introduce onSuccess/onError --- .../com/zeapo/pwdstore/git/CloneOperation.java | 4 ++-- .../java/com/zeapo/pwdstore/git/GitAsyncTask.java | 4 +++- .../java/com/zeapo/pwdstore/git/GitOperation.java | 14 +++++++++++--- .../java/com/zeapo/pwdstore/git/PullOperation.java | 4 ++-- .../java/com/zeapo/pwdstore/git/PushOperation.java | 4 ++-- .../java/com/zeapo/pwdstore/git/SyncOperation.java | 4 ++-- 6 files changed, 22 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 61e08dc2..c3f22a64 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/CloneOperation.java +++ b/app/src/main/java/com/zeapo/pwdstore/git/CloneOperation.java @@ -72,12 +72,12 @@ public class CloneOperation extends GitOperation { } @Override - public void onTaskEnded(String result) { + public void onError(String errorMessage) { new AlertDialog.Builder(callingActivity). setTitle(callingActivity.getResources().getString(R.string.jgit_error_dialog_title)). setMessage("Error occured during the clone operation, " + callingActivity.getResources().getString(R.string.jgit_error_dialog_text) - + result + + errorMessage + "\nPlease check the FAQ for possible reasons why this error might occur."). setPositiveButton(callingActivity.getResources().getString(R.string.dialog_ok), new DialogInterface.OnClickListener() { @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 a42e5d78..7fe31979 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/GitAsyncTask.java +++ b/app/src/main/java/com/zeapo/pwdstore/git/GitAsyncTask.java @@ -99,8 +99,10 @@ public class GitAsyncTask extends AsyncTask { result = "Unexpected error"; if (!result.isEmpty()) { - this.operation.onTaskEnded(result); + this.operation.onError(result); } else { + this.operation.onSuccess(); + 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 45189652..d78ca185 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/GitOperation.java +++ b/app/src/main/java/com/zeapo/pwdstore/git/GitOperation.java @@ -25,7 +25,6 @@ import com.zeapo.pwdstore.git.config.SshConfigSessionFactory; import com.zeapo.pwdstore.utils.PasswordRepository; import org.eclipse.jgit.api.GitCommand; -import org.eclipse.jgit.diff.Edit; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.transport.JschConfigSessionFactory; import org.eclipse.jgit.transport.SshSessionFactory; @@ -233,10 +232,13 @@ public abstract class GitOperation { } } - public void onTaskEnded(String result) { + /** + * Action to execute on error + */ + public void onError(String errorMessage) { new AlertDialog.Builder(callingActivity). setTitle(callingActivity.getResources().getString(R.string.jgit_error_dialog_title)). - setMessage(callingActivity.getResources().getString(R.string.jgit_error_dialog_text) + result). + setMessage(callingActivity.getResources().getString(R.string.jgit_error_dialog_text) + errorMessage). setPositiveButton(callingActivity.getResources().getString(R.string.dialog_ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { @@ -245,4 +247,10 @@ public abstract class GitOperation { } }).show(); } + + /** + * Action to execute on success + */ + public void onSuccess() { + } } 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 9ab142c8..1a903aaf 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/PullOperation.java +++ b/app/src/main/java/com/zeapo/pwdstore/git/PullOperation.java @@ -45,12 +45,12 @@ public class PullOperation extends GitOperation { } @Override - public void onTaskEnded(String result) { + public void onError(String errorMessage) { new AlertDialog.Builder(callingActivity). setTitle(callingActivity.getResources().getString(R.string.jgit_error_dialog_title)). setMessage("Error occured during the pull operation, " + callingActivity.getResources().getString(R.string.jgit_error_dialog_text) - + result + + errorMessage + "\nPlease check the FAQ for possible reasons why this error might occur."). setPositiveButton(callingActivity.getResources().getString(R.string.dialog_ok), new DialogInterface.OnClickListener() { @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 56e069d3..06eb6bb3 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/PushOperation.java +++ b/app/src/main/java/com/zeapo/pwdstore/git/PushOperation.java @@ -44,11 +44,11 @@ public class PushOperation extends GitOperation { } @Override - public void onTaskEnded(String result) { + public void onError(String errorMessage) { // TODO handle the "Nothing to push" case new AlertDialog.Builder(callingActivity). setTitle(callingActivity.getResources().getString(R.string.jgit_error_dialog_title)). - setMessage(callingActivity.getString(R.string.jgit_error_push_dialog_text) + result). + setMessage(callingActivity.getString(R.string.jgit_error_push_dialog_text) + errorMessage). setPositiveButton(callingActivity.getResources().getString(R.string.dialog_ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { 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 089993d3..9dd43cb9 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/SyncOperation.java +++ b/app/src/main/java/com/zeapo/pwdstore/git/SyncOperation.java @@ -57,12 +57,12 @@ public class SyncOperation extends GitOperation { } @Override - public void onTaskEnded(String result) { + public void onError(String errorMessage) { new AlertDialog.Builder(callingActivity). setTitle(callingActivity.getResources().getString(R.string.jgit_error_dialog_title)). setMessage("Error occured during the sync operation, " + callingActivity.getResources().getString(R.string.jgit_error_dialog_text) - + result + + errorMessage + "\nPlease check the FAQ for possible reasons why this error might occur."). setPositiveButton(callingActivity.getResources().getString(R.string.dialog_ok), new DialogInterface.OnClickListener() { @Override