Move update functions into the EntryViewHolder

This commit is contained in:
Jakob Nixdorf 2017-07-30 22:13:51 +02:00
parent 0e0d6d56bf
commit 09126ee1c0
No known key found for this signature in database
GPG key ID: BE99BF86574A7DBC

View file

@ -65,7 +65,6 @@ public class EntriesCardAdapter extends RecyclerView.Adapter<EntriesCardAdapter.
public EntriesCardAdapter(Context context) { public EntriesCardAdapter(Context context) {
this.context = context; this.context = context;
this.sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); this.sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
loadEntries(); loadEntries();
@ -133,15 +132,12 @@ public class EntriesCardAdapter extends RecyclerView.Adapter<EntriesCardAdapter.
public void onBindViewHolder(EntryViewHolder entryViewHolder, int i) { public void onBindViewHolder(EntryViewHolder entryViewHolder, int i) {
Entry entry = entries.get(displayedEntries.get(i)); Entry entry = entries.get(displayedEntries.get(i));
entryViewHolder.OTPValue.setText(entry.getCurrentOTP()); entryViewHolder.updateValues(entry.getLabel(), entry.getCurrentOTP());
entryViewHolder.OTPLabel.setText(entry.getLabel());
entryViewHolder.eventCallback = viewHolderEventCallback;
if (entry.hasNonDefaultPeriod()) { if (entry.hasNonDefaultPeriod()) {
entryViewHolder.customPeriodLayout.setVisibility(View.VISIBLE); entryViewHolder.showCustomPeriod(entry.getPeriod());
entryViewHolder.customPeriod.setText(String.format(context.getString(R.string.format_custom_period), entry.getPeriod()));
} else { } else {
entryViewHolder.customPeriodLayout.setVisibility(View.GONE); entryViewHolder.hideCustomPeriod();
} }
if (sharedPrefs.getBoolean(context.getString(R.string.settings_key_tap_to_reveal), false)) { if (sharedPrefs.getBoolean(context.getString(R.string.settings_key_tap_to_reveal), false)) {
@ -151,14 +147,17 @@ public class EntriesCardAdapter extends RecyclerView.Adapter<EntriesCardAdapter.
} }
int fontSize = sharedPrefs.getInt(context.getString(R.string.settings_key_label_size), context.getResources().getInteger(R.integer.settings_default_label_size)); int fontSize = sharedPrefs.getInt(context.getString(R.string.settings_key_label_size), context.getResources().getInteger(R.integer.settings_default_label_size));
entryViewHolder.OTPLabel.setTextSize(TypedValue.COMPLEX_UNIT_PT, fontSize); entryViewHolder.setLabelSize(fontSize);
} }
@Override @Override
public EntryViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { public EntryViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View itemView = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.component_card, viewGroup, false); View itemView = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.component_card, viewGroup, false);
return new EntryViewHolder(itemView); EntryViewHolder viewHolder = new EntryViewHolder(itemView);
viewHolder.eventCallback = viewHolderEventCallback;
return viewHolder;
} }
@Override @Override
@ -307,14 +306,14 @@ public class EntriesCardAdapter extends RecyclerView.Adapter<EntriesCardAdapter.
private ViewHolderEventCallback eventCallback; private ViewHolderEventCallback eventCallback;
protected CardView card; private CardView card;
protected TextView OTPValue; private TextView OTPValue;
protected TextView OTPValueCover; private TextView OTPValueCover;
protected TextView OTPLabel; private TextView OTPLabel;
protected LinearLayout customPeriodLayout; private LinearLayout customPeriodLayout;
protected TextView customPeriod; private TextView customPeriod;
protected ImageButton menuButton; private ImageButton menuButton;
protected ImageButton copyButton; private ImageButton copyButton;
public EntryViewHolder(final View v) { public EntryViewHolder(final View v) {
super(v); super(v);
@ -343,6 +342,24 @@ public class EntriesCardAdapter extends RecyclerView.Adapter<EntriesCardAdapter.
}); });
} }
public void updateValues(String label, String token) {
OTPLabel.setText(label);
OTPValue.setText(token);
}
public void showCustomPeriod(int period) {
customPeriodLayout.setVisibility(View.VISIBLE);
customPeriod.setText(String.format(context.getString(R.string.format_custom_period), period));
}
public void hideCustomPeriod() {
customPeriodLayout.setVisibility(View.GONE);
}
public void setLabelSize(int size) {
OTPLabel.setTextSize(TypedValue.COMPLEX_UNIT_PT, size);
}
public void enableTapToReveal() { public void enableTapToReveal() {
OTPValue.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_visibility_visible, 0, 0, 0); OTPValue.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_visibility_visible, 0, 0, 0);
OTPValue.setVisibility(View.GONE); OTPValue.setVisibility(View.GONE);