mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-05-14 14:02:49 +00:00
Added way to remove custom images
This commit is contained in:
parent
97eb3490d8
commit
f9e716391c
5 changed files with 52 additions and 10 deletions
|
@ -184,12 +184,17 @@ public class KeyInfo implements Serializable {
|
||||||
|
|
||||||
public void setImage(byte[] image)
|
public void setImage(byte[] image)
|
||||||
{
|
{
|
||||||
_image = Base64.encodeToString(image, Base64.DEFAULT);
|
if(image != null && !image.equals(""))
|
||||||
|
{
|
||||||
|
_image = Base64.encodeToString(image, Base64.DEFAULT);
|
||||||
|
} else {
|
||||||
|
_image = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] getImage()
|
public byte[] getImage()
|
||||||
{
|
{
|
||||||
return Base64.decode(_image, Base64.DEFAULT);
|
return _image != null ? Base64.decode(_image, Base64.DEFAULT) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSecret(byte[] secret) {
|
public void setSecret(byte[] secret) {
|
||||||
|
|
|
@ -49,6 +49,8 @@ import me.impy.aegis.ui.views.KeyProfile;
|
||||||
public class EditProfileActivity extends AegisActivity {
|
public class EditProfileActivity extends AegisActivity {
|
||||||
private boolean _isNew = false;
|
private boolean _isNew = false;
|
||||||
private boolean _edited = false;
|
private boolean _edited = false;
|
||||||
|
private boolean _hasCustomImage = false;
|
||||||
|
|
||||||
private KeyProfile _profile;
|
private KeyProfile _profile;
|
||||||
|
|
||||||
private CircleImageView _iconView;
|
private CircleImageView _iconView;
|
||||||
|
@ -131,8 +133,11 @@ public class EditProfileActivity extends AegisActivity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterTextChanged(Editable s) {
|
public void afterTextChanged(Editable s) {
|
||||||
TextDrawable drawable = TextDrawableHelper.generate(s.toString(), _iconView);
|
if(!_hasCustomImage)
|
||||||
_iconView.setImageDrawable(drawable);
|
{
|
||||||
|
TextDrawable drawable = TextDrawableHelper.generate(s.toString(), _iconView);
|
||||||
|
_iconView.setImageDrawable(drawable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -166,7 +171,18 @@ public class EditProfileActivity extends AegisActivity {
|
||||||
|
|
||||||
private void updateFields() {
|
private void updateFields() {
|
||||||
DatabaseEntry entry = _profile.getEntry();
|
DatabaseEntry entry = _profile.getEntry();
|
||||||
_iconView.setImageDrawable(_profile.getDrawable(_iconView));
|
|
||||||
|
if (_profile.getEntry().getInfo().getImage() != null)
|
||||||
|
{
|
||||||
|
byte[] imageBytes = _profile.getEntry().getInfo().getImage();
|
||||||
|
Bitmap image = BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length);
|
||||||
|
_iconView.setImageBitmap(image);
|
||||||
|
_hasCustomImage = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_iconView.setImageDrawable(_profile.getDrawable(_iconView));
|
||||||
|
}
|
||||||
|
|
||||||
_textName.setText(entry.getName());
|
_textName.setText(entry.getName());
|
||||||
_textIssuer.setText(entry.getInfo().getIssuer());
|
_textIssuer.setText(entry.getInfo().getIssuer());
|
||||||
|
@ -270,6 +286,9 @@ public class EditProfileActivity extends AegisActivity {
|
||||||
finish(true);
|
finish(true);
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case R.id.action_default_image:
|
||||||
|
_iconView.setImageDrawable(_profile.getDrawable(_iconView));
|
||||||
|
_hasCustomImage = false;
|
||||||
default:
|
default:
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
@ -283,6 +302,10 @@ public class EditProfileActivity extends AegisActivity {
|
||||||
if (_isNew) {
|
if (_isNew) {
|
||||||
menu.findItem(R.id.action_delete).setVisible(false);
|
menu.findItem(R.id.action_delete).setVisible(false);
|
||||||
}
|
}
|
||||||
|
if (!_hasCustomImage) {
|
||||||
|
menu.findItem(R.id.action_default_image).setVisible(false);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -309,6 +332,7 @@ public class EditProfileActivity extends AegisActivity {
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
_iconView.setImageBitmap(_kropView.getCroppedBitmap());
|
_iconView.setImageBitmap(_kropView.getCroppedBitmap());
|
||||||
_kropView.setVisibility(View.GONE);
|
_kropView.setVisibility(View.GONE);
|
||||||
|
_hasCustomImage = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -355,11 +379,18 @@ public class EditProfileActivity extends AegisActivity {
|
||||||
info.setType(type);
|
info.setType(type);
|
||||||
info.setAccountName(_textName.getText().toString());
|
info.setAccountName(_textName.getText().toString());
|
||||||
|
|
||||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
if(_hasCustomImage)
|
||||||
drawableToBitmap(_iconView.getDrawable()).compress(Bitmap.CompressFormat.JPEG, 100, stream);
|
{
|
||||||
byte[] bitmapdata = stream.toByteArray();
|
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||||
|
drawableToBitmap(_iconView.getDrawable()).compress(Bitmap.CompressFormat.JPEG, 100, stream);
|
||||||
|
byte[] bitmapdata = stream.toByteArray();
|
||||||
|
|
||||||
info.setImage(bitmapdata);
|
info.setImage(bitmapdata);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
info.setImage(null);
|
||||||
|
}
|
||||||
} catch (KeyInfoException e) {
|
} catch (KeyInfoException e) {
|
||||||
onError("The entered info is incorrect: " + e.getMessage());
|
onError("The entered info is incorrect: " + e.getMessage());
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -65,7 +65,7 @@ public class KeyProfileHolder extends RecyclerView.ViewHolder {
|
||||||
_profileIssuer.setText(" - " + profile.getEntry().getInfo().getIssuer());
|
_profileIssuer.setText(" - " + profile.getEntry().getInfo().getIssuer());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (profile.getEntry().getInfo().getImage() != null)
|
if (profile.getEntry().getInfo().getImage() != null && !profile.getEntry().getInfo().getImage().equals(""))
|
||||||
{
|
{
|
||||||
byte[] imageBytes = profile.getEntry().getInfo().getImage();
|
byte[] imageBytes = profile.getEntry().getInfo().getImage();
|
||||||
Bitmap image = BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length);
|
Bitmap image = BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length);
|
||||||
|
|
|
@ -11,4 +11,9 @@
|
||||||
android:id="@+id/action_delete"
|
android:id="@+id/action_delete"
|
||||||
android:title="@string/action_delete"
|
android:title="@string/action_delete"
|
||||||
app:showAsAction="never"/>
|
app:showAsAction="never"/>
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_default_image"
|
||||||
|
android:title="@string/action_default_image"
|
||||||
|
app:showAsAction="never"/>
|
||||||
</menu>
|
</menu>
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
<string name="action_settings">Settings</string>
|
<string name="action_settings">Settings</string>
|
||||||
<string name="action_import">Import</string>
|
<string name="action_import">Import</string>
|
||||||
<string name="action_delete">Delete</string>
|
<string name="action_delete">Delete</string>
|
||||||
|
<string name="action_default_image">Set default image</string>
|
||||||
<string name="discard">Discard</string>
|
<string name="discard">Discard</string>
|
||||||
<string name="save">Save</string>
|
<string name="save">Save</string>
|
||||||
<string name="title_activity_intro">IntroActivity</string>
|
<string name="title_activity_intro">IntroActivity</string>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue