mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-04-21 06:19: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.OtpInfo;
|
||||
import com.beemdevelopment.aegis.otp.OtpInfoException;
|
||||
import com.beemdevelopment.aegis.otp.TotpInfo;
|
||||
import com.beemdevelopment.aegis.util.UUIDMap;
|
||||
|
||||
import org.json.JSONException;
|
||||
|
@ -133,11 +134,34 @@ public class DatabaseEntry extends UUIDMap.Value {
|
|||
}
|
||||
|
||||
DatabaseEntry entry = (DatabaseEntry) o;
|
||||
return super.equals(entry)
|
||||
&& getName().equals(entry.getName())
|
||||
return super.equals(entry) && equivalates(entry);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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())
|
||||
&& Objects.equals(getGroup(), entry.getGroup())
|
||||
&& getInfo().equals(entry.getInfo())
|
||||
&& 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);
|
||||
|
||||
// fill the fields with values if possible
|
||||
if (_origEntry != null) {
|
||||
if (_origEntry.hasIcon()) {
|
||||
Glide.with(this)
|
||||
.asDrawable()
|
||||
|
@ -176,7 +175,6 @@ public class EditEntryActivity extends AegisActivity {
|
|||
|
||||
String group = _origEntry.getGroup();
|
||||
setGroup(group);
|
||||
}
|
||||
|
||||
// update the icon if the text changed
|
||||
_textIssuer.addTextChangedListener(_iconChangeListener);
|
||||
|
@ -331,7 +329,7 @@ public class EditEntryActivity extends AegisActivity {
|
|||
}
|
||||
|
||||
// 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();
|
||||
return;
|
||||
}
|
||||
|
@ -465,7 +463,6 @@ public class EditEntryActivity extends AegisActivity {
|
|||
throw new ParseException("Secret is not valid base32.");
|
||||
}
|
||||
|
||||
// set otp info
|
||||
OtpInfo info;
|
||||
try {
|
||||
switch (type.toLowerCase()) {
|
||||
|
@ -494,14 +491,8 @@ public class EditEntryActivity extends AegisActivity {
|
|||
throw new ParseException("The entered info is incorrect: " + e.getMessage());
|
||||
}
|
||||
|
||||
// set database entry info
|
||||
DatabaseEntry entry;
|
||||
if (_origEntry == null) {
|
||||
entry = new DatabaseEntry(info);
|
||||
} else {
|
||||
entry = Cloner.clone(_origEntry);
|
||||
DatabaseEntry entry = Cloner.clone(_origEntry);
|
||||
entry.setInfo(info);
|
||||
}
|
||||
entry.setIssuer(_textIssuer.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) {
|
||||
Intent intent = new Intent(this, EditEntryActivity.class);
|
||||
if (entry != null) {
|
||||
intent.putExtra("entry", entry);
|
||||
}
|
||||
intent.putExtra("entry", entry != null ? entry : DatabaseEntry.getDefault());
|
||||
intent.putExtra("isNew", isNew);
|
||||
intent.putExtra("selectedGroup", _selectedGroup);
|
||||
intent.putExtra("groups", new ArrayList<>(_db.getGroups()));
|
||||
|
|
Loading…
Add table
Reference in a new issue