From 875d37fc27824c7d6c5a65ff70f139ba23eeff5f Mon Sep 17 00:00:00 2001 From: Laurent Date: Tue, 26 May 2020 11:05:29 +0200 Subject: [PATCH] Protects unsuccesful typeface loading from crashes --- .../android/ui/graph/GraphExtensions.kt | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/net/pokeranalytics/android/ui/graph/GraphExtensions.kt b/app/src/main/java/net/pokeranalytics/android/ui/graph/GraphExtensions.kt index b93cc841..63193351 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/graph/GraphExtensions.kt +++ b/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.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) this.xAxis.typeface = font } catch (e: Resources.NotFoundException) { @@ -47,12 +47,8 @@ fun BarLineChartBase<*>.setStyle( this.xAxis.isEnabled = true when (this) { - is BarChart -> { - this.xAxis.setDrawLabels(false) - } - else -> { - this.xAxis.setDrawLabels(true) - } + is BarChart -> this.xAxis.setDrawLabels(false) + else -> this.xAxis.setDrawLabels(true) } // Y Axis @@ -67,7 +63,14 @@ fun BarLineChartBase<*>.setStyle( this.axisLeft.granularity = 1.0f 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 = 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