Aegis/app/src/main/java/me/impy/aegis/KeyProfile.java

48 lines
1.2 KiB
Java
Raw Normal View History

package me.impy.aegis;
import com.amulyakhare.textdrawable.TextDrawable;
import com.amulyakhare.textdrawable.util.ColorGenerator;
import java.io.Serializable;
2017-11-26 19:50:05 +01:00
import java.lang.reflect.UndeclaredThrowableException;
2017-11-26 19:50:05 +01:00
import me.impy.aegis.crypto.otp.OTP;
2017-08-26 21:15:53 +02:00
import me.impy.aegis.db.DatabaseEntry;
public class KeyProfile implements Serializable {
2017-08-26 21:15:53 +02:00
private String _code;
private DatabaseEntry _entry;
2017-08-26 21:15:53 +02:00
public KeyProfile(DatabaseEntry entry) {
_entry = entry;
}
public DatabaseEntry getEntry() {
return _entry;
}
public String getCode() {
return _code;
}
2017-11-26 19:50:05 +01:00
public String refreshCode() {
try {
_code = OTP.generateOTP(_entry.getInfo());
} catch (Exception e) {
throw new UndeclaredThrowableException(e);
}
return _code;
}
public TextDrawable getDrawable() {
String name = _entry.getName();
if (name == null) {
return null;
}
ColorGenerator generator = ColorGenerator.MATERIAL;
int color = generator.getColor(name);
return TextDrawable.builder().buildRound(name.substring(0, 1).toUpperCase(), color);
}
}