From b7d398b79bafdee560a64bc9f06911c017a2692e Mon Sep 17 00:00:00 2001 From: Laurent Date: Mon, 4 Jan 2021 14:47:14 +0100 Subject: [PATCH] Better error for crash --- .../modules/handhistory/model/EditorViewModel.kt | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/EditorViewModel.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/EditorViewModel.kt index 869162b2..f3555b45 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/EditorViewModel.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/EditorViewModel.kt @@ -113,9 +113,11 @@ class EditorViewModel : ViewModel(), RowRepresentableDataSource, CardCentralizer */ val currentKeyboard: HHKeyboard? get() { - this.selectionLiveData.value?.let { - val row = this.rowRepresentables[it.index] as HandHistoryRow - return row.keyboardForTag(it.tag) + this.selectionLiveData.value?.let { selection -> + val row = this.rowRepresentables[selection.index] + (row as? HandHistoryRow)?.let { hhRow -> + return hhRow.keyboardForTag(selection.tag) + } ?: throw PAIllegalStateException("Row $row cannot be cast to HandHistoryRow") } return null } @@ -695,11 +697,11 @@ class EditorViewModel : ViewModel(), RowRepresentableDataSource, CardCentralizer // Row Representable Datasource - override fun adapterRows(): List? { + override fun adapterRows(): List { return this.rowRepresentables } - override fun rowRepresentableForPosition(position: Int): RowRepresentable? { + override fun rowRepresentableForPosition(position: Int): RowRepresentable { return this.rowRepresentables[position] } @@ -859,7 +861,7 @@ class EditorViewModel : ViewModel(), RowRepresentableDataSource, CardCentralizer } } - override fun backgroundColor(position: Int, row: RowRepresentable): Int? { + override fun backgroundColor(position: Int, row: RowRepresentable): Int { return if (this.isEdited) { if (position < this.settingsRowCount) R.color.green_header else R.color.transparent } else {