-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: [ANDROAPP-6693] initial commit
- Loading branch information
1 parent
64a1951
commit a1dc252
Showing
62 changed files
with
3,589 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...in/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/composetable/TableScreenState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.hisp.dhis.mobile.ui.designsystem.component.composetable | ||
|
||
import org.hisp.dhis.mobile.ui.designsystem.component.composetable.model.TableModel | ||
import java.util.UUID | ||
|
||
data class TableScreenState( | ||
val tables: List<TableModel>, | ||
val id: UUID = UUID.randomUUID(), | ||
val state: TableState = TableState.LOADING, | ||
) | ||
// todo review if this class is still needed | ||
data class TableConfigurationState( | ||
val overwrittenTableWidth: Map<String, Float>? = null, | ||
val overwrittenRowHeaderWidth: Map<String, Float>? = null, | ||
val overwrittenColumnWidth: Map<String, Map<Int, Float>>? = null, | ||
) { | ||
fun isResized() = !overwrittenTableWidth.isNullOrEmpty() or | ||
!overwrittenRowHeaderWidth.isNullOrEmpty() or | ||
!overwrittenColumnWidth.isNullOrEmpty() | ||
} | ||
|
||
enum class TableState { | ||
LOADING, | ||
SUCCESS, | ||
} |
3 changes: 3 additions & 0 deletions
3
...n/org/hisp/dhis/mobile/ui/designsystem/component/composetable/actions/DefaultValidator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package org.hisp.dhis.mobile.ui.designsystem.component.composetable.actions | ||
|
||
class DefaultValidator : Validator |
12 changes: 12 additions & 0 deletions
12
.../org/hisp/dhis/mobile/ui/designsystem/component/composetable/actions/TableInteractions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.hisp.dhis.mobile.ui.designsystem.component.composetable.actions | ||
|
||
import org.hisp.dhis.mobile.ui.designsystem.component.composetable.model.TableCell | ||
import org.hisp.dhis.mobile.ui.designsystem.component.composetable.model.TableDialogModel | ||
import org.hisp.dhis.mobile.ui.designsystem.component.composetable.ui.TableSelection | ||
|
||
interface TableInteractions { | ||
fun onSelectionChange(newTableSelection: TableSelection) = run { } | ||
fun onDecorationClick(dialogModel: TableDialogModel) = run { } | ||
fun onClick(tableCell: TableCell) = run { } | ||
fun onOptionSelected(cell: TableCell, code: String, label: String) = run { } | ||
} |
9 changes: 9 additions & 0 deletions
9
...org/hisp/dhis/mobile/ui/designsystem/component/composetable/actions/TableResizeActions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.hisp.dhis.mobile.ui.designsystem.component.composetable.actions | ||
|
||
interface TableResizeActions { | ||
fun onTableWidthChanged(width: Int) = run {} | ||
fun onRowHeaderResize(tableId: String, newValue: Float) = run {} | ||
fun onColumnHeaderResize(tableId: String, column: Int, newValue: Float) = run {} | ||
fun onTableDimensionResize(tableId: String, newValue: Float) = run {} | ||
fun onTableDimensionReset(tableId: String) = run {} | ||
} |
9 changes: 9 additions & 0 deletions
9
.../hisp/dhis/mobile/ui/designsystem/component/composetable/actions/TextInputInteractions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.hisp.dhis.mobile.ui.designsystem.component.composetable.actions | ||
|
||
import org.hisp.dhis.mobile.ui.designsystem.component.composetable.model.TextInputModel | ||
// todo review whether this interface is still needed | ||
interface TextInputInteractions { | ||
fun onTextChanged(textInputModel: TextInputModel) = run {} | ||
fun onSave() = run {} | ||
fun onNextSelected() = run {} | ||
} |
10 changes: 10 additions & 0 deletions
10
...n/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/composetable/actions/Validator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.hisp.dhis.mobile.ui.designsystem.component.composetable.actions | ||
|
||
import org.hisp.dhis.mobile.ui.designsystem.component.composetable.model.TableCell | ||
import org.hisp.dhis.mobile.ui.designsystem.component.composetable.model.ValidationResult | ||
|
||
interface Validator { | ||
fun validate(tableCell: TableCell): ValidationResult { | ||
return ValidationResult.Success(tableCell.value) | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...otlin/org/hisp/dhis/mobile/ui/designsystem/component/composetable/model/DropdownOption.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.hisp.dhis.mobile.ui.designsystem.component.composetable.model | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
//todo: maybe we could rethink this class in order to avoid using it in so many different places in the app, it could be a generic T variable | ||
@Serializable | ||
data class DropdownOption( | ||
val code: String, | ||
val name: String, | ||
) |
3 changes: 3 additions & 0 deletions
3
...otlin/org/hisp/dhis/mobile/ui/designsystem/component/composetable/model/HeaderMeasures.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package org.hisp.dhis.mobile.ui.designsystem.component.composetable.model | ||
|
||
data class HeaderMeasures(val width: Int, val height: Int) |
23 changes: 23 additions & 0 deletions
23
.../hisp/dhis/mobile/ui/designsystem/component/composetable/model/ItemColumnHeaderUiState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.hisp.dhis.mobile.ui.designsystem.component.composetable.model | ||
|
||
import androidx.compose.foundation.layout.PaddingValues | ||
import org.hisp.dhis.mobile.ui.designsystem.component.composetable.ui.CellStyle | ||
import org.hisp.dhis.mobile.ui.designsystem.component.composetable.ui.TableDimensions | ||
import org.hisp.dhis.mobile.ui.designsystem.component.composetable.ui.semantics.HEADER_CELL | ||
|
||
data class ItemColumnHeaderUiState( | ||
val tableId: String?, | ||
val rowIndex: Int, | ||
val columnIndex: Int, | ||
val headerCell: TableHeaderCell, | ||
val headerMeasures: HeaderMeasures, | ||
val paddingValues: PaddingValues, | ||
val cellStyle: CellStyle, | ||
val onCellSelected: (Int) -> Unit, | ||
val onHeaderResize: (Int, Float) -> Unit, | ||
val onResizing: (ResizingCell?) -> Unit, | ||
val isLastRow: Boolean, | ||
val checkMaxCondition: (TableDimensions, Float) -> Boolean, | ||
) { | ||
val testTag = "$HEADER_CELL$tableId$rowIndex$columnIndex" | ||
} |
16 changes: 16 additions & 0 deletions
16
...in/org/hisp/dhis/mobile/ui/designsystem/component/composetable/model/ItemHeaderUiState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.hisp.dhis.mobile.ui.designsystem.component.composetable.model | ||
|
||
import androidx.compose.ui.unit.Dp | ||
import org.hisp.dhis.mobile.ui.designsystem.component.composetable.ui.CellStyle | ||
|
||
data class ItemHeaderUiState( | ||
val tableId: String, | ||
val rowHeader: RowHeader, | ||
val cellStyle: CellStyle, | ||
val width: Dp, | ||
val maxLines: Int, | ||
val onCellSelected: (Int?) -> Unit, | ||
val onDecorationClick: (dialogModel: TableDialogModel) -> Unit, | ||
val onHeaderResize: (Float) -> Unit, | ||
val onResizing: (ResizingCell?) -> Unit, | ||
) |
38 changes: 38 additions & 0 deletions
38
...in/org/hisp/dhis/mobile/ui/designsystem/component/composetable/model/KeyboardInputType.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package org.hisp.dhis.mobile.ui.designsystem.component.composetable.model | ||
|
||
sealed class KeyboardInputType( | ||
open val multiline: Boolean = false, | ||
open val forceCapitalize: Boolean = false, | ||
) { | ||
data class TextInput( | ||
override val multiline: Boolean = false, | ||
override val forceCapitalize: Boolean = false, | ||
) : KeyboardInputType(multiline, forceCapitalize) | ||
|
||
data class NumericInput( | ||
override val multiline: Boolean = false, | ||
override val forceCapitalize: Boolean = false, | ||
val allowDecimal: Boolean = true, | ||
val allowSigned: Boolean = true, | ||
) : KeyboardInputType(multiline, forceCapitalize) | ||
|
||
data class NumberPassword( | ||
override val multiline: Boolean = false, | ||
override val forceCapitalize: Boolean = false, | ||
) : KeyboardInputType(multiline, forceCapitalize) | ||
|
||
data class PhoneInput( | ||
override val multiline: Boolean = false, | ||
override val forceCapitalize: Boolean = false, | ||
) : KeyboardInputType(multiline) | ||
|
||
data class EmailInput( | ||
override val multiline: Boolean = false, | ||
override val forceCapitalize: Boolean = false, | ||
) : KeyboardInputType(multiline, forceCapitalize) | ||
|
||
data class URLInput( | ||
override val multiline: Boolean = false, | ||
override val forceCapitalize: Boolean = false, | ||
) : KeyboardInputType(multiline, forceCapitalize) | ||
} |
8 changes: 8 additions & 0 deletions
8
.../kotlin/org/hisp/dhis/mobile/ui/designsystem/component/composetable/model/ResizingCell.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.hisp.dhis.mobile.ui.designsystem.component.composetable.model | ||
|
||
import androidx.compose.ui.geometry.Offset | ||
|
||
data class ResizingCell( | ||
val initialPosition: Offset, | ||
val draggingOffsetX: Float, | ||
) |
12 changes: 12 additions & 0 deletions
12
...ain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/composetable/model/RowHeader.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.hisp.dhis.mobile.ui.designsystem.component.composetable.model | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class RowHeader( | ||
val id: String? = null, | ||
val title: String, | ||
val row: Int, | ||
val showDecoration: Boolean = false, | ||
val description: String? = null, | ||
) |
21 changes: 21 additions & 0 deletions
21
...ain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/composetable/model/TableCell.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.hisp.dhis.mobile.ui.designsystem.component.composetable.model | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class TableCell( | ||
val id: String? = null, | ||
val row: Int? = null, | ||
val column: Int, | ||
val value: String?, | ||
val editable: Boolean = true, | ||
val mandatory: Boolean? = false, | ||
val error: String? = null, | ||
val warning: String? = null, | ||
val legendColor: Int? = null, | ||
val isMultiText: Boolean = false, | ||
) { | ||
|
||
fun hasErrorOrWarning() = errorOrWarningMessage() != null | ||
fun errorOrWarningMessage() = error ?: warning | ||
} |
8 changes: 8 additions & 0 deletions
8
...n/org/hisp/dhis/mobile/ui/designsystem/component/composetable/model/TableCornerUiState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.hisp.dhis.mobile.ui.designsystem.component.composetable.model | ||
|
||
data class TableCornerUiState( | ||
val isSelected: Boolean = false, | ||
val onTableResize: (Float) -> Unit, | ||
val onResizing: (ResizingCell?) -> Unit, | ||
val singleValueTable: Boolean = false, | ||
) |
6 changes: 6 additions & 0 deletions
6
...lin/org/hisp/dhis/mobile/ui/designsystem/component/composetable/model/TableDialogModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package org.hisp.dhis.mobile.ui.designsystem.component.composetable.model | ||
|
||
data class TableDialogModel( | ||
val title: String, | ||
val message: String, | ||
) |
16 changes: 16 additions & 0 deletions
16
...n/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/composetable/model/TableHeader.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.hisp.dhis.mobile.ui.designsystem.component.composetable.model | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class TableHeader(val rows: List<TableHeaderRow>, val hasTotals: Boolean = false) { | ||
fun numberOfColumns(rowIndex: Int): Int { | ||
var totalCells = 1 | ||
for (index in 0 until rowIndex + 1) { | ||
totalCells *= rows[index].cells.size | ||
} | ||
return totalCells | ||
} | ||
|
||
fun tableMaxColumns() = numberOfColumns(rows.size - 1) | ||
} |
6 changes: 6 additions & 0 deletions
6
...tlin/org/hisp/dhis/mobile/ui/designsystem/component/composetable/model/TableHeaderCell.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package org.hisp.dhis.mobile.ui.designsystem.component.composetable.model | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class TableHeaderCell(val value: String) |
6 changes: 6 additions & 0 deletions
6
...otlin/org/hisp/dhis/mobile/ui/designsystem/component/composetable/model/TableHeaderRow.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package org.hisp.dhis.mobile.ui.designsystem.component.composetable.model | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class TableHeaderRow(val cells: List<TableHeaderCell>) |
75 changes: 75 additions & 0 deletions
75
...in/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/composetable/model/TableModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package org.hisp.dhis.mobile.ui.designsystem.component.composetable.model | ||
|
||
import kotlinx.serialization.Serializable | ||
import org.hisp.dhis.mobile.ui.designsystem.component.composetable.ui.TableSelection | ||
|
||
@Serializable | ||
data class TableModel( | ||
val id: String? = null, | ||
val title: String = "", | ||
val tableHeaderModel: TableHeader, | ||
val tableRows: List<TableRowModel>, | ||
val overwrittenValues: Map<Int, TableCell> = emptyMap(), | ||
) { | ||
fun countChildrenOfSelectedHeader( | ||
headerRowIndex: Int, | ||
headerColumnIndex: Int, | ||
): Map<Int, TableSelection.HeaderCellRange> { | ||
return tableHeaderModel.rows | ||
.filterIndexed { index, _ -> index > headerRowIndex } | ||
.mapIndexed { index, _ -> | ||
val rowIndex = headerRowIndex + 1 + index | ||
val rowSize = | ||
tableHeaderModel.numberOfColumns(rowIndex) / tableHeaderModel.numberOfColumns( | ||
headerRowIndex, | ||
) | ||
val init = headerColumnIndex * rowSize | ||
val end = (headerColumnIndex + 1) * rowSize - 1 | ||
rowIndex to TableSelection.HeaderCellRange(rowSize, init, end) | ||
}.toMap() | ||
} | ||
|
||
fun getNextCell( | ||
cellSelection: TableSelection.CellSelection, | ||
successValidation: Boolean, | ||
): Pair<TableCell, TableSelection.CellSelection>? = 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] | ||
when (tableCell?.editable) { | ||
true -> Pair(tableCell, nextCell) | ||
else -> getNextCell(nextCell, successValidation) | ||
} | ||
} | ||
|
||
fun cellHasError(cell: TableSelection.CellSelection): TableCell? { | ||
return when { | ||
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 } | ||
} | ||
} | ||
|
||
//review whether this class is still needed | ||
fun hasCellWithId(cellId: String?): Boolean { | ||
return tableRows.any { row -> | ||
row.rowHeader.id?.let { | ||
it.isNotEmpty() && cellId?.contains(it) == true | ||
} ?: false | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...kotlin/org/hisp/dhis/mobile/ui/designsystem/component/composetable/model/TableRowModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.hisp.dhis.mobile.ui.designsystem.component.composetable.model | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class TableRowModel( | ||
val rowHeader: RowHeader, | ||
val values: Map<Int, TableCell>, | ||
val isLastRow: Boolean = false, | ||
val maxLines: Int = 3, | ||
val dropDownOptions: List<DropdownOption>? = null, | ||
) |
Oops, something went wrong.