Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't overwrite or fetch font when already loaded #700

Draft
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Don't overwrite or fetch font when already loaded
  • Loading branch information
cameronvoell committed Jun 1, 2021
commit 9858e131bf8d4d8f52e47ed05a5df47bd6ab8668
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@ object FontRequester {

fun registerFont(context: Context, @FontRes fontRes: Int, fallback: Typeface) {
// Set the font to the fallback right away in case it's requested before getFont completes.
fontMap[fontRes] = fallback
try {
ResourcesCompat.getFont(context, fontRes, fontCallbackFor(context, fontRes), null)
} catch (e: NotFoundException) {
Log.e(TAG, "Font ${context.resources.getResourceEntryName(fontRes)} not found")
if (fontMap[fontRes] == null) {
fontMap[fontRes] = fallback
}
if (fontMap[fontRes] == fallback) {
try {
ResourcesCompat.getFont(context, fontRes, fontCallbackFor(context, fontRes), null)
} catch (e: NotFoundException) {
Log.e(TAG, "Font ${context.resources.getResourceEntryName(fontRes)} not found")
}
}
}

Expand Down