diff options
Diffstat (limited to 'app/src/main/java')
5 files changed, 106 insertions, 36 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/DividerItemDecoration.java b/app/src/main/java/com/zeapo/pwdstore/DividerItemDecoration.java new file mode 100644 index 00000000..7bc66b62 --- /dev/null +++ b/app/src/main/java/com/zeapo/pwdstore/DividerItemDecoration.java @@ -0,0 +1,51 @@ +package com.zeapo.pwdstore; + +import android.content.Context; +import android.content.res.TypedArray; +import android.graphics.Canvas; +import android.graphics.drawable.Drawable; +import android.support.v4.content.ContextCompat; +import android.support.v7.widget.RecyclerView; +import android.view.View; + +public class DividerItemDecoration extends RecyclerView.ItemDecoration { + + private static final int[] ATTRS = new int[]{android.R.attr.listDivider}; + + private Drawable mDivider; + + /** + * Default divider will be used + */ + public DividerItemDecoration(Context context) { + final TypedArray styledAttributes = context.obtainStyledAttributes(ATTRS); + mDivider = styledAttributes.getDrawable(0); + styledAttributes.recycle(); + } + + /** + * Custom divider will be used + */ + public DividerItemDecoration(Context context, int resId) { + mDivider = ContextCompat.getDrawable(context, resId); + } + + @Override + public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) { + int left = parent.getPaddingLeft(); + int right = parent.getWidth() - parent.getPaddingRight(); + + int childCount = parent.getChildCount(); + for (int i = 0; i < childCount; i++) { + View child = parent.getChildAt(i); + + RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams(); + + int top = child.getBottom() + params.bottomMargin; + int bottom = top + mDivider.getIntrinsicHeight(); + + mDivider.setBounds(left, top, right, bottom); + mDivider.draw(c); + } + } +} diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java b/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java index 1daa4f90..79401fbd 100644 --- a/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java +++ b/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java @@ -74,8 +74,11 @@ public class PasswordFragment extends Fragment{ recyclerView = (RecyclerView) view.findViewById(R.id.pass_recycler); recyclerView.setLayoutManager(mLayoutManager); -// -// // Set the adapter + + // use divider + recyclerView.addItemDecoration(new DividerItemDecoration(getActivity(), R.drawable.divider)); + + // Set the adapter recyclerView.setAdapter(recyclerAdapter); final FloatingActionButton fab = (FloatingActionButton) view.findViewById(R.id.fab); diff --git a/app/src/main/java/com/zeapo/pwdstore/UserPreference.java b/app/src/main/java/com/zeapo/pwdstore/UserPreference.java index 77600b2b..82132978 100644 --- a/app/src/main/java/com/zeapo/pwdstore/UserPreference.java +++ b/app/src/main/java/com/zeapo/pwdstore/UserPreference.java @@ -156,7 +156,7 @@ public class UserPreference extends AppCompatActivity { }); final Preference externalRepo = findPreference("pref_select_external"); - externalRepo.setSummary(getPreferenceManager().getSharedPreferences().getString("git_external_repo", "No external repository selected")); + externalRepo.setSummary(getPreferenceManager().getSharedPreferences().getString("git_external_repo", callingActivity.getString(R.string.no_repo_selected))); externalRepo.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { @@ -217,7 +217,7 @@ public class UserPreference extends AppCompatActivity { public void onStart() { super.onStart(); final SharedPreferences sharedPreferences = getPreferenceManager().getSharedPreferences(); - findPreference("pref_select_external").setSummary(getPreferenceManager().getSharedPreferences().getString("git_external_repo", "No external repository selected")); + findPreference("pref_select_external").setSummary(getPreferenceManager().getSharedPreferences().getString("git_external_repo", getString(R.string.no_repo_selected))); findPreference("ssh_see_key").setEnabled(sharedPreferences.getBoolean("use_generated_key", false)); findPreference("git_delete_repo").setEnabled(!sharedPreferences.getBoolean("git_external", false)); Preference keyPref = findPreference("openpgp_key_id_pref"); diff --git a/app/src/main/java/com/zeapo/pwdstore/crypto/PgpHandler.java b/app/src/main/java/com/zeapo/pwdstore/crypto/PgpHandler.java index a80e4800..f984ad31 100644 --- a/app/src/main/java/com/zeapo/pwdstore/crypto/PgpHandler.java +++ b/app/src/main/java/com/zeapo/pwdstore/crypto/PgpHandler.java @@ -81,6 +81,10 @@ public class PgpHandler extends AppCompatActivity implements OpenPgpServiceConne this.activity = this; this.clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); + if (getIntent().getStringExtra("Operation").equals("ENCRYPT")) { + setTitle("New password"); + } + // some persistance settings = PreferenceManager.getDefaultSharedPreferences(this); String providerPackageName = settings.getString("openpgp_provider_list", ""); @@ -121,7 +125,11 @@ public class PgpHandler extends AppCompatActivity implements OpenPgpServiceConne @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. - getMenuInflater().inflate(R.menu.pgp_handler, menu); + if (getIntent().getStringExtra("Operation").equals("ENCRYPT")) { + getMenuInflater().inflate(R.menu.pgp_handler_new_password, menu); + } else { + getMenuInflater().inflate(R.menu.pgp_handler, menu); + } return true; } @@ -141,6 +149,13 @@ public class PgpHandler extends AppCompatActivity implements OpenPgpServiceConne break; case R.id.edit_password: editPassword(); + case R.id.crypto_confirm_add: + encrypt(new Intent()); + break; + case R.id.crypto_cancel_add: + setResult(RESULT_CANCELED); + finish(); + return true; } return super.onOptionsItemSelected(item); } @@ -205,12 +220,6 @@ public class PgpHandler extends AppCompatActivity implements OpenPgpServiceConne case R.id.crypto_show_button: decryptAndVerify(new Intent()); break; - case R.id.crypto_confirm_add: - encrypt(new Intent()); - break; - case R.id.crypto_cancel_add: - finish(); - break; case R.id.crypto_delete_button: // deletePassword(); break; 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 45dd0d0b..cd64ecf7 100644 --- a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRecyclerAdapter.java +++ b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRecyclerAdapter.java @@ -1,13 +1,15 @@ package com.zeapo.pwdstore.utils; +import android.graphics.Color; +import android.os.Build; 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; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import android.widget.ImageView; import android.widget.TextView; import com.zeapo.pwdstore.PasswordFragment; @@ -33,16 +35,16 @@ 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 ImageView typeImage; 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); + typeImage = (ImageView) view.findViewById(R.id.type_image); } } @@ -69,21 +71,28 @@ public class PasswordRecyclerAdapter extends RecyclerView.Adapter<PasswordRecycl public void onBindViewHolder(final ViewHolder holder, int position) { final PasswordItem pass = values.get(position); holder.name.setText(pass.toString()); - int sdk = android.os.Build.VERSION.SDK_INT; + if (pass.getType() == PasswordItem.TYPE_CATEGORY) { + holder.typeImage.setImageResource(R.drawable.ic_folder_grey600_24dp); + holder.name.setText(pass.toString() + "/"); + } else { + holder.typeImage.setImageResource(R.drawable.ic_action_secure); + holder.name.setText(pass.toString()); + } + int sdk = Build.VERSION.SDK_INT; + holder.type.setText(pass.getFullPathName()); if (pass.getType() == PasswordItem.TYPE_CATEGORY) { - holder.type.setText(pass.getFullPathName()); - holder.card.setCardBackgroundColor(activity.getResources().getColor(R.color.deep_orange_400)); +// holder.card.setCardBackgroundColor(activity.getResources().getColor(R.color.blue_grey_200)); } else { - holder.type.setText(pass.getFullPathName()); - holder.card.setCardBackgroundColor(activity.getResources().getColor(R.color.blue_grey_400)); +// holder.card.setCardBackgroundColor(activity.getResources().getColor(R.color.blue_grey_50)); } holder.view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (mActionMode != null) { - toggleSelection(holder.getAdapterPosition(), holder.card, pass.getType()); + toggleSelection(holder.getAdapterPosition()); + mActionMode.setTitle("" + selectedItems.size()); if (selectedItems.isEmpty()) { mActionMode.finish(); } else if (selectedItems.size() == 1 && !canEdit) { @@ -98,6 +107,7 @@ public class PasswordRecyclerAdapter extends RecyclerView.Adapter<PasswordRecycl } else { listener.onFragmentInteraction(pass); } + notifyItemChanged(holder.getAdapterPosition()); } }); @@ -107,17 +117,27 @@ public class PasswordRecyclerAdapter extends RecyclerView.Adapter<PasswordRecycl if (mActionMode != null) { return false; } - toggleSelection(holder.getAdapterPosition(), holder.card, pass.getType()); + toggleSelection(holder.getAdapterPosition()); canEdit = pass.getType() == PasswordItem.TYPE_PASSWORD; // Start the CAB using the ActionMode.Callback mActionMode = activity.startSupportActionMode(mActionModeCallback); + mActionMode.setTitle("" + selectedItems.size()); mActionMode.invalidate(); + notifyItemChanged(holder.getAdapterPosition()); return true; } }); // after removal, everything is rebound for some reason; views are shuffled? - holder.view.setSelected(selectedItems.contains(position)); + boolean selected = selectedItems.contains(position); + holder.view.setSelected(selected); + if (selected) { + holder.itemView.setBackgroundResource(R.color.deep_orange_200); + holder.type.setTextColor(Color.BLACK); + } else { + holder.itemView.setBackgroundResource(Color.alpha(1)); + holder.type.setTextColor(activity.getColor(R.color.grey_500)); + } } private ActionMode.Callback mActionModeCallback = new ActionMode.Callback() { @@ -205,22 +225,9 @@ public class PasswordRecyclerAdapter extends RecyclerView.Adapter<PasswordRecycl updateSelectedItems(position, selectedItems); } - public void toggleSelection(int position, CardView card, char type) { + public void toggleSelection(int position) { if (!selectedItems.remove(position)) { selectedItems.add(position); - if (type == PasswordItem.TYPE_CATEGORY) { - card.setCardBackgroundColor(activity.getResources().getColor(R.color.deep_orange_200)); - } - else { - card.setCardBackgroundColor(activity.getResources().getColor(R.color.blue_grey_200)); - } - } else { - if (type == PasswordItem.TYPE_CATEGORY) { - card.setCardBackgroundColor(activity.getResources().getColor(R.color.deep_orange_400)); - } - else { - card.setCardBackgroundColor(activity.getResources().getColor(R.color.blue_grey_400)); - } } } |