Merge pull request #1831 from fiaxh/key_creation_flexible

Handle user input on key creation more generously
This commit is contained in:
Dominik Schürmann
2016-04-29 21:36:53 +02:00
7 changed files with 67 additions and 85 deletions

View File

@@ -78,18 +78,20 @@ public abstract class KeyRing {
}
/**
* Returns a composed user id. Returns null if name is null!
* Returns a composed user id. Returns null if name, email and comment are empty.
*/
public static String createUserId(UserId userId) {
String userIdString = userId.name; // consider name a required value
if (userIdString != null && !TextUtils.isEmpty(userId.comment)) {
userIdString += " (" + userId.comment + ")";
StringBuilder userIdBuilder = new StringBuilder();
if (!TextUtils.isEmpty(userId.name)) {
userIdBuilder.append(userId.comment);
}
if (userIdString != null && !TextUtils.isEmpty(userId.email)) {
userIdString += " <" + userId.email + ">";
if (!TextUtils.isEmpty(userId.comment)) {
userIdBuilder.append(" (" + userId.comment + ")");
}
return userIdString;
if (!TextUtils.isEmpty(userId.email)) {
userIdBuilder.append(" <" + userId.email + ">");
}
return userIdBuilder.length() == 0 ? null : userIdBuilder.toString();
}
public static class UserId implements Serializable {