From 737d2819273e7ba07d3a993422b138b93b852415 Mon Sep 17 00:00:00 2001 From: Mohamed Zenadi Date: Sun, 11 Dec 2016 16:57:17 +0100 Subject: Handle jgit errors (#243) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * initial work on the git error handling * remove throws exception and handle the jsch one correctly * move the commit task into its own operation * get rid of the interface and rely on the abstract class GitOperation * add error message to the pull command * add error message to the push command * add error message to the sync operationˆ --- .../java/com/zeapo/pwdstore/git/GitAsyncTask.java | 30 +++------------------- 1 file changed, 3 insertions(+), 27 deletions(-) (limited to 'app/src/main/java/com/zeapo/pwdstore/git/GitAsyncTask.java') 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 b5d1c907..70d3482f 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/GitAsyncTask.java +++ b/app/src/main/java/com/zeapo/pwdstore/git/GitAsyncTask.java @@ -2,16 +2,11 @@ package com.zeapo.pwdstore.git; import android.app.Activity; import android.app.ProgressDialog; -import android.content.DialogInterface; import android.os.AsyncTask; -import android.support.v7.app.AlertDialog; import com.zeapo.pwdstore.PasswordStore; import com.zeapo.pwdstore.R; -import com.zeapo.pwdstore.utils.PasswordRepository; -import org.apache.commons.io.FileUtils; -import org.eclipse.jgit.api.CloneCommand; import org.eclipse.jgit.api.GitCommand; @@ -20,9 +15,9 @@ public class GitAsyncTask extends AsyncTask { private boolean finishOnEnd; private boolean refreshListOnEnd; private ProgressDialog dialog; - private Class operation; + private GitOperation operation; - public GitAsyncTask(Activity activity, boolean finishOnEnd, boolean refreshListOnEnd, Class operation) { + public GitAsyncTask(Activity activity, boolean finishOnEnd, boolean refreshListOnEnd, GitOperation operation) { this.activity = activity; this.finishOnEnd = finishOnEnd; this.refreshListOnEnd = refreshListOnEnd; @@ -63,26 +58,7 @@ public class GitAsyncTask extends AsyncTask { result = "Unexpected error"; if (!result.isEmpty()) { - new AlertDialog.Builder(activity). - setTitle(activity.getResources().getString(R.string.jgit_error_dialog_title)). - setMessage(activity.getResources().getString(R.string.jgit_error_dialog_text) + result). - setPositiveButton(activity.getResources().getString(R.string.dialog_ok), new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int i) { - if (operation.equals(CloneCommand.class)) { - // if we were unable to finish the job - try { - FileUtils.deleteDirectory(PasswordRepository.getWorkTree()); - } catch (Exception e) { - e.printStackTrace(); - } - } else { - activity.setResult(Activity.RESULT_CANCELED); - activity.finish(); - } - } - }).show(); - + this.operation.onTaskEnded(result); } else { if (finishOnEnd) { this.activity.setResult(Activity.RESULT_OK); -- cgit v1.2.3