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
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

View file

@ -99,8 +99,10 @@ public class GitAsyncTask extends AsyncTask<GitCommand, Integer, String> {
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();

View file

@ -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() {
}
}

View file

@ -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

View file

@ -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) {

View file

@ -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