From fa5d302f867f4a71c6464c45c2b13e3f4f3c8bfb Mon Sep 17 00:00:00 2001 From: Pablo Date: Fri, 13 Dec 2024 11:29:32 +0100 Subject: [PATCH] fix: [ANDROAPP-6519] Crash when accessing cell (#3924) --- .../main/java/org/dhis2/composetable/model/TableModel.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/compose-table/src/main/java/org/dhis2/composetable/model/TableModel.kt b/compose-table/src/main/java/org/dhis2/composetable/model/TableModel.kt index c38a32ff77..6723520f0a 100644 --- a/compose-table/src/main/java/org/dhis2/composetable/model/TableModel.kt +++ b/compose-table/src/main/java/org/dhis2/composetable/model/TableModel.kt @@ -35,14 +35,17 @@ data class TableModel( ): Pair? = when { !successValidation -> cellSelection + cellSelection.columnIndex < tableHeaderModel.tableMaxColumns() - 1 -> cellSelection.copy(columnIndex = cellSelection.columnIndex + 1) + cellSelection.rowIndex < tableRows.size - 1 -> cellSelection.copy( columnIndex = 0, rowIndex = cellSelection.rowIndex + 1, globalIndex = cellSelection.globalIndex + 1, ) + else -> null }?.let { nextCell -> val tableCell = tableRows[nextCell.rowIndex].values[nextCell.columnIndex] @@ -57,10 +60,14 @@ data class TableModel( tableRows.size == 1 && tableRows.size == cell.rowIndex -> { tableRows[0].values[cell.columnIndex]?.takeIf { it.error != null } } + tableRows.size == cell.rowIndex -> { tableRows[cell.rowIndex - 1].values[cell.columnIndex]?.takeIf { it.error != null } } - else -> tableRows[cell.rowIndex].values[cell.columnIndex]?.takeIf { it.error != null } + + else -> tableRows.getOrNull(cell.rowIndex) + ?.values?.get(cell.columnIndex) + ?.takeIf { it.error != null } } }