diff options
Diffstat (limited to 'app/src/main/java')
3 files changed, 31 insertions, 23 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java index 5927ba83..146b9906 100644 --- a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java +++ b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java @@ -47,9 +47,31 @@ public class PasswordStore extends ActionBarActivity { @Override public void onResume(){ super.onResume(); - // create the repository static variable in PasswordRepository - PasswordRepository.getRepository(new File(getFilesDir() + this.getResources().getString(R.string.store_git))); + File dir = null; + + if (settings.getBoolean("git_external", false)) { + if (settings.getString("git_external_repo", null) == null) + { + // todo: show the main screen + } else { + dir = new File(settings.getString("git_external_repo", null)); + } + } else { + dir = new File(getFilesDir() + "/store"); + } + assert dir != null; + + // uninitialize the repo if the dir does not exist or is absolutely empty + if (!dir.exists() || !dir.isDirectory()) { + 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(); } @@ -192,7 +214,8 @@ public class PasswordStore extends ActionBarActivity { private void createRepository() { // final String keyId = settings.getString("openpgp_key_ids", ""); - File localDir = new File(getFilesDir() + "/store/"); + File localDir = PasswordRepository.getWorkTree(); + localDir.mkdir(); try { PasswordRepository.createRepository(localDir); @@ -239,8 +262,7 @@ public class PasswordStore extends ActionBarActivity { FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); - // TODO: Remove the getpaswords() as it is a temporary fix until every user has the repository_initialized set - if (settings.getBoolean("repository_initialized", false) || PasswordRepository.getPasswords(localDir).size() > 0) { + if (settings.getBoolean("repository_initialized", false)) { // do not push the fragment if we already have it if (fragmentManager.findFragmentByTag("PasswordsList") == null) { @@ -249,7 +271,6 @@ public class PasswordStore extends ActionBarActivity { fragmentManager.popBackStack(); } - PasswordRepository.setInitialized(true); plist = new PasswordFragment(); Bundle args = new Bundle(); args.putString("Path", PasswordRepository.getWorkTree().getAbsolutePath()); diff --git a/app/src/main/java/com/zeapo/pwdstore/git/GitActivity.java b/app/src/main/java/com/zeapo/pwdstore/git/GitActivity.java index 9e8e97c5..b763a275 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/GitActivity.java +++ b/app/src/main/java/com/zeapo/pwdstore/git/GitActivity.java @@ -432,8 +432,7 @@ public class GitActivity extends ActionBarActivity { * @param view */ public void cloneRepository(View view) { - localDir = new File(getApplicationContext().getFilesDir().getAbsoluteFile() + "/store"); - + localDir = PasswordRepository.getWorkTree(); hostname = ((EditText) findViewById(R.id.clone_uri)).getText().toString(); port = ((EditText) findViewById(R.id.server_port)).getText().toString(); // don't ask the user, take off the protocol that he puts in diff --git a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.java b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.java index 6e7de7f1..9395fd68 100644 --- a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.java +++ b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.java @@ -5,8 +5,8 @@ import android.util.Log; import org.apache.commons.io.FileUtils; import org.apache.commons.io.filefilter.FileFilterUtils; import org.eclipse.jgit.api.Git; -import org.eclipse.jgit.lib.StoredConfig; import org.eclipse.jgit.lib.Repository; +import org.eclipse.jgit.lib.StoredConfig; import org.eclipse.jgit.storage.file.FileRepositoryBuilder; import org.eclipse.jgit.transport.RefSpec; import org.eclipse.jgit.transport.RemoteConfig; @@ -49,11 +49,7 @@ public class PasswordRepository { } public static boolean isInitialized() { - return initialized; - } - - public static void setInitialized(boolean v) { - initialized = v; + return repository != null; } public static void createRepository(File localDir) throws Exception{ @@ -112,6 +108,7 @@ public class PasswordRepository { public static void closeRepository() { repository.close(); + repository = null; } public static ArrayList<File> getFilesList(){ @@ -131,15 +128,6 @@ public class PasswordRepository { } /** - * Gets a file from the working tree - * @param name the relative path of the file - * @return the file in the repository - */ - public static File getFile(String name) { - return new File(repository.getWorkTree() + "/" + name); - } - - /** * Gets the .gpg files in a directory * @param path the directory path * @return the list of gpg files in that directory |