Merge pull request #687 from mavit/fuzzy-issuer

Use an thumbnail if its name appears as a word in the TOTP issuer field
This commit is contained in:
Jakob Nixdorf 2021-03-04 06:27:31 +01:00 committed by GitHub
commit b5f5492249
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View file

@ -493,9 +493,13 @@ public class Entry {
try {
this.thumbnail = EntryThumbnail.EntryThumbnails.valueOfIgnoreCase(issuer);
} catch(Exception e) {
try {
this.thumbnail = EntryThumbnail.EntryThumbnails.valueOfFuzzy(issuer);
} catch(Exception e2) {
this.thumbnail = EntryThumbnail.EntryThumbnails.Default;
}
}
}
@Override
public boolean equals(Object o) {

View file

@ -23,6 +23,8 @@
package org.shadowice.flocke.andotp.Utilities;
import java.util.regex.Pattern;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
@ -398,6 +400,15 @@ public class EntryThumbnail {
throw new IllegalArgumentException();
}
public static EntryThumbnails valueOfFuzzy(String thumbnail) {
for (EntryThumbnails entryThumbnails : values()) {
Pattern re = Pattern.compile("\\b" + Pattern.quote(entryThumbnails.name()) + "\\b", Pattern.CASE_INSENSITIVE);
if (re.matcher(thumbnail).find())
return entryThumbnails;
}
throw new IllegalArgumentException();
}
public int getResource() {
return resource;
}