Fix & refine weird editing behaviour

This commit is contained in:
Matthew Wong 2016-07-02 13:30:59 -04:00
parent 8664d5e8ec
commit 5a509af320
3 changed files with 24 additions and 9 deletions

View file

@ -506,6 +506,15 @@ public class PasswordStore extends AppCompatActivity {
return PasswordRepository.getWorkTree(); return PasswordRepository.getWorkTree();
} }
private void commit(String message) {
Git git = new Git(PasswordRepository.getRepository(new File("")));
GitAsyncTask tasks = new GitAsyncTask(this, false, false, CommitCommand.class);
tasks.execute(
git.add().addFilepattern("."),
git.commit().setMessage(message)
);
}
protected void onActivityResult(int requestCode, int resultCode, protected void onActivityResult(int requestCode, int resultCode,
Intent data) { Intent data) {
if (resultCode == RESULT_OK) { if (resultCode == RESULT_OK) {
@ -515,16 +524,18 @@ public class PasswordStore extends AppCompatActivity {
settings.edit().putBoolean("repository_initialized", true).apply(); settings.edit().putBoolean("repository_initialized", true).apply();
break; break;
case PgpHandler.REQUEST_CODE_DECRYPT_AND_VERIFY: case PgpHandler.REQUEST_CODE_DECRYPT_AND_VERIFY:
if (!data.getBooleanExtra("needCommit", false)) { // if went from decrypt->edit and user saved changes, we need to commit
break; if (data.getBooleanExtra("needCommit", false)) {
commit(this.getResources().getString(R.string.edit_commit_text) + data.getExtras().getString("NAME"));
refreshListAdapter();
} }
break;
case PgpHandler.REQUEST_CODE_ENCRYPT: case PgpHandler.REQUEST_CODE_ENCRYPT:
Git git = new Git(PasswordRepository.getRepository(new File(""))); commit(this.getResources().getString(R.string.add_commit_text) + data.getExtras().getString("NAME") + this.getResources().getString(R.string.from_store));
GitAsyncTask tasks = new GitAsyncTask(this, false, false, CommitCommand.class); refreshListAdapter();
tasks.execute( break;
git.add().addFilepattern("."), case PgpHandler.REQUEST_CODE_EDIT:
git.commit().setMessage(this.getResources().getString(R.string.add_commit_text) + data.getExtras().getString("NAME") + this.getResources().getString(R.string.from_store)) commit(this.getResources().getString(R.string.edit_commit_text) + data.getExtras().getString("NAME"));
);
refreshListAdapter(); refreshListAdapter();
break; break;
case GitActivity.REQUEST_INIT: case GitActivity.REQUEST_INIT:

View file

@ -149,6 +149,7 @@ public class PgpHandler extends AppCompatActivity implements OpenPgpServiceConne
break; break;
case R.id.edit_password: case R.id.edit_password:
editPassword(); editPassword();
break;
case R.id.crypto_confirm_add: case R.id.crypto_confirm_add:
encrypt(new Intent()); encrypt(new Intent());
break; break;
@ -161,7 +162,6 @@ public class PgpHandler extends AppCompatActivity implements OpenPgpServiceConne
} }
public void editPassword() { public void editPassword() {
// if in encrypt or in decrypt and password is invisible // if in encrypt or in decrypt and password is invisible
// (because !showPassword, so this will instantly close), do nothing // (because !showPassword, so this will instantly close), do nothing
if (findViewById(R.id.crypto_password_show) == null if (findViewById(R.id.crypto_password_show) == null
@ -195,6 +195,9 @@ public class PgpHandler extends AppCompatActivity implements OpenPgpServiceConne
intent.putExtra("Operation", "ENCRYPT"); intent.putExtra("Operation", "ENCRYPT");
intent.putExtra("fromDecrypt", true); intent.putExtra("fromDecrypt", true);
setIntent(intent); setIntent(intent);
// recreate the options menu to be the encrypt one
invalidateOptionsMenu();
} }
public void copyToClipBoard() { public void copyToClipBoard() {

View file

@ -25,6 +25,7 @@
<string name="initialization_commit_text">[ANDROID PwdStore] Initialized store with keyID: </string> <string name="initialization_commit_text">[ANDROID PwdStore] Initialized store with keyID: </string>
<string name="add_commit_text">[ANDROID PwdStore] Add &#160;</string> <string name="add_commit_text">[ANDROID PwdStore] Add &#160;</string>
<string name="remove_commit_text">[ANDROID PwdStore] Remove &#160;</string> <string name="remove_commit_text">[ANDROID PwdStore] Remove &#160;</string>
<string name="edit_commit_text">[ANDROID PwdStore] Edit &#160;</string>
<string name="from_store">&#160; from store.</string> <string name="from_store">&#160; from store.</string>
<!-- PGPHandler --> <!-- PGPHandler -->