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();
}
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,
Intent data) {
if (resultCode == RESULT_OK) {
@ -515,16 +524,18 @@ public class PasswordStore extends AppCompatActivity {
settings.edit().putBoolean("repository_initialized", true).apply();
break;
case PgpHandler.REQUEST_CODE_DECRYPT_AND_VERIFY:
if (!data.getBooleanExtra("needCommit", false)) {
break;
// if went from decrypt->edit and user saved changes, we need to commit
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:
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(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.add_commit_text) + data.getExtras().getString("NAME") + this.getResources().getString(R.string.from_store));
refreshListAdapter();
break;
case PgpHandler.REQUEST_CODE_EDIT:
commit(this.getResources().getString(R.string.edit_commit_text) + data.getExtras().getString("NAME"));
refreshListAdapter();
break;
case GitActivity.REQUEST_INIT:

View file

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

View file

@ -25,6 +25,7 @@
<string name="initialization_commit_text">[ANDROID PwdStore] Initialized store with keyID: </string>
<string name="add_commit_text">[ANDROID PwdStore] Add &#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>
<!-- PGPHandler -->