diff options
author | Mohamed Zenadi <mohamed@zenadi.com> | 2015-05-03 22:49:44 +0200 |
---|---|---|
committer | Mohamed Zenadi <mohamed@zenadi.com> | 2015-05-17 18:58:18 +0200 |
commit | 7fe81e9c27d10ec992a28bdea146c84f3e11cd60 (patch) | |
tree | 6519815ade214e60309351ddcf684ea38793b5cf /app/src/main | |
parent | a21dd84c2bc299cabb5f4e8d5187b78e16f03e02 (diff) |
it is no longer necessary to go through settings to initialize an external repo
Diffstat (limited to 'app/src/main')
-rw-r--r-- | app/src/main/java/com/zeapo/pwdstore/PasswordStore.java | 80 |
1 files changed, 52 insertions, 28 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java index c788821f..048a7b29 100644 --- a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java +++ b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java @@ -51,34 +51,6 @@ public class PasswordStore extends AppCompatActivity { @Override public void onResume(){ super.onResume(); - File dir = null; - - if (settings.getBoolean("git_external", false)) { - if (settings.getString("git_external_repo", null) != null) { - dir = new File(settings.getString("git_external_repo", null)); - } - } else { - dir = new File(getFilesDir() + "/store"); - } - // temp for debug - if (dir == null) { - Intent intent = new Intent(this, UserPreference.class); - intent.putExtra("operation", "git_external"); - startActivity(intent); - return; - } - - // uninitialize the repo if the dir does not exist or is absolutely empty - if (!dir.exists() || !dir.isDirectory() || FileUtils.listFiles(dir, null, false).isEmpty()) { - settings.edit().putBoolean("repository_initialized", false).apply(); - } - - if (!PasswordRepository.getPasswords(dir).isEmpty()) { - settings.edit().putBoolean("repository_initialized", true).apply(); - } - - // create the repository static variable in PasswordRepository - PasswordRepository.getRepository(new File(dir.getAbsolutePath() + "/.git")); checkLocalRepository(); } @@ -239,6 +211,17 @@ public class PasswordStore extends AppCompatActivity { } public void initializeRepositoryInfo() { + if (settings.getBoolean("git_external", false) && settings.getString("git_external_repo", null) != null) { + File dir = new File(settings.getString("git_external_repo", null)); + + if (dir.exists() && dir.isDirectory() && !FileUtils.listFiles(dir, null, true).isEmpty() && + !PasswordRepository.getPasswords(dir).isEmpty()) { + PasswordRepository.closeRepository(); + checkLocalRepository(); + return; // if not empty, just show me the passwords! + } + } + final String keyId = settings.getString("openpgp_key_ids", ""); if (keyId != null && keyId.isEmpty()) @@ -263,6 +246,35 @@ public class PasswordStore extends AppCompatActivity { } private void checkLocalRepository() { + File dir = null; + + if (settings.getBoolean("git_external", false)) { + if (settings.getString("git_external_repo", null) != null) { + dir = new File(settings.getString("git_external_repo", null)); + } + } else { + dir = new File(getFilesDir() + "/store"); + } + // temp for debug + if (dir == null) { + Intent intent = new Intent(this, UserPreference.class); + intent.putExtra("operation", "git_external"); + startActivity(intent); + return; + } + + // uninitialize the repo if the dir does not exist or is absolutely empty + if (!dir.exists() || !dir.isDirectory() || FileUtils.listFiles(dir, null, false).isEmpty()) { + settings.edit().putBoolean("repository_initialized", false).apply(); + } + + if (!PasswordRepository.getPasswords(dir).isEmpty()) { + settings.edit().putBoolean("repository_initialized", true).apply(); + } + + // create the repository static variable in PasswordRepository + PasswordRepository.getRepository(new File(dir.getAbsolutePath() + "/.git")); + checkLocalRepository(PasswordRepository.getWorkTree()); } @@ -446,6 +458,17 @@ public class PasswordStore extends AppCompatActivity { initializeRepositoryInfo(); break; case CLONE_REPO_BUTTON: + // duplicate code + if (settings.getBoolean("git_external", false) && settings.getString("git_external_repo", null) != null) { + File dir = new File(settings.getString("git_external_repo", null)); + + if (dir.exists() && dir.isDirectory() && !FileUtils.listFiles(dir, null, true).isEmpty() && + !PasswordRepository.getPasswords(dir).isEmpty()) { + PasswordRepository.closeRepository(); + checkLocalRepository(); + return; // if not empty, just show me the passwords! + } + } Intent intent = new Intent(activity, GitActivity.class); intent.putExtra("Operation", GitActivity.REQUEST_CLONE); startActivityForResult(intent, GitActivity.REQUEST_CLONE); @@ -467,6 +490,7 @@ public class PasswordStore extends AppCompatActivity { intent.putExtra("operation", "git_external"); startActivityForResult(intent, operation); } else { + PasswordRepository.closeRepository(); checkLocalRepository(); } } |