From da8ec72655f3009df83ec0a5c0945f8735863e4e Mon Sep 17 00:00:00 2001 From: knuthy Date: Tue, 23 Sep 2014 00:23:55 +0200 Subject: Take into account subdirectories Fix #9 --- .../main/java/com/zeapo/pwdstore/GitHandler.java | 5 ----- .../java/com/zeapo/pwdstore/PasswordStore.java | 1 + .../zeapo/pwdstore/utils/PasswordRepository.java | 25 ++++++++++++++-------- 3 files changed, 17 insertions(+), 14 deletions(-) (limited to 'app/src') diff --git a/app/src/main/java/com/zeapo/pwdstore/GitHandler.java b/app/src/main/java/com/zeapo/pwdstore/GitHandler.java index cbb816c1..c487ce0f 100644 --- a/app/src/main/java/com/zeapo/pwdstore/GitHandler.java +++ b/app/src/main/java/com/zeapo/pwdstore/GitHandler.java @@ -2,12 +2,10 @@ package com.zeapo.pwdstore; import android.app.Activity; import android.app.AlertDialog; -import android.app.ProgressDialog; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; -import android.os.AsyncTask; import android.os.Bundle; import android.preference.PreferenceManager; import android.text.InputType; @@ -34,9 +32,6 @@ import org.apache.commons.io.FileUtils; import org.eclipse.jgit.api.GitCommand; import org.eclipse.jgit.api.PullCommand; import org.eclipse.jgit.api.PushCommand; -import org.eclipse.jgit.api.errors.InvalidRemoteException; -import org.eclipse.jgit.api.errors.JGitInternalException; -import org.eclipse.jgit.api.errors.TransportException; import org.eclipse.jgit.errors.UnsupportedCredentialItem; import org.eclipse.jgit.transport.CredentialItem; import org.eclipse.jgit.transport.CredentialsProvider; diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java index 71954859..4fadb65e 100644 --- a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java +++ b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java @@ -215,6 +215,7 @@ public class PasswordStore extends Activity implements ToCloneOrNot.OnFragmentI } private void checkLocalRepository(File localDir) { + Log.d("PASS", localDir.getAbsolutePath()); FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); 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 eda32b0a..289f9f43 100644 --- a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.java +++ b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.java @@ -1,6 +1,9 @@ package com.zeapo.pwdstore.utils; +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; @@ -10,7 +13,10 @@ import org.eclipse.jgit.transport.RemoteConfig; import org.eclipse.jgit.transport.URIish; import java.io.File; +import java.io.FileFilter; +import java.lang.reflect.Array; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Set; @@ -115,7 +121,10 @@ public class PasswordRepository { public static ArrayList getFilesList(File path){ if (!path.exists()) return new ArrayList(); - List files = (List) FileUtils.listFiles(path, new String[] {"gpg"}, true); + Log.d("REPO", path.getAbsolutePath()); + 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); } @@ -129,15 +138,13 @@ public class PasswordRepository { ArrayList passwordList = new ArrayList(); for (File file : passList) { - String fileName = file.getAbsolutePath().replace(path.getAbsolutePath() + "/", ""); - - String[] parts = fileName.split("/"); - if (parts.length == 1) { - passwordList.add(PasswordItem.newPassword(parts[0], file)); + if (file.isFile()) { + passwordList.add(PasswordItem.newPassword(file.getName(), file)); } else { - if (!passwordList.contains(PasswordItem.newCategory(parts[0], file.getParentFile()))) { - passwordList.add(PasswordItem.newCategory(parts[0], file.getParentFile())); - } + // ignore .git directory + if (file.getName().equals(".git")) + continue; + passwordList.add(PasswordItem.newCategory(file.getName(), file)); } } sort(passwordList); -- cgit v1.2.3