From 0da4b968726145dd8cb57146869326373d3eda23 Mon Sep 17 00:00:00 2001 From: Moez Bhatti Date: Fri, 18 May 2018 13:57:30 -0400 Subject: [PATCH] Fix crash with SmsMessage.calculateLength() --- presentation/src/main/java/feature/compose/ComposeViewModel.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/presentation/src/main/java/feature/compose/ComposeViewModel.kt b/presentation/src/main/java/feature/compose/ComposeViewModel.kt index c53958aa..27a8c9a1 100644 --- a/presentation/src/main/java/feature/compose/ComposeViewModel.kt +++ b/presentation/src/main/java/feature/compose/ComposeViewModel.kt @@ -60,6 +60,7 @@ import util.extensions.asObservable import util.extensions.isImage import util.extensions.mapNotNull import util.extensions.removeAccents +import util.tryOrNull import java.net.URLDecoder import java.util.* import java.util.concurrent.TimeUnit @@ -479,7 +480,7 @@ class ComposeViewModel @Inject constructor( // Show the remaining character counter when necessary view.textChangedIntent .observeOn(Schedulers.computation()) - .map { draft -> SmsMessage.calculateLength(draft, false) } + .mapNotNull { draft -> tryOrNull { SmsMessage.calculateLength(draft, false) } } .map { array -> val messages = array[0] val remaining = array[2]