aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorZeapo <mohamed@zenadi.com>2014-07-27 22:40:15 +0100
committerZeapo <mohamed@zenadi.com>2014-07-27 22:40:15 +0100
commitf738c7ee36c0798a96b39aaf57aabf1f1843d60f (patch)
tree896c698ceca2e668333970a4bb6127c0c8615922 /app/src/main/java
parent3f5e93e5c30c937fe1efd10f947f538fcf7cb1a4 (diff)
performance optimization
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/PasswordRepository.java43
1 files changed, 41 insertions, 2 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordRepository.java b/app/src/main/java/com/zeapo/pwdstore/PasswordRepository.java
index 5861d229..75e65144 100644
--- a/app/src/main/java/com/zeapo/pwdstore/PasswordRepository.java
+++ b/app/src/main/java/com/zeapo/pwdstore/PasswordRepository.java
@@ -11,11 +11,15 @@ import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.List;
public class PasswordRepository {
private static Repository repository;
+ private static LinkedHashMap<String, ArrayList<String>> mainPasswordMap;
+ private static ArrayList<String> mainListOfFiles;
protected PasswordRepository(){ }
@@ -41,15 +45,50 @@ public class PasswordRepository {
}
public static ArrayList<String> getFilesList(){
- return getFilesList(repository.getWorkTree());
+ // Avoid multiple queries
+ if (null == mainListOfFiles) {
+ mainListOfFiles = getFilesList(repository.getWorkTree());
+ }
+ return mainListOfFiles;
+ }
+
+ public static LinkedHashMap<String, ArrayList<String>> getPasswords() {
+ // avoid multiple queries
+ if (null == mainPasswordMap) {
+ mainPasswordMap = getPasswords(repository.getWorkTree());
+ }
+ return mainPasswordMap;
}
public static ArrayList<String> getFilesList(File path){
List<File> files = (List<File>) FileUtils.listFiles(path, new String[] {"gpg"}, true);
ArrayList<String> filePaths = new ArrayList<String>();
for (File file : files) {
- filePaths.add(file.getAbsolutePath().replace(repository.getWorkTree().getAbsolutePath(), ""));
+ filePaths.add(file.getAbsolutePath().replace(repository.getWorkTree().getAbsolutePath() + "/", ""));
}
return filePaths;
}
+
+ public static LinkedHashMap<String, ArrayList<String>> getPasswords(File path) {
+ //We need to recover the passwords then parse the files
+ ArrayList<String> passList = getFilesList(path);
+ LinkedHashMap<String, ArrayList<String>> passMap = new LinkedHashMap<String, ArrayList<String>>();
+ passMap.put("Without Category", new ArrayList<String>());
+
+ for (String file : passList) {
+ String[] parts = file.split("/");
+ if (parts.length == 1) {
+ passMap.get("Without Category").add(parts[0]);
+ } else {
+ if (passMap.containsKey(parts[0])) {
+ passMap.get(parts[0]).add(parts[1]);
+ } else {
+ ArrayList<String> tempList = new ArrayList<String>();
+ tempList.add(parts[1]);
+ passMap.put(parts[0], tempList);
+ }
+ }
+ }
+ return passMap;
+ }
}