Surrounds crash with try/catch block

blinds
Laurent 5 years ago
parent 6325daf4c3
commit eb86679fa7
  1. 20
      app/src/main/java/net/pokeranalytics/android/ui/fragment/SubscriptionFragment.kt

@ -1,5 +1,6 @@
package net.pokeranalytics.android.ui.fragment
import android.content.res.Resources
import android.graphics.drawable.GradientDrawable
import android.os.Build
import android.os.Bundle
@ -118,14 +119,21 @@ class SubscriptionFragment : BaseFragment(), SkuDetailsResponseListener, Purchas
if (indexOfLastSpace >= 0) {
val end = upgradeString.chars().count().toInt()
val lightTypeFace = ResourcesCompat.getFont(requireContext(), R.font.roboto_light)
val boldTypeFace = ResourcesCompat.getFont(requireContext(), R.font.roboto_bold)
try { // can crash for unknown reasons
if (lightTypeFace != null && boldTypeFace != null) {
ssb.setSpan(TypefaceSpan(lightTypeFace), 0, indexOfLastSpace, Spanned.SPAN_EXCLUSIVE_INCLUSIVE)
ssb.setSpan(TypefaceSpan(boldTypeFace), indexOfLastSpace, end, Spanned.SPAN_EXCLUSIVE_INCLUSIVE)
val end = upgradeString.chars().count().toInt()
val lightTypeFace = ResourcesCompat.getFont(requireContext(), R.font.roboto_light)
val boldTypeFace = ResourcesCompat.getFont(requireContext(), R.font.roboto_bold)
if (lightTypeFace != null && boldTypeFace != null) {
ssb.setSpan(TypefaceSpan(lightTypeFace), 0, indexOfLastSpace, Spanned.SPAN_EXCLUSIVE_INCLUSIVE)
ssb.setSpan(TypefaceSpan(boldTypeFace), indexOfLastSpace, end, Spanned.SPAN_EXCLUSIVE_INCLUSIVE)
}
} catch (e: Resources.NotFoundException) {
CrashLogging.log(e.message ?: "ResourcesCompat.getFont crashes somehow")
}
}
title.text = ssb

Loading…
Cancel
Save