Protects unsuccesful typeface loading from crashes

od
Laurent 6 years ago
parent b5bfc875d8
commit 875d37fc27
  1. 19
      app/src/main/java/net/pokeranalytics/android/ui/graph/GraphExtensions.kt

@ -35,7 +35,7 @@ fun BarLineChartBase<*>.setStyle(
this.xAxis.granularity = 1.0f this.xAxis.granularity = 1.0f
this.xAxis.textColor = ContextCompat.getColor(context, R.color.chart_default) this.xAxis.textColor = ContextCompat.getColor(context, R.color.chart_default)
try { try { // can crash for unknown reasons, same below for Y axis
val font = ResourcesCompat.getFont(context, R.font.roboto_medium) val font = ResourcesCompat.getFont(context, R.font.roboto_medium)
this.xAxis.typeface = font this.xAxis.typeface = font
} catch (e: Resources.NotFoundException) { } catch (e: Resources.NotFoundException) {
@ -47,12 +47,8 @@ fun BarLineChartBase<*>.setStyle(
this.xAxis.isEnabled = true this.xAxis.isEnabled = true
when (this) { when (this) {
is BarChart -> { is BarChart -> this.xAxis.setDrawLabels(false)
this.xAxis.setDrawLabels(false) else -> this.xAxis.setDrawLabels(true)
}
else -> {
this.xAxis.setDrawLabels(true)
}
} }
// Y Axis // Y Axis
@ -67,7 +63,14 @@ fun BarLineChartBase<*>.setStyle(
this.axisLeft.granularity = 1.0f this.axisLeft.granularity = 1.0f
this.axisLeft.textColor = ContextCompat.getColor(context, R.color.chart_default) this.axisLeft.textColor = ContextCompat.getColor(context, R.color.chart_default)
this.axisLeft.typeface = ResourcesCompat.getFont(context, R.font.roboto_medium)
try {
val font = ResourcesCompat.getFont(context, R.font.roboto_medium)
this.axisLeft.typeface = font
} catch (e: Resources.NotFoundException) {
Crashlytics.log(e.message)
}
this.axisLeft.labelCount = this.axisLeft.labelCount =
if (small) 1 else 7 // @todo not great if interval is [0..2] for number of records as we get decimals if (small) 1 else 7 // @todo not great if interval is [0..2] for number of records as we get decimals
this.axisLeft.textSize = 12f this.axisLeft.textSize = 12f

Loading…
Cancel
Save