mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-04-20 05:49:13 +00:00
Abstract away otp refreshing
This commit is contained in:
parent
f09d227378
commit
754a42b2c0
4 changed files with 13 additions and 32 deletions
|
@ -67,15 +67,7 @@ public class AddProfileActivity extends AppCompatActivity {
|
|||
_textIssuer.setText(info.getIssuer());
|
||||
_textPeriod.setText(info.getPeriod() + " seconds");
|
||||
|
||||
String otp;
|
||||
try {
|
||||
otp = OTP.generateOTP(info);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
_keyProfile.setCode(otp);
|
||||
String otp = _keyProfile.refreshCode();
|
||||
_textOtp.setText(otp.substring(0, 3) + " " + otp.substring(3));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
package me.impy.aegis;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.UndeclaredThrowableException;
|
||||
|
||||
import me.impy.aegis.crypto.otp.OTP;
|
||||
import me.impy.aegis.db.DatabaseEntry;
|
||||
|
||||
public class KeyProfile implements Serializable {
|
||||
|
@ -19,7 +21,12 @@ public class KeyProfile implements Serializable {
|
|||
return _code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
_code = code;
|
||||
public String refreshCode() {
|
||||
try {
|
||||
_code = OTP.generateOTP(_entry.getInfo());
|
||||
} catch (Exception e) {
|
||||
throw new UndeclaredThrowableException(e);
|
||||
}
|
||||
return _code;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,13 +16,11 @@ import android.widget.TextView;
|
|||
import com.amulyakhare.textdrawable.TextDrawable;
|
||||
import com.amulyakhare.textdrawable.util.ColorGenerator;
|
||||
|
||||
import java.lang.reflect.UndeclaredThrowableException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import me.impy.aegis.crypto.otp.OTP;
|
||||
import me.impy.aegis.helpers.ItemTouchHelperAdapter;
|
||||
|
||||
public class KeyProfileAdapter extends RecyclerView.Adapter<KeyProfileAdapter.KeyProfileHolder> implements ItemTouchHelperAdapter {
|
||||
|
@ -146,14 +144,7 @@ public class KeyProfileAdapter extends RecyclerView.Adapter<KeyProfileAdapter.Ke
|
|||
if (_keyProfile == null) {
|
||||
return;
|
||||
}
|
||||
String otp = "";
|
||||
try {
|
||||
otp = OTP.generateOTP(_keyProfile.getEntry().getInfo());
|
||||
} catch (Exception e) {
|
||||
throw new UndeclaredThrowableException(e);
|
||||
}
|
||||
|
||||
_keyProfile.setCode(otp);
|
||||
String otp = _keyProfile.refreshCode();
|
||||
_profileCode.setText(otp.substring(0, 3) + " " + otp.substring(3));
|
||||
|
||||
long millisTillRotation = _keyProfile.getEntry().getInfo().getMillisTillNextRotation();
|
||||
|
|
|
@ -36,7 +36,6 @@ import java.util.Comparator;
|
|||
import java.util.Objects;
|
||||
|
||||
import me.impy.aegis.crypto.MasterKey;
|
||||
import me.impy.aegis.crypto.otp.OTP;
|
||||
import me.impy.aegis.db.DatabaseEntry;
|
||||
import me.impy.aegis.db.DatabaseManager;
|
||||
import me.impy.aegis.ext.FreeOTPImporter;
|
||||
|
@ -214,19 +213,11 @@ public class MainActivity extends AppCompatActivity {
|
|||
}
|
||||
|
||||
private void addKey(KeyProfile profile) {
|
||||
profile.refreshCode();
|
||||
|
||||
DatabaseEntry entry = profile.getEntry();
|
||||
|
||||
String otp;
|
||||
try {
|
||||
otp = OTP.generateOTP(entry.getInfo());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
entry.setName(entry.getInfo().getAccountName());
|
||||
entry.setOrder(_keyProfiles.size() + 1);
|
||||
profile.setCode(otp);
|
||||
try {
|
||||
_db.addKey(entry);
|
||||
} catch (Exception e) {
|
||||
|
|
Loading…
Add table
Reference in a new issue