avoid repeated checks for custom typeface when there is none

This commit is contained in:
Helium314 2025-01-18 12:49:57 +01:00
parent 789b533358
commit cde1a70427

View file

@ -198,6 +198,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
// static cache for background images to avoid potentially slow reload on every settings reload // static cache for background images to avoid potentially slow reload on every settings reload
private final static Drawable[] sCachedBackgroundImages = new Drawable[4]; private final static Drawable[] sCachedBackgroundImages = new Drawable[4];
private static Typeface sCachedTypeface; private static Typeface sCachedTypeface;
private static boolean sCustomTypefaceLoaded; // to avoid repeatedly checking custom typeface file when there is no custom typeface
private Map<String, Integer> mCustomToolbarKeyCodes = null; private Map<String, Integer> mCustomToolbarKeyCodes = null;
private Map<String, Integer> mCustomToolbarLongpressCodes = null; private Map<String, Integer> mCustomToolbarLongpressCodes = null;
@ -738,15 +739,17 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
@Nullable @Nullable
public Typeface getCustomTypeface() { public Typeface getCustomTypeface() {
if (sCachedTypeface == null) { if (!sCustomTypefaceLoaded) {
try { try {
sCachedTypeface = Typeface.createFromFile(getCustomFontFile(mContext)); sCachedTypeface = Typeface.createFromFile(getCustomFontFile(mContext));
} catch (Exception e) { } } catch (Exception e) { }
} }
sCustomTypefaceLoaded = true;
return sCachedTypeface; return sCachedTypeface;
} }
public static void clearCachedTypeface() { public static void clearCachedTypeface() {
sCachedTypeface = null; sCachedTypeface = null;
sCustomTypefaceLoaded = false;
} }
} }