add and remove are now committing files to git
This commit is contained in:
parent
bac44808d3
commit
79fd5586f9
3 changed files with 25 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
|||
package com.zeapo.pwdstore;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.ProgressDialog;
|
||||
import android.os.AsyncTask;
|
||||
import android.util.Log;
|
||||
|
||||
|
@ -15,10 +16,21 @@ import org.eclipse.jgit.api.errors.TransportException;
|
|||
public class GitAsyncTask extends AsyncTask<GitCommand, Integer, Integer> {
|
||||
private Activity activity;
|
||||
private boolean finishOnEnd;
|
||||
private ProgressDialog dialog;
|
||||
|
||||
public GitAsyncTask(Activity activity, boolean finishOnEnd) {
|
||||
this.activity = activity;
|
||||
this.finishOnEnd = finishOnEnd;
|
||||
|
||||
dialog = new ProgressDialog(this.activity);
|
||||
}
|
||||
|
||||
protected void onPreExecute() {
|
||||
this.dialog.setMessage("Running command...");
|
||||
this.dialog.setCancelable(false);
|
||||
this.dialog.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Integer doInBackground(GitCommand... cmd) {
|
||||
int count = cmd.length;
|
||||
|
@ -45,6 +57,7 @@ public class GitAsyncTask extends AsyncTask<GitCommand, Integer, Integer> {
|
|||
|
||||
protected void onPostExecute(Integer result) {
|
||||
Log.i("GIT_ASYNC", result + "");
|
||||
this.dialog.dismiss();
|
||||
if (finishOnEnd) {
|
||||
this.activity.finish();
|
||||
}
|
||||
|
|
|
@ -262,7 +262,7 @@ public class PasswordStore extends Activity implements ToCloneOrNot.OnFragmentI
|
|||
GitAsyncTask tasks = new GitAsyncTask(this, false);
|
||||
tasks.execute(
|
||||
git.add().addFilepattern("."),
|
||||
git.commit().setMessage("Added " + data.getExtras().getString("NAME"))
|
||||
git.commit().setMessage("[ANDROID PwdStore] Add " + data.getExtras().getString("NAME") + " from store.")
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -25,11 +25,13 @@ import android.widget.ProgressBar;
|
|||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.zeapo.pwdstore.GitAsyncTask;
|
||||
import com.zeapo.pwdstore.R;
|
||||
import com.zeapo.pwdstore.UserPreference;
|
||||
import com.zeapo.pwdstore.utils.PasswordRepository;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.eclipse.jgit.api.Git;
|
||||
import org.openintents.openpgp.OpenPgpError;
|
||||
import org.openintents.openpgp.OpenPgpSignatureResult;
|
||||
import org.openintents.openpgp.util.OpenPgpApi;
|
||||
|
@ -50,6 +52,7 @@ public class PgpHandler extends Activity {
|
|||
private String keyIDs = "";
|
||||
private String accountName = "";
|
||||
SharedPreferences settings;
|
||||
private Activity activity;
|
||||
|
||||
public static final int REQUEST_CODE_SIGN = 9910;
|
||||
public static final int REQUEST_CODE_ENCRYPT = 9911;
|
||||
|
@ -68,6 +71,7 @@ public class PgpHandler extends Activity {
|
|||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
activity = this;
|
||||
|
||||
// some persistance
|
||||
settings = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
|
@ -441,6 +445,13 @@ public class PgpHandler extends Activity {
|
|||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
(new File(getIntent().getExtras().getString("FILE_PATH"))).delete();
|
||||
|
||||
Git git = new Git(PasswordRepository.getRepository(new File("")));
|
||||
GitAsyncTask tasks = new GitAsyncTask(activity, false);
|
||||
tasks.execute(
|
||||
git.rm().addFilepattern(getIntent().getExtras().getString("FILE_PATH").replace(PasswordRepository.getWorkTree() + "/", "")),
|
||||
git.commit().setMessage("[ANDROID PwdStore] Remove " + getIntent().getExtras().getString("FILE_PATH") + " from store.")
|
||||
);
|
||||
setResult(RESULT_OK);
|
||||
finish();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue