introduce onSuccess/onError

This commit is contained in:
zeapo
2017-08-11 09:31:36 +02:00
parent 8ae59a4922
commit d6017be4ec
6 changed files with 22 additions and 12 deletions

View File

@@ -72,12 +72,12 @@ public class CloneOperation extends GitOperation {
} }
@Override @Override
public void onTaskEnded(String result) { public void onError(String errorMessage) {
new AlertDialog.Builder(callingActivity). new AlertDialog.Builder(callingActivity).
setTitle(callingActivity.getResources().getString(R.string.jgit_error_dialog_title)). setTitle(callingActivity.getResources().getString(R.string.jgit_error_dialog_title)).
setMessage("Error occured during the clone operation, " setMessage("Error occured during the clone operation, "
+ callingActivity.getResources().getString(R.string.jgit_error_dialog_text) + callingActivity.getResources().getString(R.string.jgit_error_dialog_text)
+ result + errorMessage
+ "\nPlease check the FAQ for possible reasons why this error might occur."). + "\nPlease check the FAQ for possible reasons why this error might occur.").
setPositiveButton(callingActivity.getResources().getString(R.string.dialog_ok), new DialogInterface.OnClickListener() { setPositiveButton(callingActivity.getResources().getString(R.string.dialog_ok), new DialogInterface.OnClickListener() {
@Override @Override

View File

@@ -99,8 +99,10 @@ public class GitAsyncTask extends AsyncTask<GitCommand, Integer, String> {
result = "Unexpected error"; result = "Unexpected error";
if (!result.isEmpty()) { if (!result.isEmpty()) {
this.operation.onTaskEnded(result); this.operation.onError(result);
} else { } else {
this.operation.onSuccess();
if (finishOnEnd) { if (finishOnEnd) {
this.activity.setResult(Activity.RESULT_OK); this.activity.setResult(Activity.RESULT_OK);
this.activity.finish(); this.activity.finish();

View File

@@ -25,7 +25,6 @@ import com.zeapo.pwdstore.git.config.SshConfigSessionFactory;
import com.zeapo.pwdstore.utils.PasswordRepository; import com.zeapo.pwdstore.utils.PasswordRepository;
import org.eclipse.jgit.api.GitCommand; import org.eclipse.jgit.api.GitCommand;
import org.eclipse.jgit.diff.Edit;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.transport.JschConfigSessionFactory; import org.eclipse.jgit.transport.JschConfigSessionFactory;
import org.eclipse.jgit.transport.SshSessionFactory; 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). new AlertDialog.Builder(callingActivity).
setTitle(callingActivity.getResources().getString(R.string.jgit_error_dialog_title)). 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() { setPositiveButton(callingActivity.getResources().getString(R.string.dialog_ok), new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialogInterface, int i) { public void onClick(DialogInterface dialogInterface, int i) {
@@ -245,4 +247,10 @@ public abstract class GitOperation {
} }
}).show(); }).show();
} }
/**
* Action to execute on success
*/
public void onSuccess() {
}
} }

View File

@@ -45,12 +45,12 @@ public class PullOperation extends GitOperation {
} }
@Override @Override
public void onTaskEnded(String result) { public void onError(String errorMessage) {
new AlertDialog.Builder(callingActivity). new AlertDialog.Builder(callingActivity).
setTitle(callingActivity.getResources().getString(R.string.jgit_error_dialog_title)). setTitle(callingActivity.getResources().getString(R.string.jgit_error_dialog_title)).
setMessage("Error occured during the pull operation, " setMessage("Error occured during the pull operation, "
+ callingActivity.getResources().getString(R.string.jgit_error_dialog_text) + callingActivity.getResources().getString(R.string.jgit_error_dialog_text)
+ result + errorMessage
+ "\nPlease check the FAQ for possible reasons why this error might occur."). + "\nPlease check the FAQ for possible reasons why this error might occur.").
setPositiveButton(callingActivity.getResources().getString(R.string.dialog_ok), new DialogInterface.OnClickListener() { setPositiveButton(callingActivity.getResources().getString(R.string.dialog_ok), new DialogInterface.OnClickListener() {
@Override @Override

View File

@@ -44,11 +44,11 @@ public class PushOperation extends GitOperation {
} }
@Override @Override
public void onTaskEnded(String result) { public void onError(String errorMessage) {
// TODO handle the "Nothing to push" case // TODO handle the "Nothing to push" case
new AlertDialog.Builder(callingActivity). new AlertDialog.Builder(callingActivity).
setTitle(callingActivity.getResources().getString(R.string.jgit_error_dialog_title)). 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() { setPositiveButton(callingActivity.getResources().getString(R.string.dialog_ok), new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialogInterface, int i) { public void onClick(DialogInterface dialogInterface, int i) {

View File

@@ -57,12 +57,12 @@ public class SyncOperation extends GitOperation {
} }
@Override @Override
public void onTaskEnded(String result) { public void onError(String errorMessage) {
new AlertDialog.Builder(callingActivity). new AlertDialog.Builder(callingActivity).
setTitle(callingActivity.getResources().getString(R.string.jgit_error_dialog_title)). setTitle(callingActivity.getResources().getString(R.string.jgit_error_dialog_title)).
setMessage("Error occured during the sync operation, " setMessage("Error occured during the sync operation, "
+ callingActivity.getResources().getString(R.string.jgit_error_dialog_text) + callingActivity.getResources().getString(R.string.jgit_error_dialog_text)
+ result + errorMessage
+ "\nPlease check the FAQ for possible reasons why this error might occur."). + "\nPlease check the FAQ for possible reasons why this error might occur.").
setPositiveButton(callingActivity.getResources().getString(R.string.dialog_ok), new DialogInterface.OnClickListener() { setPositiveButton(callingActivity.getResources().getString(R.string.dialog_ok), new DialogInterface.OnClickListener() {
@Override @Override