From 7ddc23ee839c8648b60217101862b739df4018c3 Mon Sep 17 00:00:00 2001 From: zeapo Date: Wed, 29 Oct 2014 22:09:40 +0100 Subject: corrected some issues with filtering and categories --- .../zeapo/pwdstore/utils/PasswordRepository.java | 27 ++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'app/src/main/java/com/zeapo/pwdstore/utils') 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 b35f9701..31dea887 100644 --- a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.java +++ b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.java @@ -28,6 +28,11 @@ public class PasswordRepository { protected PasswordRepository(){ } + /** + * Returns the git repository + * @param localDir needed only on the creation + * @return the git repository + */ public static Repository getRepository(File localDir) { if (repository == null) { FileRepositoryBuilder builder = new FileRepositoryBuilder(); @@ -92,6 +97,10 @@ public class PasswordRepository { return getFilesList(repository.getWorkTree()); } + /** + * Gets the password items in the root directory + * @return a list of passwords in the root direcotyr + */ public static ArrayList getPasswords() { return getPasswords(repository.getWorkTree()); } @@ -100,27 +109,41 @@ public class PasswordRepository { return repository.getWorkTree(); } + /** + * 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 + */ public static ArrayList getFilesList(File path){ if (!path.exists()) return new ArrayList(); - Log.d("REPO", path.getAbsolutePath()); + Log.d("REPO", "current path: " + path.getPath()); ArrayList files = new ArrayList(Arrays.asList(path.listFiles((FileFilter) FileFilterUtils.directoryFileFilter()))); files.addAll( new ArrayList((List)FileUtils.listFiles(path, new String[] {"gpg"}, false))); return new ArrayList(files); } + /** + * Gets the passwords (PasswordItem) in a directory + * @param path the directory path + * @return a list of password items + */ public static ArrayList getPasswords(File path) { //We need to recover the passwords then parse the files ArrayList passList = getFilesList(path); if (passList.size() == 0) return new ArrayList(); - // TODO replace with a set ArrayList passwordList = new ArrayList(); for (File file : passList) { -- cgit v1.2.3