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,7 +493,11 @@ public class Entry {
try { try {
this.thumbnail = EntryThumbnail.EntryThumbnails.valueOfIgnoreCase(issuer); this.thumbnail = EntryThumbnail.EntryThumbnails.valueOfIgnoreCase(issuer);
} catch(Exception e) { } catch(Exception e) {
this.thumbnail = EntryThumbnail.EntryThumbnails.Default; try {
this.thumbnail = EntryThumbnail.EntryThumbnails.valueOfFuzzy(issuer);
} catch(Exception e2) {
this.thumbnail = EntryThumbnail.EntryThumbnails.Default;
}
} }
} }

View file

@ -23,6 +23,8 @@
package org.shadowice.flocke.andotp.Utilities; package org.shadowice.flocke.andotp.Utilities;
import java.util.regex.Pattern;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
@ -398,6 +400,15 @@ public class EntryThumbnail {
throw new IllegalArgumentException(); 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() { public int getResource() {
return resource; return resource;
} }