mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-05-15 06:22:49 +00:00
Generate TextDrawable based on issuer and use account name as fallback
This commit is contained in:
parent
4a4ab1a82c
commit
3aba0f3f47
3 changed files with 28 additions and 22 deletions
|
@ -8,13 +8,16 @@ public class TextDrawableHelper {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TextDrawable generate(String s) {
|
public static TextDrawable generate(String text, String fallback) {
|
||||||
if (s == null || s.length() <= 1) {
|
if (text == null || text.isEmpty()) {
|
||||||
|
if (fallback == null || fallback.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
text = fallback;
|
||||||
|
}
|
||||||
|
|
||||||
ColorGenerator generator = ColorGenerator.MATERIAL;
|
ColorGenerator generator = ColorGenerator.MATERIAL;
|
||||||
int color = generator.getColor(s);
|
int color = generator.getColor(text);
|
||||||
return TextDrawable.builder().buildRound(s.substring(0, 1).toUpperCase(), color);
|
return TextDrawable.builder().buildRound(text.substring(0, 1).toUpperCase(), color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,7 +97,7 @@ public class EditEntryActivity extends AegisActivity {
|
||||||
|
|
||||||
// fill the fields with values if possible
|
// fill the fields with values if possible
|
||||||
if (_entry != null) {
|
if (_entry != null) {
|
||||||
TextDrawable drawable = TextDrawableHelper.generate(_entry.getName());
|
TextDrawable drawable = TextDrawableHelper.generate(_entry.getIssuer(), _entry.getName());
|
||||||
_iconView.setImageDrawable(drawable);
|
_iconView.setImageDrawable(drawable);
|
||||||
|
|
||||||
_textName.setText(_entry.getName());
|
_textName.setText(_entry.getName());
|
||||||
|
@ -142,21 +142,8 @@ public class EditEntryActivity extends AegisActivity {
|
||||||
_spinnerDigits.setOnItemSelectedListener(_selectedListener);
|
_spinnerDigits.setOnItemSelectedListener(_selectedListener);
|
||||||
|
|
||||||
// update the icon if the text changed
|
// update the icon if the text changed
|
||||||
_textName.addTextChangedListener(new TextWatcher() {
|
_textIssuer.addTextChangedListener(_iconChangeListener);
|
||||||
@Override
|
_textName.addTextChangedListener(_iconChangeListener);
|
||||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void afterTextChanged(Editable s) {
|
|
||||||
TextDrawable drawable = TextDrawableHelper.generate(s.toString());
|
|
||||||
_iconView.setImageDrawable(drawable);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// show/hide period and counter fields on type change
|
// show/hide period and counter fields on type change
|
||||||
_spinnerType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
_spinnerType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||||
|
@ -406,6 +393,22 @@ public class EditEntryActivity extends AegisActivity {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private TextWatcher _iconChangeListener = new TextWatcher() {
|
||||||
|
@Override
|
||||||
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterTextChanged(Editable s) {
|
||||||
|
TextDrawable drawable = TextDrawableHelper.generate(_textIssuer.getText().toString(), _textName.getText().toString());
|
||||||
|
_iconView.setImageDrawable(drawable);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
private class SpinnerItemSelectedListener implements AdapterView.OnItemSelectedListener, View.OnTouchListener {
|
private class SpinnerItemSelectedListener implements AdapterView.OnItemSelectedListener, View.OnTouchListener {
|
||||||
private boolean _userSelect = false;
|
private boolean _userSelect = false;
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,7 @@ public class EntryHolder extends RecyclerView.ViewHolder {
|
||||||
_profileIssuer.setText(" - " + entry.getIssuer());
|
_profileIssuer.setText(" - " + entry.getIssuer());
|
||||||
}
|
}
|
||||||
|
|
||||||
TextDrawable drawable = TextDrawableHelper.generate(entry.getName());
|
TextDrawable drawable = TextDrawableHelper.generate(entry.getIssuer(), entry.getName());
|
||||||
_profileDrawable.setImageDrawable(drawable);
|
_profileDrawable.setImageDrawable(drawable);
|
||||||
|
|
||||||
refreshCode();
|
refreshCode();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue