diff options
Diffstat (limited to 'app/src/main/java/com/zeapo/pwdstore/utils')
3 files changed, 27 insertions, 30 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordItem.java b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordItem.java index 4f129851..7fa88085 100644 --- a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordItem.java +++ b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordItem.java @@ -11,6 +11,7 @@ public class PasswordItem implements Comparable{ private String name; private PasswordItem parent; private File file; + private String fullPathName; public boolean selected = false; /** Create a password item @@ -20,11 +21,12 @@ public class PasswordItem implements Comparable{ * @param parent * @param type */ - protected PasswordItem(String name, PasswordItem parent, char type, File file) { + protected PasswordItem(String name, PasswordItem parent, char type, File file, File rootDir) { this.name = name; this.parent = parent; this.type = type; this.file = file; + this.fullPathName = file.getAbsolutePath().replace(rootDir.getAbsolutePath(), "").replace(file.getName(), ""); } /** Create a new Category item @@ -33,8 +35,8 @@ public class PasswordItem implements Comparable{ * @param parent * @return */ - public static PasswordItem newCategory(String name, File file, PasswordItem parent) { - return new PasswordItem(name, parent, TYPE_CATEGORY, file); + public static PasswordItem newCategory(String name, File file, PasswordItem parent, File rootDir) { + return new PasswordItem(name, parent, TYPE_CATEGORY, file, rootDir); } /** Create a new parentless category item @@ -42,8 +44,8 @@ public class PasswordItem implements Comparable{ * @param name * @return */ - public static PasswordItem newCategory(String name, File file) { - return new PasswordItem(name, null, TYPE_CATEGORY, file); + public static PasswordItem newCategory(String name, File file, File rootDir) { + return new PasswordItem(name, null, TYPE_CATEGORY, file, rootDir); } /** Create a new password item @@ -52,8 +54,8 @@ public class PasswordItem implements Comparable{ * @param parent * @return */ - public static PasswordItem newPassword(String name, File file, PasswordItem parent) { - return new PasswordItem(name, parent, TYPE_PASSWORD, file); + public static PasswordItem newPassword(String name, File file, PasswordItem parent, File rootDir) { + return new PasswordItem(name, parent, TYPE_PASSWORD, file, rootDir); } /** Create a new parentless password item @@ -61,8 +63,8 @@ public class PasswordItem implements Comparable{ * @param name * @return */ - public static PasswordItem newPassword(String name, File file) { - return new PasswordItem(name, null, TYPE_PASSWORD, file); + public static PasswordItem newPassword(String name, File file, File rootDir) { + return new PasswordItem(name, null, TYPE_PASSWORD, file, rootDir); } public char getType(){ @@ -81,6 +83,10 @@ public class PasswordItem implements Comparable{ return this.file; } + public String getFullPathName() { + return this.fullPathName; + } + @Override public String toString(){ return this.getName().replace(".gpg", ""); diff --git a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRecyclerAdapter.java b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRecyclerAdapter.java index 4bf9cb98..208ec2eb 100644 --- a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRecyclerAdapter.java +++ b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRecyclerAdapter.java @@ -1,6 +1,7 @@ package com.zeapo.pwdstore.utils; import android.support.v7.view.ActionMode; +import android.support.v7.widget.CardView; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.Menu; @@ -31,12 +32,14 @@ public class PasswordRecyclerAdapter extends RecyclerView.Adapter<PasswordRecycl public static class ViewHolder extends RecyclerView.ViewHolder { // each data item is just a string in this case public View view; + public CardView card; public TextView name; public TextView type; public ViewHolder(View v) { super(v); view = v; + card = (CardView) view.findViewById(R.id.password_card); name = (TextView) view.findViewById(R.id.label); type = (TextView) view.findViewById(R.id.type); } @@ -68,23 +71,11 @@ public class PasswordRecyclerAdapter extends RecyclerView.Adapter<PasswordRecycl int sdk = android.os.Build.VERSION.SDK_INT; if (pass.getType() == PasswordItem.TYPE_CATEGORY) { - holder.type.setText("C"); - if(sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) { - holder.type.setBackgroundDrawable(activity.getResources().getDrawable(R.drawable.category_rectangle)); - } else { - holder.type.setBackground(activity.getResources().getDrawable(R.drawable.category_rectangle)); - } - - holder.type.setTextColor(activity.getResources().getColor(R.color.deep_orange_50)); + holder.type.setText(pass.getFullPathName()); + holder.card.setCardBackgroundColor(activity.getResources().getColor(R.color.deep_orange_400)); } else { - holder.type.setText("P"); - if(sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) { - holder.type.setBackgroundDrawable(activity.getResources().getDrawable(R.drawable.password_rectangle)); - } else { - holder.type.setBackground(activity.getResources().getDrawable(R.drawable.password_rectangle)); - } - - holder.type.setTextColor(activity.getResources().getColor(R.color.blue_grey_50)); + holder.type.setText(pass.getFullPathName()); + holder.card.setCardBackgroundColor(activity.getResources().getColor(R.color.light_blue_600)); } holder.view.setOnClickListener(new View.OnClickListener() { 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 a2ca8824..c571e5a5 100644 --- a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.java +++ b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.java @@ -155,8 +155,8 @@ public class PasswordRepository { * Gets the password items in the root directory * @return a list of passwords in the root direcotyr */ - public static ArrayList<PasswordItem> getPasswords() { - return getPasswords(repository.getWorkTree()); + public static ArrayList<PasswordItem> getPasswords(File rootDir) { + return getPasswords(rootDir, rootDir); } public static File getWorkTree() { @@ -183,7 +183,7 @@ public class PasswordRepository { * @param path the directory path * @return a list of password items */ - public static ArrayList<PasswordItem> getPasswords(File path) { + public static ArrayList<PasswordItem> getPasswords(File path, File rootDir) { //We need to recover the passwords then parse the files ArrayList<File> passList = getFilesList(path); @@ -193,12 +193,12 @@ public class PasswordRepository { for (File file : passList) { if (file.isFile()) { - passwordList.add(PasswordItem.newPassword(file.getName(), file)); + passwordList.add(PasswordItem.newPassword(file.getName(), file, rootDir)); } else { // ignore .git directory if (file.getName().equals(".git")) continue; - passwordList.add(PasswordItem.newCategory(file.getName(), file)); + passwordList.add(PasswordItem.newCategory(file.getName(), file, rootDir)); } } sort(passwordList); |
