diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java b/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java index f6a2d8225..2f9f655b3 100644 --- a/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java +++ b/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java @@ -47,7 +47,7 @@ public class PasswordFragment extends Fragment implements AbsListView.OnItemClic public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - mAdapter = new PasswordAdapter(getActivity(), new ArrayList()); + mAdapter = new PasswordAdapter(getActivity(), PasswordRepository.getFilesList()); } @Override diff --git a/app/src/main/java/com/zeapo/pwdstore/GitRepo.java b/app/src/main/java/com/zeapo/pwdstore/PasswordRepository.java similarity index 56% rename from app/src/main/java/com/zeapo/pwdstore/GitRepo.java rename to app/src/main/java/com/zeapo/pwdstore/PasswordRepository.java index 34757b881..5861d2293 100644 --- a/app/src/main/java/com/zeapo/pwdstore/GitRepo.java +++ b/app/src/main/java/com/zeapo/pwdstore/PasswordRepository.java @@ -1,5 +1,7 @@ package com.zeapo.pwdstore; +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.filefilter.TrueFileFilter; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.internal.storage.file.FileRepository; import org.eclipse.jgit.lib.Repository; @@ -8,15 +10,14 @@ import org.eclipse.jgit.storage.file.FileRepositoryBuilder; import java.io.File; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; -/** - * Created by zeapo on 7/27/14. - */ -public class GitRepo { +public class PasswordRepository { private static Repository repository; - protected GitRepo(){ } + protected PasswordRepository(){ } public static Repository getRepository(File localDir) { if (repository == null) { @@ -38,4 +39,17 @@ public class GitRepo { public static void closeRepository() { repository.close(); } + + public static ArrayList getFilesList(){ + return getFilesList(repository.getWorkTree()); + } + + public static ArrayList getFilesList(File path){ + List files = (List) FileUtils.listFiles(path, new String[] {"gpg"}, true); + ArrayList filePaths = new ArrayList(); + for (File file : files) { + filePaths.add(file.getAbsolutePath().replace(repository.getWorkTree().getAbsolutePath(), "")); + } + return filePaths; + } } diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java index 8b0476268..a31fa50e5 100644 --- a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java +++ b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java @@ -48,9 +48,10 @@ public class PasswordStore extends Activity implements ToCloneOrNot.OnFragmentI super.onResume(); // re-check that there was no change with the repository state checkLocalRepository(); + Repository repository = PasswordRepository.getRepository(new File(getFilesDir() + "/store/.git")); + PasswordRepository.getFilesList(); } - @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. @@ -115,12 +116,4 @@ public class PasswordStore extends Activity implements ToCloneOrNot.OnFragmentI } } - public void addItem(View view) { - ListView l = (ListView) findViewById(R.id.pass_list); - - PasswordAdapter pad = (PasswordAdapter) l.getAdapter(); - - pad.add("Something"); - } - } diff --git a/app/src/main/res/layout/fragment_password_list.xml b/app/src/main/res/layout/fragment_password_list.xml index e3f04ece6..a20912727 100644 --- a/app/src/main/res/layout/fragment_password_list.xml +++ b/app/src/main/res/layout/fragment_password_list.xml @@ -11,10 +11,5 @@ android:layout_height="match_parent" android:dividerHeight="8dp" android:divider="@android:color/transparent"/> -