From af3447419a361071c7d0719da3c2c5dcd9bc6e68 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Sat, 15 Jan 2022 12:03:18 +0800 Subject: Load custom fonts. --- .../ml/docilealligator/infinityforreddit/Infinity.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Infinity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Infinity.java index a1e966de..237f3fc7 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Infinity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Infinity.java @@ -34,6 +34,9 @@ import ml.docilealligator.infinityforreddit.broadcastreceivers.WallpaperChangeRe import ml.docilealligator.infinityforreddit.events.ChangeAppLockEvent; import ml.docilealligator.infinityforreddit.events.ChangeNetworkStatusEvent; import ml.docilealligator.infinityforreddit.events.ToggleSecureModeEvent; +import ml.docilealligator.infinityforreddit.font.ContentFontFamily; +import ml.docilealligator.infinityforreddit.font.FontFamily; +import ml.docilealligator.infinityforreddit.font.TitleFontFamily; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.utils.Utils; @@ -69,12 +72,18 @@ public class Infinity extends Application implements LifecycleObserver { isSecureMode = mSecuritySharedPreferences.getBoolean(SharedPreferencesUtils.SECURE_MODE, false); try { - typeface = Typeface.createFromFile(getExternalFilesDir("fonts") + "/font_family.ttf"); - titleTypeface = Typeface.createFromFile(getExternalFilesDir("fonts") + "/title_font_family.ttf"); - contentTypeface = Typeface.createFromFile(getExternalFilesDir("fonts") + "/content_font_family.ttf"); + if (mSharedPreferences.getString(SharedPreferencesUtils.FONT_FAMILY_KEY, FontFamily.Default.name()).equals(FontFamily.Custom.name())) { + typeface = Typeface.createFromFile(getExternalFilesDir("fonts") + "/font_family.ttf"); + } + if (mSharedPreferences.getString(SharedPreferencesUtils.TITLE_FONT_FAMILY_KEY, TitleFontFamily.Default.name()).equals(TitleFontFamily.Custom.name())) { + titleTypeface = Typeface.createFromFile(getExternalFilesDir("fonts") + "/title_font_family.ttf"); + } + if (mSharedPreferences.getString(SharedPreferencesUtils.CONTENT_FONT_FAMILY_KEY, ContentFontFamily.Default.name()).equals(ContentFontFamily.Custom.name())) { + contentTypeface = Typeface.createFromFile(getExternalFilesDir("fonts") + "/content_font_family.ttf"); + } } catch (RuntimeException e) { e.printStackTrace(); - Toast.makeText(this, "Some font files do not exist", Toast.LENGTH_SHORT).show(); + Toast.makeText(this, R.string.unable_to_load_font, Toast.LENGTH_SHORT).show(); } registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() { -- cgit v1.2.3