2016-08-16 20:04:38 +02:00
|
|
|
package me.impy.aegis;
|
|
|
|
|
2017-12-27 22:04:22 +01:00
|
|
|
import com.amulyakhare.textdrawable.TextDrawable;
|
|
|
|
import com.amulyakhare.textdrawable.util.ColorGenerator;
|
|
|
|
|
2016-08-16 20:04:38 +02:00
|
|
|
import java.io.Serializable;
|
2017-11-26 19:50:05 +01:00
|
|
|
import java.lang.reflect.UndeclaredThrowableException;
|
2016-08-16 20:04:38 +02:00
|
|
|
|
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;
|
2016-08-16 20:04:38 +02:00
|
|
|
|
|
|
|
public class KeyProfile implements Serializable {
|
2017-08-26 21:15:53 +02:00
|
|
|
private String _code;
|
|
|
|
private DatabaseEntry _entry;
|
2016-10-25 23:53:33 +02:00
|
|
|
|
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;
|
2016-10-25 23:53:33 +02:00
|
|
|
}
|
2017-12-27 22:04:22 +01:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2016-08-16 20:04:38 +02:00
|
|
|
}
|