Added way to remove custom images

pull/41/head
Michael Schättgen 7 years ago
parent 97eb3490d8
commit f9e716391c

@ -184,12 +184,17 @@ public class KeyInfo implements Serializable {
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()
{
return Base64.decode(_image, Base64.DEFAULT);
return _image != null ? Base64.decode(_image, Base64.DEFAULT) : null;
}
public void setSecret(byte[] secret) {

@ -49,6 +49,8 @@ import me.impy.aegis.ui.views.KeyProfile;
public class EditProfileActivity extends AegisActivity {
private boolean _isNew = false;
private boolean _edited = false;
private boolean _hasCustomImage = false;
private KeyProfile _profile;
private CircleImageView _iconView;
@ -131,8 +133,11 @@ public class EditProfileActivity extends AegisActivity {
@Override
public void afterTextChanged(Editable s) {
TextDrawable drawable = TextDrawableHelper.generate(s.toString(), _iconView);
_iconView.setImageDrawable(drawable);
if(!_hasCustomImage)
{
TextDrawable drawable = TextDrawableHelper.generate(s.toString(), _iconView);
_iconView.setImageDrawable(drawable);
}
}
});
@ -166,7 +171,18 @@ public class EditProfileActivity extends AegisActivity {
private void updateFields() {
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());
_textIssuer.setText(entry.getInfo().getIssuer());
@ -270,6 +286,9 @@ public class EditProfileActivity extends AegisActivity {
finish(true);
});
break;
case R.id.action_default_image:
_iconView.setImageDrawable(_profile.getDrawable(_iconView));
_hasCustomImage = false;
default:
return super.onOptionsItemSelected(item);
}
@ -283,6 +302,10 @@ public class EditProfileActivity extends AegisActivity {
if (_isNew) {
menu.findItem(R.id.action_delete).setVisible(false);
}
if (!_hasCustomImage) {
menu.findItem(R.id.action_default_image).setVisible(false);
}
return true;
}
@ -309,6 +332,7 @@ public class EditProfileActivity extends AegisActivity {
public void onClick(View v) {
_iconView.setImageBitmap(_kropView.getCroppedBitmap());
_kropView.setVisibility(View.GONE);
_hasCustomImage = true;
}
});
}
@ -355,11 +379,18 @@ public class EditProfileActivity extends AegisActivity {
info.setType(type);
info.setAccountName(_textName.getText().toString());
ByteArrayOutputStream stream = new ByteArrayOutputStream();
drawableToBitmap(_iconView.getDrawable()).compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] bitmapdata = stream.toByteArray();
if(_hasCustomImage)
{
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) {
onError("The entered info is incorrect: " + e.getMessage());
return false;

@ -65,7 +65,7 @@ public class KeyProfileHolder extends RecyclerView.ViewHolder {
_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();
Bitmap image = BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length);

@ -11,4 +11,9 @@
android:id="@+id/action_delete"
android:title="@string/action_delete"
app:showAsAction="never"/>
<item
android:id="@+id/action_default_image"
android:title="@string/action_default_image"
app:showAsAction="never"/>
</menu>

@ -3,6 +3,7 @@
<string name="action_settings">Settings</string>
<string name="action_import">Import</string>
<string name="action_delete">Delete</string>
<string name="action_default_image">Set default image</string>
<string name="discard">Discard</string>
<string name="save">Save</string>
<string name="title_activity_intro">IntroActivity</string>

Loading…
Cancel
Save