mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-04-20 22:09:12 +00:00
Merge pull request #189 from alexbakker/entry-defaults
Set a default value for period and digits for new entries
This commit is contained in:
commit
189698dddb
3 changed files with 71 additions and 58 deletions
|
@ -5,6 +5,7 @@ import com.beemdevelopment.aegis.encoding.Base64Exception;
|
||||||
import com.beemdevelopment.aegis.otp.GoogleAuthInfo;
|
import com.beemdevelopment.aegis.otp.GoogleAuthInfo;
|
||||||
import com.beemdevelopment.aegis.otp.OtpInfo;
|
import com.beemdevelopment.aegis.otp.OtpInfo;
|
||||||
import com.beemdevelopment.aegis.otp.OtpInfoException;
|
import com.beemdevelopment.aegis.otp.OtpInfoException;
|
||||||
|
import com.beemdevelopment.aegis.otp.TotpInfo;
|
||||||
import com.beemdevelopment.aegis.util.UUIDMap;
|
import com.beemdevelopment.aegis.util.UUIDMap;
|
||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
|
@ -133,11 +134,34 @@ public class DatabaseEntry extends UUIDMap.Value {
|
||||||
}
|
}
|
||||||
|
|
||||||
DatabaseEntry entry = (DatabaseEntry) o;
|
DatabaseEntry entry = (DatabaseEntry) o;
|
||||||
return super.equals(entry)
|
return super.equals(entry) && equivalates(entry);
|
||||||
&& getName().equals(entry.getName())
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reports whether this entry is equivalent to the given entry. The UUIDs of these
|
||||||
|
* entries are ignored during the comparison, so they are not necessarily the same
|
||||||
|
* instance.
|
||||||
|
*/
|
||||||
|
public boolean equivalates(DatabaseEntry entry) {
|
||||||
|
return getName().equals(entry.getName())
|
||||||
&& getIssuer().equals(entry.getIssuer())
|
&& getIssuer().equals(entry.getIssuer())
|
||||||
&& Objects.equals(getGroup(), entry.getGroup())
|
&& Objects.equals(getGroup(), entry.getGroup())
|
||||||
&& getInfo().equals(entry.getInfo())
|
&& getInfo().equals(entry.getInfo())
|
||||||
&& Arrays.equals(getIcon(), entry.getIcon());
|
&& Arrays.equals(getIcon(), entry.getIcon());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reports whether this entry has its values set to the defaults.
|
||||||
|
*/
|
||||||
|
public boolean isDefault() {
|
||||||
|
return equivalates(getDefault());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DatabaseEntry getDefault() {
|
||||||
|
try {
|
||||||
|
return new DatabaseEntry(new TotpInfo(null));
|
||||||
|
} catch (OtpInfoException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -133,51 +133,49 @@ public class EditEntryActivity extends AegisActivity {
|
||||||
_advancedSettings = findViewById(R.id.expandableLayout);
|
_advancedSettings = findViewById(R.id.expandableLayout);
|
||||||
|
|
||||||
// fill the fields with values if possible
|
// fill the fields with values if possible
|
||||||
if (_origEntry != null) {
|
if (_origEntry.hasIcon()) {
|
||||||
if (_origEntry.hasIcon()) {
|
Glide.with(this)
|
||||||
Glide.with(this)
|
.asDrawable()
|
||||||
.asDrawable()
|
.load(_origEntry)
|
||||||
.load(_origEntry)
|
.diskCacheStrategy(DiskCacheStrategy.NONE)
|
||||||
.diskCacheStrategy(DiskCacheStrategy.NONE)
|
.skipMemoryCache(false)
|
||||||
.skipMemoryCache(false)
|
.into(_iconView);
|
||||||
.into(_iconView);
|
_hasCustomIcon = true;
|
||||||
_hasCustomIcon = true;
|
} else {
|
||||||
} else {
|
TextDrawable drawable = TextDrawableHelper.generate(_origEntry.getIssuer(), _origEntry.getName(), _iconView);
|
||||||
TextDrawable drawable = TextDrawableHelper.generate(_origEntry.getIssuer(), _origEntry.getName(), _iconView);
|
_iconView.setImageDrawable(drawable);
|
||||||
_iconView.setImageDrawable(drawable);
|
|
||||||
}
|
|
||||||
|
|
||||||
_textName.setText(_origEntry.getName());
|
|
||||||
_textIssuer.setText(_origEntry.getIssuer());
|
|
||||||
|
|
||||||
OtpInfo info = _origEntry.getInfo();
|
|
||||||
if (info instanceof TotpInfo) {
|
|
||||||
_textPeriod.setText(Integer.toString(((TotpInfo) info).getPeriod()));
|
|
||||||
_rowPeriod.setVisibility(View.VISIBLE);
|
|
||||||
} else if (info instanceof HotpInfo) {
|
|
||||||
_textCounter.setText(Long.toString(((HotpInfo) info).getCounter()));
|
|
||||||
_rowCounter.setVisibility(View.VISIBLE);
|
|
||||||
} else {
|
|
||||||
throw new RuntimeException();
|
|
||||||
}
|
|
||||||
_textDigits.setText(Integer.toString(info.getDigits()));
|
|
||||||
|
|
||||||
byte[] secretBytes = _origEntry.getInfo().getSecret();
|
|
||||||
if (secretBytes != null) {
|
|
||||||
char[] secretChars = Base32.encode(secretBytes);
|
|
||||||
_textSecret.setText(secretChars, 0, secretChars.length);
|
|
||||||
}
|
|
||||||
|
|
||||||
String type = _origEntry.getInfo().getType();
|
|
||||||
_spinnerType.setSelection(getStringResourceIndex(R.array.otp_types_array, type), false);
|
|
||||||
|
|
||||||
String algo = _origEntry.getInfo().getAlgorithm(false);
|
|
||||||
_spinnerAlgo.setSelection(getStringResourceIndex(R.array.otp_algo_array, algo), false);
|
|
||||||
|
|
||||||
String group = _origEntry.getGroup();
|
|
||||||
setGroup(group);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_textName.setText(_origEntry.getName());
|
||||||
|
_textIssuer.setText(_origEntry.getIssuer());
|
||||||
|
|
||||||
|
OtpInfo info = _origEntry.getInfo();
|
||||||
|
if (info instanceof TotpInfo) {
|
||||||
|
_textPeriod.setText(Integer.toString(((TotpInfo) info).getPeriod()));
|
||||||
|
_rowPeriod.setVisibility(View.VISIBLE);
|
||||||
|
} else if (info instanceof HotpInfo) {
|
||||||
|
_textCounter.setText(Long.toString(((HotpInfo) info).getCounter()));
|
||||||
|
_rowCounter.setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
throw new RuntimeException();
|
||||||
|
}
|
||||||
|
_textDigits.setText(Integer.toString(info.getDigits()));
|
||||||
|
|
||||||
|
byte[] secretBytes = _origEntry.getInfo().getSecret();
|
||||||
|
if (secretBytes != null) {
|
||||||
|
char[] secretChars = Base32.encode(secretBytes);
|
||||||
|
_textSecret.setText(secretChars, 0, secretChars.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
String type = _origEntry.getInfo().getType();
|
||||||
|
_spinnerType.setSelection(getStringResourceIndex(R.array.otp_types_array, type), false);
|
||||||
|
|
||||||
|
String algo = _origEntry.getInfo().getAlgorithm(false);
|
||||||
|
_spinnerAlgo.setSelection(getStringResourceIndex(R.array.otp_algo_array, algo), false);
|
||||||
|
|
||||||
|
String group = _origEntry.getGroup();
|
||||||
|
setGroup(group);
|
||||||
|
|
||||||
// update the icon if the text changed
|
// update the icon if the text changed
|
||||||
_textIssuer.addTextChangedListener(_iconChangeListener);
|
_textIssuer.addTextChangedListener(_iconChangeListener);
|
||||||
_textName.addTextChangedListener(_iconChangeListener);
|
_textName.addTextChangedListener(_iconChangeListener);
|
||||||
|
@ -331,7 +329,7 @@ public class EditEntryActivity extends AegisActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
// close the activity if the entry has not been changed
|
// close the activity if the entry has not been changed
|
||||||
if (_origEntry != null && !_hasChangedIcon && _origEntry.equals(entry.get())) {
|
if (!_hasChangedIcon && _origEntry.equals(entry.get())) {
|
||||||
super.onBackPressed();
|
super.onBackPressed();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -465,7 +463,6 @@ public class EditEntryActivity extends AegisActivity {
|
||||||
throw new ParseException("Secret is not valid base32.");
|
throw new ParseException("Secret is not valid base32.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// set otp info
|
|
||||||
OtpInfo info;
|
OtpInfo info;
|
||||||
try {
|
try {
|
||||||
switch (type.toLowerCase()) {
|
switch (type.toLowerCase()) {
|
||||||
|
@ -494,14 +491,8 @@ public class EditEntryActivity extends AegisActivity {
|
||||||
throw new ParseException("The entered info is incorrect: " + e.getMessage());
|
throw new ParseException("The entered info is incorrect: " + e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
// set database entry info
|
DatabaseEntry entry = Cloner.clone(_origEntry);
|
||||||
DatabaseEntry entry;
|
entry.setInfo(info);
|
||||||
if (_origEntry == null) {
|
|
||||||
entry = new DatabaseEntry(info);
|
|
||||||
} else {
|
|
||||||
entry = Cloner.clone(_origEntry);
|
|
||||||
entry.setInfo(info);
|
|
||||||
}
|
|
||||||
entry.setIssuer(_textIssuer.getText().toString());
|
entry.setIssuer(_textIssuer.getText().toString());
|
||||||
entry.setName(_textName.getText().toString());
|
entry.setName(_textName.getText().toString());
|
||||||
|
|
||||||
|
|
|
@ -227,9 +227,7 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
|
||||||
|
|
||||||
private void startEditProfileActivity(int requestCode, DatabaseEntry entry, boolean isNew) {
|
private void startEditProfileActivity(int requestCode, DatabaseEntry entry, boolean isNew) {
|
||||||
Intent intent = new Intent(this, EditEntryActivity.class);
|
Intent intent = new Intent(this, EditEntryActivity.class);
|
||||||
if (entry != null) {
|
intent.putExtra("entry", entry != null ? entry : DatabaseEntry.getDefault());
|
||||||
intent.putExtra("entry", entry);
|
|
||||||
}
|
|
||||||
intent.putExtra("isNew", isNew);
|
intent.putExtra("isNew", isNew);
|
||||||
intent.putExtra("selectedGroup", _selectedGroup);
|
intent.putExtra("selectedGroup", _selectedGroup);
|
||||||
intent.putExtra("groups", new ArrayList<>(_db.getGroups()));
|
intent.putExtra("groups", new ArrayList<>(_db.getGroups()));
|
||||||
|
|
Loading…
Add table
Reference in a new issue