mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-06-08 23:57:45 +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,7 +133,6 @@ 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()
|
||||||
|
@ -176,7 +175,6 @@ public class EditEntryActivity extends AegisActivity {
|
||||||
|
|
||||||
String group = _origEntry.getGroup();
|
String group = _origEntry.getGroup();
|
||||||
setGroup(group);
|
setGroup(group);
|
||||||
}
|
|
||||||
|
|
||||||
// update the icon if the text changed
|
// update the icon if the text changed
|
||||||
_textIssuer.addTextChangedListener(_iconChangeListener);
|
_textIssuer.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;
|
|
||||||
if (_origEntry == null) {
|
|
||||||
entry = new DatabaseEntry(info);
|
|
||||||
} else {
|
|
||||||
entry = Cloner.clone(_origEntry);
|
|
||||||
entry.setInfo(info);
|
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
Add a link
Reference in a new issue