diff --git a/app/src/main/java/org/dhis2/data/forms/dataentry/tablefields/FieldViewModel.java b/app/src/main/java/org/dhis2/data/forms/dataentry/tablefields/FieldViewModel.java index 16f3b95ae4..f58260f7f9 100644 --- a/app/src/main/java/org/dhis2/data/forms/dataentry/tablefields/FieldViewModel.java +++ b/app/src/main/java/org/dhis2/data/forms/dataentry/tablefields/FieldViewModel.java @@ -3,7 +3,8 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import org.dhis2.composetable.model.DropdownOption; + +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.model.DropdownOption; import java.util.List; diff --git a/app/src/main/java/org/dhis2/data/forms/dataentry/tablefields/FieldViewModelFactory.java b/app/src/main/java/org/dhis2/data/forms/dataentry/tablefields/FieldViewModelFactory.java index 10d2e546bd..76015a3f7d 100644 --- a/app/src/main/java/org/dhis2/data/forms/dataentry/tablefields/FieldViewModelFactory.java +++ b/app/src/main/java/org/dhis2/data/forms/dataentry/tablefields/FieldViewModelFactory.java @@ -3,9 +3,9 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import org.dhis2.composetable.model.DropdownOption; import org.hisp.dhis.android.core.common.ValueType; import org.hisp.dhis.android.core.program.SectionRenderingType; +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.model.DropdownOption; import java.util.List; diff --git a/app/src/main/java/org/dhis2/data/forms/dataentry/tablefields/FieldViewModelFactoryImpl.java b/app/src/main/java/org/dhis2/data/forms/dataentry/tablefields/FieldViewModelFactoryImpl.java index 42c07287b2..a5de4e6428 100644 --- a/app/src/main/java/org/dhis2/data/forms/dataentry/tablefields/FieldViewModelFactoryImpl.java +++ b/app/src/main/java/org/dhis2/data/forms/dataentry/tablefields/FieldViewModelFactoryImpl.java @@ -3,7 +3,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import org.dhis2.composetable.model.DropdownOption; + import org.dhis2.data.forms.dataentry.tablefields.age.AgeViewModel; import org.dhis2.data.forms.dataentry.tablefields.coordinate.CoordinateViewModel; import org.dhis2.data.forms.dataentry.tablefields.datetime.DateTimeViewModel; @@ -14,6 +14,7 @@ import org.dhis2.data.forms.dataentry.tablefields.unsupported.UnsupportedViewModel; import org.hisp.dhis.android.core.common.ValueType; import org.hisp.dhis.android.core.program.SectionRenderingType; +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.model.DropdownOption; import java.util.List; diff --git a/app/src/main/java/org/dhis2/data/forms/dataentry/tablefields/age/AgeViewModel.java b/app/src/main/java/org/dhis2/data/forms/dataentry/tablefields/age/AgeViewModel.java index f3299ed601..7640748695 100644 --- a/app/src/main/java/org/dhis2/data/forms/dataentry/tablefields/age/AgeViewModel.java +++ b/app/src/main/java/org/dhis2/data/forms/dataentry/tablefields/age/AgeViewModel.java @@ -5,8 +5,8 @@ import com.google.auto.value.AutoValue; -import org.dhis2.composetable.model.DropdownOption; import org.dhis2.data.forms.dataentry.tablefields.FieldViewModel; +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.model.DropdownOption; import java.util.List; diff --git a/app/src/main/java/org/dhis2/data/forms/dataentry/tablefields/coordinate/CoordinateViewModel.java b/app/src/main/java/org/dhis2/data/forms/dataentry/tablefields/coordinate/CoordinateViewModel.java index c6faeaa1aa..fc0424a67b 100644 --- a/app/src/main/java/org/dhis2/data/forms/dataentry/tablefields/coordinate/CoordinateViewModel.java +++ b/app/src/main/java/org/dhis2/data/forms/dataentry/tablefields/coordinate/CoordinateViewModel.java @@ -5,8 +5,8 @@ import com.google.auto.value.AutoValue; -import org.dhis2.composetable.model.DropdownOption; import org.dhis2.data.forms.dataentry.tablefields.FieldViewModel; +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.model.DropdownOption; import java.util.List; diff --git a/app/src/main/java/org/dhis2/data/forms/dataentry/tablefields/datetime/DateTimeViewModel.java b/app/src/main/java/org/dhis2/data/forms/dataentry/tablefields/datetime/DateTimeViewModel.java index 525279ff72..5565ec7490 100644 --- a/app/src/main/java/org/dhis2/data/forms/dataentry/tablefields/datetime/DateTimeViewModel.java +++ b/app/src/main/java/org/dhis2/data/forms/dataentry/tablefields/datetime/DateTimeViewModel.java @@ -5,9 +5,9 @@ import com.google.auto.value.AutoValue; -import org.dhis2.composetable.model.DropdownOption; import org.dhis2.data.forms.dataentry.tablefields.FieldViewModel; import org.hisp.dhis.android.core.common.ValueType; +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.model.DropdownOption; import java.util.List; diff --git a/app/src/main/java/org/dhis2/data/forms/dataentry/tablefields/edittext/EditTextViewModel.java b/app/src/main/java/org/dhis2/data/forms/dataentry/tablefields/edittext/EditTextViewModel.java index d3557731a4..b082ca5ada 100644 --- a/app/src/main/java/org/dhis2/data/forms/dataentry/tablefields/edittext/EditTextViewModel.java +++ b/app/src/main/java/org/dhis2/data/forms/dataentry/tablefields/edittext/EditTextViewModel.java @@ -6,9 +6,9 @@ import com.google.auto.value.AutoValue; -import org.dhis2.composetable.model.DropdownOption; import org.dhis2.data.forms.dataentry.tablefields.FieldViewModel; import org.hisp.dhis.android.core.common.ValueType; +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.model.DropdownOption; import java.util.List; diff --git a/app/src/main/java/org/dhis2/data/forms/dataentry/tablefields/file/FileViewModel.java b/app/src/main/java/org/dhis2/data/forms/dataentry/tablefields/file/FileViewModel.java index eed70d13b4..2fea834bc5 100644 --- a/app/src/main/java/org/dhis2/data/forms/dataentry/tablefields/file/FileViewModel.java +++ b/app/src/main/java/org/dhis2/data/forms/dataentry/tablefields/file/FileViewModel.java @@ -5,8 +5,8 @@ import com.google.auto.value.AutoValue; -import org.dhis2.composetable.model.DropdownOption; import org.dhis2.data.forms.dataentry.tablefields.FieldViewModel; +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.model.DropdownOption; import java.util.List; diff --git a/app/src/main/java/org/dhis2/data/forms/dataentry/tablefields/image/ImageViewModel.java b/app/src/main/java/org/dhis2/data/forms/dataentry/tablefields/image/ImageViewModel.java index 24dbc35812..62cb32c1a9 100644 --- a/app/src/main/java/org/dhis2/data/forms/dataentry/tablefields/image/ImageViewModel.java +++ b/app/src/main/java/org/dhis2/data/forms/dataentry/tablefields/image/ImageViewModel.java @@ -4,8 +4,8 @@ import com.google.auto.value.AutoValue; -import org.dhis2.composetable.model.DropdownOption; import org.dhis2.data.forms.dataentry.tablefields.FieldViewModel; +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.model.DropdownOption; import java.util.List; diff --git a/app/src/main/java/org/dhis2/data/forms/dataentry/tablefields/orgUnit/OrgUnitViewModel.java b/app/src/main/java/org/dhis2/data/forms/dataentry/tablefields/orgUnit/OrgUnitViewModel.java index fc90c8ffa9..28f617acb8 100644 --- a/app/src/main/java/org/dhis2/data/forms/dataentry/tablefields/orgUnit/OrgUnitViewModel.java +++ b/app/src/main/java/org/dhis2/data/forms/dataentry/tablefields/orgUnit/OrgUnitViewModel.java @@ -4,8 +4,8 @@ import com.google.auto.value.AutoValue; -import org.dhis2.composetable.model.DropdownOption; import org.dhis2.data.forms.dataentry.tablefields.FieldViewModel; +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.model.DropdownOption; import java.util.List; diff --git a/app/src/main/java/org/dhis2/data/forms/dataentry/tablefields/radiobutton/RadioButtonViewModel.java b/app/src/main/java/org/dhis2/data/forms/dataentry/tablefields/radiobutton/RadioButtonViewModel.java index 1b27259248..0090a2e6d1 100644 --- a/app/src/main/java/org/dhis2/data/forms/dataentry/tablefields/radiobutton/RadioButtonViewModel.java +++ b/app/src/main/java/org/dhis2/data/forms/dataentry/tablefields/radiobutton/RadioButtonViewModel.java @@ -5,9 +5,9 @@ import com.google.auto.value.AutoValue; -import org.dhis2.composetable.model.DropdownOption; import org.dhis2.data.forms.dataentry.tablefields.FieldViewModel; import org.hisp.dhis.android.core.common.ValueType; +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.model.DropdownOption; import java.util.List; import java.util.Locale; diff --git a/app/src/main/java/org/dhis2/data/forms/dataentry/tablefields/spinner/SpinnerViewModel.java b/app/src/main/java/org/dhis2/data/forms/dataentry/tablefields/spinner/SpinnerViewModel.java index f44f0b2198..6e260fd3c9 100644 --- a/app/src/main/java/org/dhis2/data/forms/dataentry/tablefields/spinner/SpinnerViewModel.java +++ b/app/src/main/java/org/dhis2/data/forms/dataentry/tablefields/spinner/SpinnerViewModel.java @@ -4,8 +4,8 @@ import com.google.auto.value.AutoValue; -import org.dhis2.composetable.model.DropdownOption; import org.dhis2.data.forms.dataentry.tablefields.FieldViewModel; +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.model.DropdownOption; import java.util.List; diff --git a/app/src/main/java/org/dhis2/data/forms/dataentry/tablefields/unsupported/UnsupportedViewModel.java b/app/src/main/java/org/dhis2/data/forms/dataentry/tablefields/unsupported/UnsupportedViewModel.java index 13d26c08fb..4b01347ab9 100644 --- a/app/src/main/java/org/dhis2/data/forms/dataentry/tablefields/unsupported/UnsupportedViewModel.java +++ b/app/src/main/java/org/dhis2/data/forms/dataentry/tablefields/unsupported/UnsupportedViewModel.java @@ -4,8 +4,8 @@ import com.google.auto.value.AutoValue; -import org.dhis2.composetable.model.DropdownOption; import org.dhis2.data.forms.dataentry.tablefields.FieldViewModel; +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.model.DropdownOption; import java.util.List; diff --git a/app/src/main/java/org/dhis2/usescases/datasets/dataSetTable/dataSetSection/DataSetSectionFragment.kt b/app/src/main/java/org/dhis2/usescases/datasets/dataSetTable/dataSetSection/DataSetSectionFragment.kt index b2c7b0f4f3..e8126825ca 100644 --- a/app/src/main/java/org/dhis2/usescases/datasets/dataSetTable/dataSetSection/DataSetSectionFragment.kt +++ b/app/src/main/java/org/dhis2/usescases/datasets/dataSetTable/dataSetSection/DataSetSectionFragment.kt @@ -31,14 +31,7 @@ import org.dhis2.commons.dialogs.DialogClickListener import org.dhis2.commons.dialogs.calendarpicker.CalendarPicker import org.dhis2.commons.dialogs.calendarpicker.OnDatePickerListener import org.dhis2.commons.orgunitselector.OUTreeFragment -import org.dhis2.composetable.actions.TableResizeActions -import org.dhis2.composetable.model.TableCell -import org.dhis2.composetable.ui.DataSetTableScreen -import org.dhis2.composetable.ui.TableColors -import org.dhis2.composetable.ui.TableConfiguration -import org.dhis2.composetable.ui.TableDimensions -import org.dhis2.composetable.ui.TableTheme -import org.dhis2.composetable.ui.semantics.MAX_CELL_WIDTH_SPACE + import org.dhis2.data.forms.dataentry.tablefields.age.AgeView import org.dhis2.data.forms.dataentry.tablefields.coordinate.CoordinatesView import org.dhis2.data.forms.dataentry.tablefields.radiobutton.YesNoView @@ -55,6 +48,14 @@ import org.hisp.dhis.android.core.common.FeatureType import org.hisp.dhis.android.core.common.ValueTypeRenderingType import org.hisp.dhis.android.core.dataelement.DataElement import org.hisp.dhis.android.core.organisationunit.OrganisationUnit +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.actions.TableResizeActions +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.model.TableCell +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.ui.DataSetTableScreen +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.ui.TableColors +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.ui.TableConfiguration +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.ui.TableDimensions +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.ui.TableTheme +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.ui.semantics.MAX_CELL_WIDTH_SPACE import java.text.SimpleDateFormat import java.util.Calendar import java.util.Date diff --git a/app/src/main/java/org/dhis2/usescases/datasets/dataSetTable/dataSetSection/DataValueContract.kt b/app/src/main/java/org/dhis2/usescases/datasets/dataSetTable/dataSetSection/DataValueContract.kt index 07bf6c3b3e..59af5b59de 100644 --- a/app/src/main/java/org/dhis2/usescases/datasets/dataSetTable/dataSetSection/DataValueContract.kt +++ b/app/src/main/java/org/dhis2/usescases/datasets/dataSetTable/dataSetSection/DataValueContract.kt @@ -1,10 +1,10 @@ package org.dhis2.usescases.datasets.dataSetTable.dataSetSection -import org.dhis2.composetable.model.TableCell import org.dhis2.data.forms.dataentry.tablefields.spinner.SpinnerViewModel import org.dhis2.usescases.general.AbstractActivityContracts import org.hisp.dhis.android.core.dataelement.DataElement import org.hisp.dhis.android.core.organisationunit.OrganisationUnit +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.model.TableCell class DataValueContract { interface View : AbstractActivityContracts.View { diff --git a/app/src/main/java/org/dhis2/usescases/datasets/dataSetTable/dataSetSection/DataValuePresenter.kt b/app/src/main/java/org/dhis2/usescases/datasets/dataSetTable/dataSetSection/DataValuePresenter.kt index 36310c14dd..299263edff 100644 --- a/app/src/main/java/org/dhis2/usescases/datasets/dataSetTable/dataSetSection/DataValuePresenter.kt +++ b/app/src/main/java/org/dhis2/usescases/datasets/dataSetTable/dataSetSection/DataValuePresenter.kt @@ -13,14 +13,6 @@ import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import org.dhis2.commons.schedulers.SchedulerProvider import org.dhis2.commons.viewmodel.DispatcherProvider -import org.dhis2.composetable.TableConfigurationState -import org.dhis2.composetable.TableScreenState -import org.dhis2.composetable.TableState -import org.dhis2.composetable.actions.Validator -import org.dhis2.composetable.model.TableCell -import org.dhis2.composetable.model.TableModel -import org.dhis2.composetable.model.TextInputModel -import org.dhis2.composetable.model.ValidationResult import org.dhis2.data.forms.dataentry.ValueStore import org.dhis2.data.forms.dataentry.tablefields.spinner.SpinnerViewModel import org.dhis2.form.model.ValueStoreResult.ERROR_UPDATING_VALUE @@ -30,6 +22,14 @@ import org.dhis2.usescases.datasets.dataSetTable.dataSetSection.TableDataToTable import org.hisp.dhis.android.core.arch.helpers.Result import org.hisp.dhis.android.core.common.ValueType import org.hisp.dhis.android.core.dataelement.DataElement +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.TableConfigurationState +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.TableScreenState +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.TableState +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.actions.Validator +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.model.TableCell +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.model.TableModel +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.model.TextInputModel +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.model.ValidationResult import timber.log.Timber import kotlin.coroutines.CoroutineContext diff --git a/app/src/main/java/org/dhis2/usescases/datasets/dataSetTable/dataSetSection/DataValueRepository.kt b/app/src/main/java/org/dhis2/usescases/datasets/dataSetTable/dataSetSection/DataValueRepository.kt index 4da96acd03..d9e1d6468d 100644 --- a/app/src/main/java/org/dhis2/usescases/datasets/dataSetTable/dataSetSection/DataValueRepository.kt +++ b/app/src/main/java/org/dhis2/usescases/datasets/dataSetTable/dataSetSection/DataValueRepository.kt @@ -9,8 +9,6 @@ import org.dhis2.bindings.decimalFormat import org.dhis2.commons.bindings.dataValueConflicts import org.dhis2.commons.data.tuples.Pair import org.dhis2.commons.date.DateUtils -import org.dhis2.composetable.model.DropdownOption -import org.dhis2.composetable.model.TableCell import org.dhis2.data.dhislogic.AUTH_DATAVALUE_ADD import org.dhis2.data.forms.dataentry.tablefields.FieldViewModel import org.dhis2.data.forms.dataentry.tablefields.FieldViewModelFactoryImpl @@ -34,6 +32,8 @@ import org.hisp.dhis.android.core.dataset.DataSetElement import org.hisp.dhis.android.core.datavalue.DataValue import org.hisp.dhis.android.core.organisationunit.OrganisationUnit import org.hisp.dhis.android.core.period.Period +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.model.DropdownOption +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.model.TableCell import java.util.SortedMap class DataValueRepository( diff --git a/app/src/main/java/org/dhis2/usescases/datasets/dataSetTable/dataSetSection/TableDataToTableModelMapper.kt b/app/src/main/java/org/dhis2/usescases/datasets/dataSetTable/dataSetSection/TableDataToTableModelMapper.kt index 8c7cc29348..10c8fc0bde 100644 --- a/app/src/main/java/org/dhis2/usescases/datasets/dataSetTable/dataSetSection/TableDataToTableModelMapper.kt +++ b/app/src/main/java/org/dhis2/usescases/datasets/dataSetTable/dataSetSection/TableDataToTableModelMapper.kt @@ -1,14 +1,15 @@ package org.dhis2.usescases.datasets.dataSetTable.dataSetSection import org.dhis2.R -import org.dhis2.composetable.model.RowHeader -import org.dhis2.composetable.model.TableCell -import org.dhis2.composetable.model.TableHeader -import org.dhis2.composetable.model.TableHeaderCell -import org.dhis2.composetable.model.TableHeaderRow -import org.dhis2.composetable.model.TableModel -import org.dhis2.composetable.model.TableRowModel + import org.hisp.dhis.android.core.common.ValueType +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.model.RowHeader +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.model.TableCell +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.model.TableHeader +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.model.TableHeaderCell +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.model.TableHeaderRow +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.model.TableModel +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.model.TableRowModel import java.util.SortedMap class TableDataToTableModelMapper(val mapFieldValueToUser: MapFieldValueToUser) { diff --git a/app/src/main/java/org/dhis2/usescases/datasets/dataSetTable/dataSetSection/TableDimensionStore.kt b/app/src/main/java/org/dhis2/usescases/datasets/dataSetTable/dataSetSection/TableDimensionStore.kt index 9d25774a21..6a774134c6 100644 --- a/app/src/main/java/org/dhis2/usescases/datasets/dataSetTable/dataSetSection/TableDimensionStore.kt +++ b/app/src/main/java/org/dhis2/usescases/datasets/dataSetTable/dataSetSection/TableDimensionStore.kt @@ -1,7 +1,7 @@ package org.dhis2.usescases.datasets.dataSetTable.dataSetSection -import org.dhis2.composetable.model.TableModel import org.hisp.dhis.android.core.D2 +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.model.TableModel class TableDimensionStore( val d2: D2, diff --git a/app/src/main/java/org/dhis2/usescases/datasets/dataSetTable/dataSetSection/ValueTypeToKeyboardInputTypeMapper.kt b/app/src/main/java/org/dhis2/usescases/datasets/dataSetTable/dataSetSection/ValueTypeToKeyboardInputTypeMapper.kt index 40b6e2ef30..b7c9c2225e 100644 --- a/app/src/main/java/org/dhis2/usescases/datasets/dataSetTable/dataSetSection/ValueTypeToKeyboardInputTypeMapper.kt +++ b/app/src/main/java/org/dhis2/usescases/datasets/dataSetTable/dataSetSection/ValueTypeToKeyboardInputTypeMapper.kt @@ -1,7 +1,7 @@ package org.dhis2.usescases.datasets.dataSetTable.dataSetSection -import org.dhis2.composetable.model.KeyboardInputType import org.hisp.dhis.android.core.common.ValueType +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.model.KeyboardInputType fun ValueType.toKeyBoardInputType(): KeyboardInputType? { return when (this) { diff --git a/commons/build.gradle.kts b/commons/build.gradle.kts index 546f96cceb..3ac2dfe20a 100644 --- a/commons/build.gradle.kts +++ b/commons/build.gradle.kts @@ -126,6 +126,7 @@ dependencies { api(libs.analytics.sentry.compose) implementation(libs.github.treeView) api(libs.dhis2.mobile.designsystem) { + exclude(group = "tech.annexflow.compose", module = "constraintlayout-compose-multiplatform-android") isChanging = true } coreLibraryDesugaring(libs.desugar) diff --git a/compose-table/build.gradle.kts b/compose-table/build.gradle.kts index 0d8159c902..75830d48c4 100644 --- a/compose-table/build.gradle.kts +++ b/compose-table/build.gradle.kts @@ -50,9 +50,11 @@ kotlin { } dependencies { - implementation(libs.bundles.table.implementation) debugImplementation(libs.bundles.table.debugImplementation) testImplementation(libs.bundles.table.test) androidTestImplementation(libs.bundles.table.androidTest) - implementation(libs.dhis2.mobile.designsystem) + implementation(libs.dhis2.mobile.designsystem) { + exclude(group = "tech.annexflow.compose", module = "constraintlayout-compose-multiplatform-android") + + } } diff --git a/compose-table/src/main/java/org/dhis2/composetable/TableScreenState.kt b/compose-table/src/main/java/org/dhis2/composetable/TableScreenState.kt deleted file mode 100644 index a558287e25..0000000000 --- a/compose-table/src/main/java/org/dhis2/composetable/TableScreenState.kt +++ /dev/null @@ -1,25 +0,0 @@ -package org.dhis2.composetable - -import org.dhis2.composetable.model.TableModel -import java.util.UUID - -data class TableScreenState( - val tables: List, - val id: UUID = UUID.randomUUID(), - val state: TableState = TableState.LOADING, -) - -data class TableConfigurationState( - val overwrittenTableWidth: Map? = null, - val overwrittenRowHeaderWidth: Map? = null, - val overwrittenColumnWidth: Map>? = null, -) { - fun isResized() = !overwrittenTableWidth.isNullOrEmpty() or - !overwrittenRowHeaderWidth.isNullOrEmpty() or - !overwrittenColumnWidth.isNullOrEmpty() -} - -enum class TableState { - LOADING, - SUCCESS, -} diff --git a/compose-table/src/main/java/org/dhis2/composetable/actions/DefaultValidator.kt b/compose-table/src/main/java/org/dhis2/composetable/actions/DefaultValidator.kt deleted file mode 100644 index 76cc91c144..0000000000 --- a/compose-table/src/main/java/org/dhis2/composetable/actions/DefaultValidator.kt +++ /dev/null @@ -1,3 +0,0 @@ -package org.dhis2.composetable.actions - -class DefaultValidator : Validator diff --git a/compose-table/src/main/java/org/dhis2/composetable/actions/TableInteractions.kt b/compose-table/src/main/java/org/dhis2/composetable/actions/TableInteractions.kt deleted file mode 100644 index 86068b6e63..0000000000 --- a/compose-table/src/main/java/org/dhis2/composetable/actions/TableInteractions.kt +++ /dev/null @@ -1,12 +0,0 @@ -package org.dhis2.composetable.actions - -import org.dhis2.composetable.model.TableCell -import org.dhis2.composetable.model.TableDialogModel -import org.dhis2.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 { } -} diff --git a/compose-table/src/main/java/org/dhis2/composetable/actions/TableResizeActions.kt b/compose-table/src/main/java/org/dhis2/composetable/actions/TableResizeActions.kt deleted file mode 100644 index 43c10d1b1d..0000000000 --- a/compose-table/src/main/java/org/dhis2/composetable/actions/TableResizeActions.kt +++ /dev/null @@ -1,9 +0,0 @@ -package org.dhis2.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 {} -} diff --git a/compose-table/src/main/java/org/dhis2/composetable/actions/TextInputInteractions.kt b/compose-table/src/main/java/org/dhis2/composetable/actions/TextInputInteractions.kt deleted file mode 100644 index e295096786..0000000000 --- a/compose-table/src/main/java/org/dhis2/composetable/actions/TextInputInteractions.kt +++ /dev/null @@ -1,9 +0,0 @@ -package org.dhis2.composetable.actions - -import org.dhis2.composetable.model.TextInputModel - -interface TextInputInteractions { - fun onTextChanged(textInputModel: TextInputModel) = run {} - fun onSave() = run {} - fun onNextSelected() = run {} -} diff --git a/compose-table/src/main/java/org/dhis2/composetable/actions/Validator.kt b/compose-table/src/main/java/org/dhis2/composetable/actions/Validator.kt deleted file mode 100644 index dc80fe8fbe..0000000000 --- a/compose-table/src/main/java/org/dhis2/composetable/actions/Validator.kt +++ /dev/null @@ -1,10 +0,0 @@ -package org.dhis2.composetable.actions - -import org.dhis2.composetable.model.TableCell -import org.dhis2.composetable.model.ValidationResult - -interface Validator { - fun validate(tableCell: TableCell): ValidationResult { - return ValidationResult.Success(tableCell.value) - } -} diff --git a/compose-table/src/main/java/org/dhis2/composetable/model/DropdownOption.kt b/compose-table/src/main/java/org/dhis2/composetable/model/DropdownOption.kt deleted file mode 100644 index 20b2147e87..0000000000 --- a/compose-table/src/main/java/org/dhis2/composetable/model/DropdownOption.kt +++ /dev/null @@ -1,9 +0,0 @@ -package org.dhis2.composetable.model - -import kotlinx.serialization.Serializable - -@Serializable -data class DropdownOption( - val code: String, - val name: String, -) diff --git a/compose-table/src/main/java/org/dhis2/composetable/model/HeaderMeasures.kt b/compose-table/src/main/java/org/dhis2/composetable/model/HeaderMeasures.kt deleted file mode 100644 index f3ee35a3e4..0000000000 --- a/compose-table/src/main/java/org/dhis2/composetable/model/HeaderMeasures.kt +++ /dev/null @@ -1,3 +0,0 @@ -package org.dhis2.composetable.model - -data class HeaderMeasures(val width: Int, val height: Int) diff --git a/compose-table/src/main/java/org/dhis2/composetable/model/ItemColumnHeaderUiState.kt b/compose-table/src/main/java/org/dhis2/composetable/model/ItemColumnHeaderUiState.kt deleted file mode 100644 index e5607b045e..0000000000 --- a/compose-table/src/main/java/org/dhis2/composetable/model/ItemColumnHeaderUiState.kt +++ /dev/null @@ -1,23 +0,0 @@ -package org.dhis2.composetable.model - -import androidx.compose.foundation.layout.PaddingValues -import org.dhis2.composetable.ui.CellStyle -import org.dhis2.composetable.ui.TableDimensions -import org.dhis2.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" -} diff --git a/compose-table/src/main/java/org/dhis2/composetable/model/ItemHeaderUiState.kt b/compose-table/src/main/java/org/dhis2/composetable/model/ItemHeaderUiState.kt deleted file mode 100644 index 72d7e8cbf2..0000000000 --- a/compose-table/src/main/java/org/dhis2/composetable/model/ItemHeaderUiState.kt +++ /dev/null @@ -1,16 +0,0 @@ -package org.dhis2.composetable.model - -import androidx.compose.ui.unit.Dp -import org.dhis2.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, -) diff --git a/compose-table/src/main/java/org/dhis2/composetable/model/KeyboardInputType.kt b/compose-table/src/main/java/org/dhis2/composetable/model/KeyboardInputType.kt deleted file mode 100644 index 5458c29e8d..0000000000 --- a/compose-table/src/main/java/org/dhis2/composetable/model/KeyboardInputType.kt +++ /dev/null @@ -1,38 +0,0 @@ -package org.dhis2.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) -} diff --git a/compose-table/src/main/java/org/dhis2/composetable/model/ResizingCell.kt b/compose-table/src/main/java/org/dhis2/composetable/model/ResizingCell.kt deleted file mode 100644 index 383bff68af..0000000000 --- a/compose-table/src/main/java/org/dhis2/composetable/model/ResizingCell.kt +++ /dev/null @@ -1,8 +0,0 @@ -package org.dhis2.composetable.model - -import androidx.compose.ui.geometry.Offset - -data class ResizingCell( - val initialPosition: Offset, - val draggingOffsetX: Float, -) diff --git a/compose-table/src/main/java/org/dhis2/composetable/model/RowHeader.kt b/compose-table/src/main/java/org/dhis2/composetable/model/RowHeader.kt deleted file mode 100644 index b3a48c9afa..0000000000 --- a/compose-table/src/main/java/org/dhis2/composetable/model/RowHeader.kt +++ /dev/null @@ -1,12 +0,0 @@ -package org.dhis2.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, -) diff --git a/compose-table/src/main/java/org/dhis2/composetable/model/TableCell.kt b/compose-table/src/main/java/org/dhis2/composetable/model/TableCell.kt deleted file mode 100644 index 1a68a29db1..0000000000 --- a/compose-table/src/main/java/org/dhis2/composetable/model/TableCell.kt +++ /dev/null @@ -1,21 +0,0 @@ -package org.dhis2.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 -} diff --git a/compose-table/src/main/java/org/dhis2/composetable/model/TableCornerUiState.kt b/compose-table/src/main/java/org/dhis2/composetable/model/TableCornerUiState.kt deleted file mode 100644 index 7a9779f563..0000000000 --- a/compose-table/src/main/java/org/dhis2/composetable/model/TableCornerUiState.kt +++ /dev/null @@ -1,8 +0,0 @@ -package org.dhis2.composetable.model - -data class TableCornerUiState( - val isSelected: Boolean = false, - val onTableResize: (Float) -> Unit, - val onResizing: (ResizingCell?) -> Unit, - val singleValueTable: Boolean = false, -) diff --git a/compose-table/src/main/java/org/dhis2/composetable/model/TableDialogModel.kt b/compose-table/src/main/java/org/dhis2/composetable/model/TableDialogModel.kt deleted file mode 100644 index 25245593c5..0000000000 --- a/compose-table/src/main/java/org/dhis2/composetable/model/TableDialogModel.kt +++ /dev/null @@ -1,6 +0,0 @@ -package org.dhis2.composetable.model - -data class TableDialogModel( - val title: String, - val message: String, -) diff --git a/compose-table/src/main/java/org/dhis2/composetable/model/TableHeader.kt b/compose-table/src/main/java/org/dhis2/composetable/model/TableHeader.kt deleted file mode 100644 index fbff7a5992..0000000000 --- a/compose-table/src/main/java/org/dhis2/composetable/model/TableHeader.kt +++ /dev/null @@ -1,16 +0,0 @@ -package org.dhis2.composetable.model - -import kotlinx.serialization.Serializable - -@Serializable -data class TableHeader(val rows: List, 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) -} diff --git a/compose-table/src/main/java/org/dhis2/composetable/model/TableHeaderCell.kt b/compose-table/src/main/java/org/dhis2/composetable/model/TableHeaderCell.kt deleted file mode 100644 index 438d3165b1..0000000000 --- a/compose-table/src/main/java/org/dhis2/composetable/model/TableHeaderCell.kt +++ /dev/null @@ -1,6 +0,0 @@ -package org.dhis2.composetable.model - -import kotlinx.serialization.Serializable - -@Serializable -data class TableHeaderCell(val value: String) diff --git a/compose-table/src/main/java/org/dhis2/composetable/model/TableHeaderRow.kt b/compose-table/src/main/java/org/dhis2/composetable/model/TableHeaderRow.kt deleted file mode 100644 index a1eecf5778..0000000000 --- a/compose-table/src/main/java/org/dhis2/composetable/model/TableHeaderRow.kt +++ /dev/null @@ -1,6 +0,0 @@ -package org.dhis2.composetable.model - -import kotlinx.serialization.Serializable - -@Serializable -data class TableHeaderRow(val cells: List) 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 deleted file mode 100644 index c38a32ff77..0000000000 --- a/compose-table/src/main/java/org/dhis2/composetable/model/TableModel.kt +++ /dev/null @@ -1,74 +0,0 @@ -package org.dhis2.composetable.model - -import kotlinx.serialization.Serializable -import org.dhis2.composetable.ui.TableSelection - -@Serializable -data class TableModel( - val id: String? = null, - val title: String = "", - val tableHeaderModel: TableHeader, - val tableRows: List, - val overwrittenValues: Map = emptyMap(), -) { - fun countChildrenOfSelectedHeader( - headerRowIndex: Int, - headerColumnIndex: Int, - ): Map { - 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? = 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 } - } - } - - fun hasCellWithId(cellId: String?): Boolean { - return tableRows.any { row -> - row.rowHeader.id?.let { - it.isNotEmpty() && cellId?.contains(it) == true - } ?: false - } - } -} diff --git a/compose-table/src/main/java/org/dhis2/composetable/model/TableRowModel.kt b/compose-table/src/main/java/org/dhis2/composetable/model/TableRowModel.kt deleted file mode 100644 index 5d9c32b9c6..0000000000 --- a/compose-table/src/main/java/org/dhis2/composetable/model/TableRowModel.kt +++ /dev/null @@ -1,12 +0,0 @@ -package org.dhis2.composetable.model - -import kotlinx.serialization.Serializable - -@Serializable -data class TableRowModel( - val rowHeader: RowHeader, - val values: Map, - val isLastRow: Boolean = false, - val maxLines: Int = 3, - val dropDownOptions: List? = null, -) diff --git a/compose-table/src/main/java/org/dhis2/composetable/model/TextInputModel.kt b/compose-table/src/main/java/org/dhis2/composetable/model/TextInputModel.kt deleted file mode 100644 index fc3d10d08f..0000000000 --- a/compose-table/src/main/java/org/dhis2/composetable/model/TextInputModel.kt +++ /dev/null @@ -1,24 +0,0 @@ -package org.dhis2.composetable.model - -import androidx.compose.ui.text.TextRange - -data class TextInputModel( - val id: String = "", - val mainLabel: String = "", - val secondaryLabels: List = emptyList(), - val helperText: String? = null, - val currentValue: String? = null, - val keyboardInputType: KeyboardInputType = KeyboardInputType.TextInput(), - val selection: TextRange? = null, - val error: String? = null, - val warning: String? = null, - private val clearable: Boolean = false, -) { - fun showClearButton() = clearable && currentValue?.isNotEmpty() == true - fun errorOrWarningMessage() = error ?: warning - fun hasErrorOrWarning() = errorOrWarningMessage() != null - - fun actionIconCanBeClicked(hasFocus: Boolean) = hasFocus && error == null - - fun hasHelperText() = helperText?.isNotEmpty() ?: false -} diff --git a/compose-table/src/main/java/org/dhis2/composetable/model/ValidationResult.kt b/compose-table/src/main/java/org/dhis2/composetable/model/ValidationResult.kt deleted file mode 100644 index 173280a301..0000000000 --- a/compose-table/src/main/java/org/dhis2/composetable/model/ValidationResult.kt +++ /dev/null @@ -1,6 +0,0 @@ -package org.dhis2.composetable.model - -sealed class ValidationResult { - data class Success(val value: String?) : ValidationResult() - data class Error(val message: String) : ValidationResult() -} diff --git a/compose-table/src/main/java/org/dhis2/composetable/model/extensions/KeyboardInputTypeExtensions.kt b/compose-table/src/main/java/org/dhis2/composetable/model/extensions/KeyboardInputTypeExtensions.kt deleted file mode 100644 index 8187725dd0..0000000000 --- a/compose-table/src/main/java/org/dhis2/composetable/model/extensions/KeyboardInputTypeExtensions.kt +++ /dev/null @@ -1,19 +0,0 @@ -package org.dhis2.composetable.model.extensions - -import androidx.compose.ui.text.input.KeyboardCapitalization -import androidx.compose.ui.text.input.KeyboardType -import org.dhis2.composetable.model.KeyboardInputType - -fun KeyboardInputType.toKeyboardType(): KeyboardType = when (this) { - is KeyboardInputType.NumericInput -> KeyboardType.Number - is KeyboardInputType.NumberPassword -> KeyboardType.NumberPassword - is KeyboardInputType.EmailInput -> KeyboardType.Email - is KeyboardInputType.TextInput -> KeyboardType.Text - is KeyboardInputType.PhoneInput -> KeyboardType.Phone - is KeyboardInputType.URLInput -> KeyboardType.Uri -} - -fun KeyboardInputType.keyboardCapitalization() = when { - forceCapitalize -> KeyboardCapitalization.Characters - else -> KeyboardCapitalization.None -} diff --git a/compose-table/src/main/java/org/dhis2/composetable/model/extensions/TableModelExtensions.kt b/compose-table/src/main/java/org/dhis2/composetable/model/extensions/TableModelExtensions.kt deleted file mode 100644 index 0078b19685..0000000000 --- a/compose-table/src/main/java/org/dhis2/composetable/model/extensions/TableModelExtensions.kt +++ /dev/null @@ -1,13 +0,0 @@ -package org.dhis2.composetable.model.extensions - -import org.dhis2.composetable.model.TableModel - -fun TableModel.areAllValuesEmpty(): Boolean { - this.tableRows.forEach { row -> - val result = row.values.values.filterNot { it.value == "" } - if (result.isNotEmpty()) { - return false - } - } - return true -} diff --git a/compose-table/src/main/java/org/dhis2/composetable/ui/CellLegend.kt b/compose-table/src/main/java/org/dhis2/composetable/ui/CellLegend.kt deleted file mode 100644 index 11c37682cc..0000000000 --- a/compose-table/src/main/java/org/dhis2/composetable/ui/CellLegend.kt +++ /dev/null @@ -1,55 +0,0 @@ -package org.dhis2.composetable.ui - -import androidx.compose.foundation.background -import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.BoxScope -import androidx.compose.foundation.layout.height -import androidx.compose.foundation.layout.width -import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier -import androidx.compose.ui.draw.clip -import androidx.compose.ui.draw.drawBehind -import androidx.compose.ui.geometry.Offset -import androidx.compose.ui.geometry.Size -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.tooling.preview.Preview -import androidx.compose.ui.unit.dp - -@Composable -fun CellLegendBox( - modifier: Modifier = Modifier, - legendColor: Color?, - content: @Composable - BoxScope.() -> Unit, -) { - val boxModifier = legendColor?.let { - val cornerSize = LocalTableDimensions.current.defaultLegendCornerSize - val borderWidth = LocalTableDimensions.current.defaultLegendBorderWidth - modifier - .clip(shape = RoundedCornerShape(size = cornerSize)) - .drawBehind { - drawRect( - color = legendColor, - topLeft = Offset(0f, 0f), - size = Size(borderWidth.toPx(), size.height), - ) - } - .background(color = legendColor.copy(alpha = 0.15f)) - } ?: modifier - Box( - modifier = boxModifier, - content = content, - ) -} - -@Composable -@Preview -fun CellLegendPreview() { - CellLegendBox( - modifier = Modifier - .width(44.dp) - .height(16.dp), - legendColor = Color(44, 152, 240), - ) {} -} diff --git a/compose-table/src/main/java/org/dhis2/composetable/ui/CellStyle.kt b/compose-table/src/main/java/org/dhis2/composetable/ui/CellStyle.kt deleted file mode 100644 index 8344d0dff8..0000000000 --- a/compose-table/src/main/java/org/dhis2/composetable/ui/CellStyle.kt +++ /dev/null @@ -1,85 +0,0 @@ -package org.dhis2.composetable.ui - -import androidx.compose.runtime.Composable -import androidx.compose.ui.graphics.Color - -sealed class CellStyle { - data class HeaderStyle(val backgroundColor: Color, val textColor: Color) : CellStyle() - data class CellBorderStyle(val backgroundColor: Color, val borderColor: Color) : CellStyle() - - fun backgroundColor() = when (this) { - is CellBorderStyle -> backgroundColor - is HeaderStyle -> backgroundColor - } - - fun mainColor() = when (this) { - is CellBorderStyle -> borderColor - is HeaderStyle -> textColor - } -} - -@Composable -fun styleForColumnHeader( - isSelected: Boolean, - isParentSelected: Boolean, - columnIndex: Int, -): CellStyle = when { - isSelected -> CellStyle.HeaderStyle( - backgroundColor = LocalTableColors.current.primary, - textColor = LocalTableColors.current.onPrimary, - ) - isParentSelected -> CellStyle.HeaderStyle( - backgroundColor = LocalTableColors.current.primaryLight, - textColor = LocalTableColors.current.headerText, - ) - columnIndex % 2 == 0 -> CellStyle.HeaderStyle( - backgroundColor = LocalTableColors.current.headerBackground1, - textColor = LocalTableColors.current.headerText, - ) - else -> - CellStyle.HeaderStyle( - backgroundColor = LocalTableColors.current.headerBackground2, - textColor = LocalTableColors.current.headerText, - ) -} - -@Composable -fun styleForRowHeader(isSelected: Boolean, isOtherRowSelected: Boolean): CellStyle = when { - isSelected -> CellStyle.HeaderStyle( - TableTheme.colors.primary, - TableTheme.colors.onPrimary, - ) - isOtherRowSelected -> CellStyle.HeaderStyle( - TableTheme.colors.primaryLight, - TableTheme.colors.primary, - ) - else -> CellStyle.HeaderStyle( - backgroundColor = TableTheme.colors.tableBackground, - textColor = TableTheme.colors.primary, - ) -} - -fun styleForCell( - tableColorProvider: () -> TableColors, - isSelected: Boolean, - isParentSelected: Boolean, - hasError: Boolean, - hasWarning: Boolean, - isEditable: Boolean, - legendColor: Int?, -) = CellStyle.CellBorderStyle( - borderColor = when { - isSelected && hasError -> tableColorProvider().errorColor - isSelected && hasWarning -> tableColorProvider().warningColor - isSelected -> tableColorProvider().primary - else -> Color.Transparent - }, - backgroundColor = when { - legendColor != null -> Color.Transparent - !isEditable && isParentSelected -> tableColorProvider().disabledSelectedBackground - isParentSelected -> tableColorProvider().primaryLight - !isEditable -> tableColorProvider().disabledCellBackground - isSelected -> tableColorProvider().tableBackground - else -> tableColorProvider().tableBackground - }, -) diff --git a/compose-table/src/main/java/org/dhis2/composetable/ui/DataSetTableScreen.kt b/compose-table/src/main/java/org/dhis2/composetable/ui/DataSetTableScreen.kt deleted file mode 100644 index 315b7e7b50..0000000000 --- a/compose-table/src/main/java/org/dhis2/composetable/ui/DataSetTableScreen.kt +++ /dev/null @@ -1,336 +0,0 @@ -package org.dhis2.composetable.ui - -import androidx.activity.compose.BackHandler -import androidx.compose.animation.AnimatedVisibility -import androidx.compose.animation.fadeIn -import androidx.compose.animation.fadeOut -import androidx.compose.foundation.background -import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.fillMaxHeight -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.material.BottomSheetScaffold -import androidx.compose.material.BottomSheetValue -import androidx.compose.material.CircularProgressIndicator -import androidx.compose.material.ExperimentalMaterialApi -import androidx.compose.material.Icon -import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.outlined.ErrorOutline -import androidx.compose.material.rememberBottomSheetScaffoldState -import androidx.compose.material.rememberBottomSheetState -import androidx.compose.runtime.Composable -import androidx.compose.runtime.CompositionLocalProvider -import androidx.compose.runtime.LaunchedEffect -import androidx.compose.runtime.derivedStateOf -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember -import androidx.compose.runtime.rememberCoroutineScope -import androidx.compose.runtime.setValue -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.focus.FocusRequester -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.platform.LocalFocusManager -import androidx.compose.ui.platform.testTag -import androidx.compose.ui.unit.dp -import kotlinx.coroutines.launch -import org.dhis2.composetable.TableScreenState -import org.dhis2.composetable.TableState -import org.dhis2.composetable.actions.TableInteractions -import org.dhis2.composetable.actions.TextInputInteractions -import org.dhis2.composetable.model.TableCell -import org.dhis2.composetable.model.TableDialogModel -import org.dhis2.composetable.model.TextInputModel -import org.dhis2.composetable.model.ValidationResult -import org.dhis2.composetable.ui.compositions.LocalCurrentCellValue -import org.dhis2.composetable.ui.compositions.LocalInteraction -import org.dhis2.composetable.ui.compositions.LocalUpdatingCell -import org.dhis2.composetable.ui.extensions.collapseIfExpanded -import org.dhis2.composetable.ui.extensions.expandIfCollapsed -import org.hisp.dhis.mobile.ui.designsystem.component.AdditionalInfoItemColor -import org.hisp.dhis.mobile.ui.designsystem.component.InfoBar -import org.hisp.dhis.mobile.ui.designsystem.component.InfoBarData - -@OptIn(ExperimentalMaterialApi::class) -@Composable -fun DataSetTableScreen( - tableScreenState: TableScreenState, - onCellClick: ( - tableId: String, - TableCell, - updateCellValue: (TableCell) -> Unit, - ) -> TextInputModel?, - emptyTablesText: String? = null, - onEdition: (editing: Boolean) -> Unit, - onSaveValue: (TableCell) -> Unit, - bottomContent: @Composable (() -> Unit)? = null, -) { - val bottomSheetState = rememberBottomSheetScaffoldState( - bottomSheetState = rememberBottomSheetState(initialValue = BottomSheetValue.Collapsed), - ) - - var currentCell by remember { mutableStateOf(null) } - var updatingCell by remember { mutableStateOf(null) } - var currentInputType by remember { mutableStateOf(TextInputModel()) } - var displayDescription by remember { mutableStateOf(null) } - val coroutineScope = rememberCoroutineScope() - var tableSelection by remember { mutableStateOf(TableSelection.Unselected()) } - - val focusManager = LocalFocusManager.current - val tableConfiguration = LocalTableConfiguration.current - val focusRequester = remember { FocusRequester() } - - var alreadyFinish by remember { mutableStateOf(false) } - - val isKeyboardOpen by keyboardAsState() - - fun finishEdition() { - focusManager.clearFocus(true) - tableSelection = TableSelection.Unselected() - onEdition(false) - } - - fun collapseBottomSheet(finish: Boolean = false) { - focusManager.clearFocus(true) - coroutineScope.launch { - bottomSheetState.bottomSheetState.collapseIfExpanded { - if (finish) { - finishEdition() - } - alreadyFinish = true - } - } - } - - fun startEdition() { - coroutineScope.launch { - bottomSheetState.bottomSheetState.expandIfCollapsed { onEdition(true) } - } - alreadyFinish = false - } - - fun updateError(tableCell: TableCell) { - currentInputType = currentInputType.copy(error = tableCell.error) - currentCell = currentCell?.copy(error = tableCell.error) - } - - fun updateCellValue(tableCell: TableCell?) { - currentCell = tableCell - } - - var saveClicked by remember { mutableStateOf(false) } - - if (saveClicked) { - (tableSelection as? TableSelection.CellSelection)?.let { cellSelected -> - val currentTable = tableScreenState.tables.firstOrNull { it.id == cellSelected.tableId } - currentTable?.cellHasError(cellSelected)?.let { - updateError(it) - saveClicked = false - } - } - } - bottomSheetState.bottomSheetState.progress - BackHandler( - bottomSheetState.bottomSheetState.isExpanded && - bottomSheetState.bottomSheetState.progress == 1f, - ) { - collapseBottomSheet(finish = true) - } - - LaunchedEffect(bottomSheetState.bottomSheetState.currentValue) { - if ( - bottomSheetState.bottomSheetState.currentValue == BottomSheetValue.Collapsed && - !alreadyFinish - ) { - finishEdition() - } - } - - LaunchedEffect(isKeyboardOpen) { - if (isKeyboardOpen == Keyboard.Closed) { - if (tableConfiguration.textInputViewMode) { - focusManager.clearFocus(true) - } else if (bottomSheetState.bottomSheetState.isExpanded) { - collapseBottomSheet(true) - bottomSheetState.bottomSheetState.collapse() - } - } - } - - val iter by remember { - mutableStateOf( - object : TableInteractions { - override fun onSelectionChange(newTableSelection: TableSelection) { - tableSelection = newTableSelection - } - - override fun onDecorationClick(dialogModel: TableDialogModel) { - displayDescription = dialogModel - } - - override fun onClick(tableCell: TableCell) { - currentCell?.takeIf { it != tableCell }?.let { onSaveValue(it) } - updatingCell = currentCell - onCellClick( - tableSelection.tableId, - tableCell, - ) { updateCellValue(it) }?.let { inputModel -> - currentCell = tableCell - currentInputType = - inputModel.copy(currentValue = currentCell?.value) - startEdition() - focusRequester.requestFocus() - } ?: collapseBottomSheet() - } - - override fun onOptionSelected(cell: TableCell, code: String, label: String) { - currentCell = cell.copy( - value = label, - error = null, - ).also { - onSaveValue(cell.copy(value = code)) - } - } - }, - ) - } - - BottomSheetScaffold( - scaffoldState = bottomSheetState, - sheetContent = { - val validator = TableTheme.validator - val textInputInteractions by remember(tableScreenState) { - derivedStateOf { - object : TextInputInteractions { - override fun onTextChanged(textInputModel: TextInputModel) { - currentInputType = textInputModel - currentCell = currentCell?.copy( - value = textInputModel.currentValue, - error = null, - ) - } - - override fun onSave() { - if (!tableConfiguration.textInputViewMode) { - collapseBottomSheet(true) - } - currentCell?.let { onSaveValue(it) } - saveClicked = true - } - - override fun onNextSelected() { - currentCell?.let { tableCell -> - val result = validator.validate(tableCell) - onSaveValue(tableCell) - (tableSelection as? TableSelection.CellSelection) - ?.let { cellSelected -> - val currentTable = tableScreenState.tables.first { - it.id == cellSelected.tableId - } - currentTable.getNextCell( - cellSelection = cellSelected, - successValidation = result is ValidationResult.Success, - )?.let { (tableCell, nextCell) -> - if (nextCell != cellSelected) { - updatingCell = currentCell - tableSelection = nextCell - onCellClick( - tableSelection.tableId, - tableCell, - ) { updateCellValue(it) }?.let { inputModel -> - currentCell = tableCell - currentInputType = inputModel - focusRequester.requestFocus() - } ?: collapseBottomSheet() - } else { - updateError(tableCell) - } - } ?: collapseBottomSheet(finish = true) - } - } - } - } - } - } - TextInput( - textInputModel = currentInputType, - textInputInteractions = textInputInteractions, - focusRequester = focusRequester, - ) - }, - sheetPeekHeight = 0.dp, - sheetShape = RoundedCornerShape( - topStart = 16.dp, - topEnd = 16.dp, - ), - ) { - AnimatedVisibility( - visible = tableScreenState.state == TableState.LOADING, - enter = fadeIn(), - exit = fadeOut(), - ) { - Box( - modifier = Modifier - .fillMaxHeight() - .fillMaxWidth() - .background(Color.White), - contentAlignment = Alignment.Center, - ) { - CircularProgressIndicator() - } - } - CompositionLocalProvider( - LocalTableSelection provides tableSelection, - LocalCurrentCellValue provides { currentCell?.value }, - LocalUpdatingCell provides updatingCell, - LocalInteraction provides iter, - ) { - if (tableScreenState.state == TableState.SUCCESS && tableScreenState.tables.isEmpty()) { - Column( - modifier = Modifier.fillMaxWidth() - .padding(16.dp), - horizontalAlignment = Alignment.CenterHorizontally, - ) { - InfoBar( - infoBarData = InfoBarData( - text = emptyTablesText ?: "", - icon = { - Icon( - imageVector = Icons.Outlined.ErrorOutline, - contentDescription = "warning", - tint = AdditionalInfoItemColor.WARNING.color, - ) - }, - color = AdditionalInfoItemColor.WARNING.color, - backgroundColor = AdditionalInfoItemColor.WARNING.color.copy(alpha = 0.1f), - actionText = null, - onClick = {}, - ), - Modifier.testTag(EMPTY_TABLE_TEXT_TAG), - ) - } - } else { - DataTable( - tableList = tableScreenState.tables, - bottomContent = bottomContent, - ) - } - } - displayDescription?.let { - TableDialog( - dialogModel = it, - onDismiss = { - displayDescription = null - }, - onPrimaryButtonClick = { - displayDescription = null - }, - ) - } - } -} - -const val EMPTY_TABLE_TEXT_TAG = "EMPTY_TABLE_TEXT_TAG" diff --git a/compose-table/src/main/java/org/dhis2/composetable/ui/DataTable.kt b/compose-table/src/main/java/org/dhis2/composetable/ui/DataTable.kt deleted file mode 100644 index 365b5ca459..0000000000 --- a/compose-table/src/main/java/org/dhis2/composetable/ui/DataTable.kt +++ /dev/null @@ -1,152 +0,0 @@ -package org.dhis2.composetable.ui - -import androidx.compose.foundation.background -import androidx.compose.foundation.layout.height -import androidx.compose.foundation.rememberScrollState -import androidx.compose.runtime.Composable -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember -import androidx.compose.runtime.setValue -import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.platform.LocalDensity -import org.dhis2.composetable.model.ResizingCell -import org.dhis2.composetable.model.TableCornerUiState -import org.dhis2.composetable.model.TableModel -import org.dhis2.composetable.ui.TableTheme.tableSelection -import org.dhis2.composetable.ui.compositions.LocalInteraction -import org.dhis2.composetable.ui.compositions.LocalTableResizeActions - -@Composable -fun DataTable(tableList: List, bottomContent: @Composable (() -> Unit)? = null) { - val tableResizeActions = LocalTableResizeActions.current - val tableInteractions = LocalInteraction.current - var resizingCell: ResizingCell? by remember { mutableStateOf(null) } - val horizontalScrollStates = tableList.map { rememberScrollState() } - - Table( - tableList = tableList, - tableHeaderRow = { index, tableModel -> - val isSingleValue = tableModel.tableRows.firstOrNull()?.values?.size == 1 - TableHeaderRow( - modifier = Modifier - .background(Color.White), - cornerUiState = TableCornerUiState( - isSelected = tableSelection.isCornerSelected(tableModel.id ?: ""), - onTableResize = { - if (isSingleValue) { - tableResizeActions.onRowHeaderResize( - tableModel.id ?: "", - it, - ) - } else { - tableResizeActions.onTableDimensionResize( - tableModel.id ?: "", - it, - ) - } - }, - onResizing = { resizingCell = it }, - singleValueTable = isSingleValue, - ), - tableModel = tableModel, - horizontalScrollState = horizontalScrollStates[index], - cellStyle = { columnIndex, rowIndex -> - styleForColumnHeader( - isSelected = tableSelection.isHeaderSelected( - selectedTableId = tableModel.id ?: "", - columnIndex = columnIndex, - columnHeaderRowIndex = rowIndex, - ), - isParentSelected = tableSelection.isParentHeaderSelected( - selectedTableId = tableModel.id ?: "", - columnIndex = columnIndex, - columnHeaderRowIndex = rowIndex, - ), - columnIndex = columnIndex, - ) - }, - onTableCornerClick = { - tableInteractions.onSelectionChange( - TableSelection.AllCellSelection(tableModel.id ?: ""), - ) - }, - onHeaderCellClick = { headerColumnIndex, headerRowIndex -> - tableInteractions.onSelectionChange( - TableSelection.ColumnSelection( - tableId = tableModel.id ?: "", - columnIndex = headerColumnIndex, - columnHeaderRow = headerRowIndex, - childrenOfSelectedHeader = - tableModel.countChildrenOfSelectedHeader( - headerRowIndex, - headerColumnIndex, - ), - ), - ) - }, - onHeaderResize = { column, width -> - tableResizeActions.onColumnHeaderResize( - tableModel.id ?: "", - column, - width, - ) - }, - onResizing = { resizingCell = it }, - onResetResize = { - tableResizeActions.onTableDimensionReset(tableModel.id ?: "") - }, - ) - }, - tableItemRow = { index, tableModel, tableRowModel -> - TableItemRow( - tableModel = tableModel, - horizontalScrollState = horizontalScrollStates[index], - rowModel = tableRowModel, - rowHeaderCellStyle = { rowHeaderIndex -> - styleForRowHeader( - isSelected = tableSelection.isRowSelected( - selectedTableId = tableModel.id ?: "", - rowHeaderIndex = rowHeaderIndex ?: -1, - ), - isOtherRowSelected = tableSelection.isOtherRowSelected( - selectedTableId = tableModel.id ?: "", - rowHeaderIndex = rowHeaderIndex ?: -1, - ), - ) - }, - onRowHeaderClick = { rowHeaderIndex -> - tableInteractions.onSelectionChange( - TableSelection.RowSelection( - tableId = tableModel.id ?: "", - rowIndex = rowHeaderIndex ?: -1, - ), - ) - }, - onDecorationClick = { tableInteractions.onDecorationClick(it) }, - onHeaderResize = { width -> - tableResizeActions.onRowHeaderResize( - tableModel.id ?: "", - width, - ) - }, - onResizing = { resizingCell = it }, - ) - }, - verticalResizingView = { tableHeight -> - VerticalResizingView( - modifier = tableHeight?.let { - Modifier - .height( - with(LocalDensity.current) { - it.toDp() - }, - ) - } ?: Modifier, - provideResizingCell = { resizingCell }, - ) - }, - bottomContent = bottomContent, - ) -} diff --git a/compose-table/src/main/java/org/dhis2/composetable/ui/DropDownOptions.kt b/compose-table/src/main/java/org/dhis2/composetable/ui/DropDownOptions.kt deleted file mode 100644 index 65e64f6fa1..0000000000 --- a/compose-table/src/main/java/org/dhis2/composetable/ui/DropDownOptions.kt +++ /dev/null @@ -1,30 +0,0 @@ -package org.dhis2.composetable.ui - -import androidx.compose.material.DropdownMenu -import androidx.compose.material.DropdownMenuItem -import androidx.compose.material.Text -import androidx.compose.runtime.Composable -import org.dhis2.composetable.model.DropdownOption - -@Composable -fun DropDownOptions( - expanded: Boolean, - options: List, - onDismiss: () -> Unit, - onSelected: (code: String, label: String) -> Unit, -) { - DropdownMenu( - expanded = expanded, - onDismissRequest = onDismiss, - ) { - options.forEach { option -> - DropdownMenuItem( - onClick = { - onSelected.invoke(option.code, option.name) - }, - ) { - Text(text = option.name) - } - } - } -} diff --git a/compose-table/src/main/java/org/dhis2/composetable/ui/ExtendDivider.kt b/compose-table/src/main/java/org/dhis2/composetable/ui/ExtendDivider.kt deleted file mode 100644 index 7211f4e97d..0000000000 --- a/compose-table/src/main/java/org/dhis2/composetable/ui/ExtendDivider.kt +++ /dev/null @@ -1,60 +0,0 @@ -package org.dhis2.composetable.ui - -import androidx.compose.foundation.background -import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.height -import androidx.compose.foundation.layout.width -import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier -import androidx.compose.ui.draw.drawBehind -import androidx.compose.ui.geometry.Offset -import androidx.compose.ui.geometry.Size -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.platform.LocalDensity -import androidx.compose.ui.unit.dp - -@Composable -fun ExtendDivider(tableId: String, selected: Boolean) { - val background = TableTheme.colors.primary - Row(modifier = Modifier.fillMaxWidth()) { - Box( - modifier = Modifier - .width( - with(LocalDensity.current) { - TableTheme.dimensions - .rowHeaderWidth(tableId) - .toDp() - }, - ) - .height(8.dp) - .background( - color = if (selected) { - TableTheme.colors.primary - } else { - Color.White - }, - ) - .drawBehind { - drawRect( - color = background, - topLeft = Offset(size.width - 1.dp.toPx(), 0f), - size = Size(1.dp.toPx(), size.height), - ) - }, - ) - Box( - modifier = Modifier - .weight(1f) - .height(8.dp) - .background( - color = if (selected) { - TableTheme.colors.primaryLight - } else { - Color.White - }, - ), - ) - } -} diff --git a/compose-table/src/main/java/org/dhis2/composetable/ui/HeaderCell.kt b/compose-table/src/main/java/org/dhis2/composetable/ui/HeaderCell.kt deleted file mode 100644 index 7074414950..0000000000 --- a/compose-table/src/main/java/org/dhis2/composetable/ui/HeaderCell.kt +++ /dev/null @@ -1,90 +0,0 @@ -package org.dhis2.composetable.ui - -import androidx.compose.foundation.background -import androidx.compose.foundation.clickable -import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.fillMaxHeight -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.layout.width -import androidx.compose.material.Divider -import androidx.compose.material.Text -import androidx.compose.runtime.Composable -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.platform.LocalDensity -import androidx.compose.ui.platform.testTag -import androidx.compose.ui.semantics.semantics -import androidx.compose.ui.text.style.TextAlign -import androidx.compose.ui.text.style.TextOverflow -import androidx.compose.ui.zIndex -import org.dhis2.composetable.model.ItemColumnHeaderUiState -import org.dhis2.composetable.ui.semantics.columnBackground -import org.dhis2.composetable.ui.semantics.columnIndexHeader -import org.dhis2.composetable.ui.semantics.rowIndexHeader -import org.dhis2.composetable.ui.semantics.tableIdColumnHeader - -@Composable -fun HeaderCell(itemHeaderUiState: ItemColumnHeaderUiState, modifier: Modifier = Modifier) { - Box( - modifier = modifier - .width(with(LocalDensity.current) { itemHeaderUiState.headerMeasures.width.toDp() }) - .fillMaxHeight() - .background(itemHeaderUiState.cellStyle.backgroundColor()) - .testTag(itemHeaderUiState.testTag) - .semantics { - itemHeaderUiState.tableId?.let { tableIdColumnHeader = it } - columnIndexHeader = itemHeaderUiState.columnIndex - rowIndexHeader = itemHeaderUiState.rowIndex - columnBackground = itemHeaderUiState.cellStyle.backgroundColor() - } - .clickable { - itemHeaderUiState.onCellSelected(itemHeaderUiState.columnIndex) - }, - contentAlignment = Alignment.Center, - ) { - Text( - modifier = Modifier - .padding(itemHeaderUiState.paddingValues) - .align(Alignment.Center) - .fillMaxWidth() - .align(Alignment.Center), - color = itemHeaderUiState.cellStyle.mainColor(), - text = itemHeaderUiState.headerCell.value, - textAlign = TextAlign.Center, - fontSize = TableTheme.dimensions.defaultHeaderTextSize, - overflow = TextOverflow.Ellipsis, - maxLines = 3, - softWrap = true, - ) - Divider( - color = TableTheme.colors.primary, - modifier = Modifier - .fillMaxWidth() - .align(Alignment.BottomCenter), - ) - val isSelected = when (LocalTableSelection.current) { - is TableSelection.AllCellSelection -> false - else -> LocalTableSelection.current.isHeaderSelected( - selectedTableId = itemHeaderUiState.tableId ?: "", - columnIndex = itemHeaderUiState.columnIndex, - columnHeaderRowIndex = itemHeaderUiState.rowIndex, - ) - } - if (isSelected && itemHeaderUiState.isLastRow) { - VerticalResizingRule( - modifier = Modifier - .align(Alignment.CenterEnd) - .zIndex(2f), - checkMaxMinCondition = itemHeaderUiState.checkMaxCondition, - onHeaderResize = { newValue -> - itemHeaderUiState.onHeaderResize( - itemHeaderUiState.columnIndex, - newValue, - ) - }, - onResizing = itemHeaderUiState.onResizing, - ) - } - } -} diff --git a/compose-table/src/main/java/org/dhis2/composetable/ui/ItemHeader.kt b/compose-table/src/main/java/org/dhis2/composetable/ui/ItemHeader.kt deleted file mode 100644 index 9502c6ba66..0000000000 --- a/compose-table/src/main/java/org/dhis2/composetable/ui/ItemHeader.kt +++ /dev/null @@ -1,120 +0,0 @@ -package org.dhis2.composetable.ui - -import androidx.compose.foundation.background -import androidx.compose.foundation.clickable -import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.Spacer -import androidx.compose.foundation.layout.defaultMinSize -import androidx.compose.foundation.layout.fillMaxHeight -import androidx.compose.foundation.layout.height -import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.layout.size -import androidx.compose.foundation.layout.width -import androidx.compose.material.Divider -import androidx.compose.material.Icon -import androidx.compose.material.Text -import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.outlined.Info -import androidx.compose.runtime.Composable -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.platform.testTag -import androidx.compose.ui.semantics.semantics -import androidx.compose.ui.text.style.TextOverflow -import androidx.compose.ui.unit.dp -import org.dhis2.composetable.model.ItemHeaderUiState -import org.dhis2.composetable.model.TableDialogModel -import org.dhis2.composetable.ui.semantics.INFO_ICON -import org.dhis2.composetable.ui.semantics.infoIconId -import org.dhis2.composetable.ui.semantics.rowBackground -import org.dhis2.composetable.ui.semantics.rowIndexSemantic -import org.dhis2.composetable.ui.semantics.tableIdSemantic - -@Composable -fun ItemHeader(uiState: ItemHeaderUiState) { - Box { - Row( - modifier = Modifier - .defaultMinSize( - minHeight = TableTheme.dimensions.defaultCellHeight, - ) - .width(uiState.width) - .fillMaxHeight() - .background(uiState.cellStyle.backgroundColor()) - .semantics { - tableIdSemantic = uiState.tableId - uiState.rowHeader.row?.let { rowIndexSemantic = uiState.rowHeader.row } - infoIconId = if (uiState.rowHeader.showDecoration) INFO_ICON else "" - rowBackground = uiState.cellStyle.backgroundColor() - } - .testTag("${uiState.tableId}${uiState.rowHeader.row}") - .clickable { - uiState.onCellSelected(uiState.rowHeader.row) - if (uiState.rowHeader.showDecoration) { - uiState.onDecorationClick( - TableDialogModel( - uiState.rowHeader.title, - uiState.rowHeader.description ?: "", - ), - ) - } - }, - verticalAlignment = Alignment.CenterVertically, - ) { - Row( - modifier = Modifier - .weight(1f) - .padding(4.dp), - verticalAlignment = Alignment.CenterVertically, - ) { - Text( - modifier = Modifier - .weight(1f), - text = uiState.rowHeader.title, - color = uiState.cellStyle.mainColor(), - fontSize = TableTheme.dimensions.defaultRowHeaderTextSize, - maxLines = uiState.maxLines, - overflow = TextOverflow.Ellipsis, - ) - if (uiState.rowHeader.showDecoration) { - Spacer(modifier = Modifier.size(4.dp)) - Icon( - imageVector = Icons.Outlined.Info, - contentDescription = "info", - modifier = Modifier - .height(10.dp) - .width(10.dp), - tint = uiState.cellStyle.mainColor(), - ) - } - } - Divider( - modifier = Modifier - .fillMaxHeight() - .width(1.dp), - color = TableTheme.colors.primary, - ) - } - - val isSelected = LocalTableSelection.current !is TableSelection.AllCellSelection && - LocalTableSelection.current.isRowSelected( - selectedTableId = uiState.tableId, - rowHeaderIndex = uiState.rowHeader.row ?: -1, - ) - if (isSelected) { - VerticalResizingRule( - modifier = Modifier - .align(Alignment.CenterEnd), - checkMaxMinCondition = { dimensions, currentOffsetX -> - dimensions.canUpdateRowHeaderWidth( - tableId = uiState.tableId, - widthOffset = currentOffsetX, - ) - }, - onHeaderResize = uiState.onHeaderResize, - onResizing = uiState.onResizing, - ) - } - } -} diff --git a/compose-table/src/main/java/org/dhis2/composetable/ui/ItemValues.kt b/compose-table/src/main/java/org/dhis2/composetable/ui/ItemValues.kt deleted file mode 100644 index 801d0ed4df..0000000000 --- a/compose-table/src/main/java/org/dhis2/composetable/ui/ItemValues.kt +++ /dev/null @@ -1,60 +0,0 @@ -package org.dhis2.composetable.ui - -import androidx.compose.foundation.ScrollState -import androidx.compose.foundation.horizontalScroll -import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.Spacer -import androidx.compose.foundation.layout.size -import androidx.compose.runtime.Composable -import androidx.compose.runtime.key -import androidx.compose.ui.Modifier -import org.dhis2.composetable.model.DropdownOption -import org.dhis2.composetable.model.TableCell -import org.dhis2.composetable.model.TableHeader -import org.dhis2.composetable.ui.semantics.CELL_TEST_TAG - -@Composable -fun ItemValues( - tableId: String, - horizontalScrollState: ScrollState, - maxLines: Int, - cellValues: Map, - overridenValues: Map, - tableHeaderModel: TableHeader, - options: List, - headerLabel: String, -) { - Row( - modifier = Modifier - .horizontalScroll(state = horizontalScrollState), - ) { - repeat( - times = cellValues.size, - action = { columnIndex -> - val cellValue = - if (overridenValues[columnIndex]?.id == cellValues[columnIndex]?.id) { - overridenValues[columnIndex] - } else { - cellValues[columnIndex] - } ?: TableCell(value = "", column = columnIndex) - - key("$tableId$CELL_TEST_TAG${cellValue.row}${cellValue.column}") { - TableCell( - tableId = tableId, - cell = cellValue, - maxLines = maxLines, - headerExtraSize = TableTheme.dimensions.extraSize( - tableId, - tableHeaderModel.tableMaxColumns(), - tableHeaderModel.hasTotals, - columnIndex, - ), - options = options, - headerLabel = headerLabel, - ) - } - }, - ) - Spacer(Modifier.size(TableTheme.dimensions.tableEndExtraScroll)) - } -} diff --git a/compose-table/src/main/java/org/dhis2/composetable/ui/MultiOptionSelector.kt b/compose-table/src/main/java/org/dhis2/composetable/ui/MultiOptionSelector.kt deleted file mode 100644 index 64d38ed6f8..0000000000 --- a/compose-table/src/main/java/org/dhis2/composetable/ui/MultiOptionSelector.kt +++ /dev/null @@ -1,43 +0,0 @@ -package org.dhis2.composetable.ui - -import androidx.compose.runtime.Composable -import androidx.compose.ui.res.stringResource -import org.dhis2.composetable.R -import org.dhis2.composetable.model.DropdownOption -import org.dhis2.composetable.model.TableCell -import org.hisp.dhis.mobile.ui.designsystem.component.CheckBoxData -import org.hisp.dhis.mobile.ui.designsystem.component.MultiSelectBottomSheet - -@Composable -fun MultiOptionSelector( - options: List, - cell: TableCell, - title: String, - onSave: (String, String) -> Unit, - onDismiss: () -> Unit, -) { - MultiSelectBottomSheet( - items = options.map { option -> - CheckBoxData( - uid = option.code, - checked = cell.value?.split(", ")?.contains(option.name) == true, - enabled = cell.editable, - textInput = option.name, - ) - }, - title = title, - noResultsFoundString = stringResource(R.string.no_results_found), - searchToFindMoreString = stringResource(id = R.string.search_to_see_more), - doneButtonText = stringResource(id = R.string.done), - onItemsSelected = { checkBoxes -> - val checkedCodes = checkBoxes - .filter { item -> item.checked } - .joinToString(", ") { it.uid } - val checkedValues = checkBoxes - .filter { item -> item.checked } - .joinToString(", ") { it.textInput?.text.orEmpty() } - onSave(checkedCodes, checkedValues) - }, - onDismiss = onDismiss, - ) -} diff --git a/compose-table/src/main/java/org/dhis2/composetable/ui/Table.kt b/compose-table/src/main/java/org/dhis2/composetable/ui/Table.kt deleted file mode 100644 index 4365f94cf6..0000000000 --- a/compose-table/src/main/java/org/dhis2/composetable/ui/Table.kt +++ /dev/null @@ -1,304 +0,0 @@ -package org.dhis2.composetable.ui - -import androidx.compose.foundation.ExperimentalFoundationApi -import androidx.compose.foundation.background -import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.PaddingValues -import androidx.compose.foundation.layout.Spacer -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.height -import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.lazy.LazyColumn -import androidx.compose.foundation.lazy.LazyListScope -import androidx.compose.foundation.lazy.LazyListState -import androidx.compose.foundation.lazy.itemsIndexed -import androidx.compose.foundation.lazy.rememberLazyListState -import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.runtime.Composable -import androidx.compose.runtime.LaunchedEffect -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember -import androidx.compose.runtime.setValue -import androidx.compose.ui.Modifier -import androidx.compose.ui.draw.clip -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.layout.onSizeChanged -import androidx.compose.ui.tooling.preview.Preview -import androidx.compose.ui.unit.dp -import org.dhis2.composetable.model.RowHeader -import org.dhis2.composetable.model.TableHeaderCell -import org.dhis2.composetable.model.TableModel -import org.dhis2.composetable.model.TableRowModel -import org.dhis2.composetable.model.extensions.areAllValuesEmpty -import org.dhis2.composetable.ui.TableTheme.tableSelection -import org.dhis2.composetable.ui.compositions.LocalTableResizeActions -import org.dhis2.composetable.ui.extensions.fixedStickyHeader - -@OptIn(ExperimentalFoundationApi::class) -@Composable -fun Table( - tableList: List, - tableHeaderRow: @Composable ((index: Int, tableModel: TableModel) -> Unit)? = null, - tableItemRow: @Composable ( - ( - index: Int, - tableModel: TableModel, - tableRowModel: TableRowModel, - ) -> Unit - )? = null, - verticalResizingView: @Composable ((tableHeight: Int?) -> Unit)? = null, - bottomContent: @Composable (() -> Unit)? = null, -) { - Box( - modifier = Modifier - .background(Color.White) - .clip(RoundedCornerShape(8.dp)), - ) { - val resizeActions = LocalTableResizeActions.current - var tableHeight: Int? by remember { mutableStateOf(null) } - - if (!TableTheme.configuration.editable && !tableList.all { it.areAllValuesEmpty() }) { - Column( - Modifier - .fillMaxWidth() - .padding( - vertical = LocalTableDimensions.current.tableVerticalPadding, - horizontal = LocalTableDimensions.current.tableHorizontalPadding, - ) - .onSizeChanged { - resizeActions.onTableWidthChanged(it.width) - tableHeight = it.height - }, - ) { - tableList.forEachIndexed { index, tableModel -> - tableHeaderRow?.invoke(index, tableModel) - tableModel.tableRows.forEach { tableRowModel -> - tableItemRow?.invoke(index, tableModel, tableRowModel) - LastRowDivider( - tableId = tableModel.id ?: "", - isLastRow = tableRowModel.isLastRow, - ) - } - } - } - } else { - val verticalScrollState = rememberLazyListState() - val keyboardState by keyboardAsState() - val tableSelection = LocalTableSelection.current - - LaunchedEffect(keyboardState) { - val isCellSelection = tableSelection is TableSelection.CellSelection - val isKeyboardOpen = keyboardState == Keyboard.Opened - verticalScrollState.animateToIf( - tableSelection.getSelectedCellRowIndex(tableSelection.tableId), - isCellSelection && isKeyboardOpen, - ) - } - - LazyColumn( - modifier = Modifier - .background(Color.White) - .fillMaxWidth() - .padding( - horizontal = TableTheme.dimensions.tableHorizontalPadding, - vertical = TableTheme.dimensions.tableVerticalPadding, - ) - .onSizeChanged { - resizeActions.onTableWidthChanged(it.width) - }, - contentPadding = PaddingValues(bottom = TableTheme.dimensions.tableBottomPadding), - state = verticalScrollState, - ) { - tableList.forEachIndexed { index, tableModel -> - fixedStickyHeader( - fixHeader = keyboardState == Keyboard.Closed, - key = tableModel.id, - ) { - tableHeaderRow?.invoke(index, tableModel) - } - itemsIndexed( - items = tableModel.tableRows, - key = { _, item -> item.rowHeader.id!! }, - ) { _, tableRowModel -> - tableItemRow?.invoke(index, tableModel, tableRowModel) - LastRowDivider(tableModel.id ?: "", tableRowModel.isLastRow) - } - stickyFooter(keyboardState == Keyboard.Closed) - } - bottomContent?.let { item { it.invoke() } } - } - } - verticalResizingView?.invoke(tableHeight) - } -} - -@Composable -private fun LastRowDivider(tableId: String, isLastRow: Boolean) { - if (isLastRow) { - ExtendDivider( - tableId = tableId, - selected = tableSelection.isCornerSelected(tableId), - ) - } -} - -private suspend fun LazyListState.animateToIf(index: Int, condition: Boolean) { - if (condition) { - apply { - if (index >= 0) { - animateScrollToItem(index) - } - } - } -} - -@OptIn(ExperimentalFoundationApi::class) -private fun LazyListScope.stickyFooter(showFooter: Boolean = true) { - if (showFooter) { - stickyHeader { - Spacer( - modifier = Modifier - .height(16.dp) - .background(color = Color.White), - ) - } - } -} - -@Preview(showBackground = true) -@Composable -fun TablePreview() { - val tableHeaderModel = org.dhis2.composetable.model.TableHeader( - rows = listOf( - org.dhis2.composetable.model.TableHeaderRow( - cells = listOf( - TableHeaderCell("<18"), - TableHeaderCell(">18 <65"), - TableHeaderCell(">65"), - ), - ), - org.dhis2.composetable.model.TableHeaderRow( - cells = listOf( - TableHeaderCell("Male"), - TableHeaderCell("Female"), - ), - ), - org.dhis2.composetable.model.TableHeaderRow( - cells = listOf( - TableHeaderCell("Fixed"), - TableHeaderCell("Outreach"), - ), - ), - ), - hasTotals = true, - ) - - val tableRows = TableRowModel( - rowHeader = RowHeader("uid", "Data Element", 0, true), - values = mapOf( - Pair( - 0, - org.dhis2.composetable.model.TableCell( - id = "0", - value = "12.123523452341232131312", - mandatory = true, - row = 0, - column = 0, - ), - ), - Pair( - 1, - org.dhis2.composetable.model.TableCell( - id = "1", - value = "1", - editable = false, - row = 0, - column = 1, - ), - ), - Pair( - 2, - org.dhis2.composetable.model.TableCell( - id = "2", - value = "", - mandatory = true, - row = 0, - column = 2, - ), - ), - Pair( - 3, - org.dhis2.composetable.model.TableCell( - id = "3", - value = "12", - mandatory = true, - error = "Error", - row = 0, - column = 3, - ), - ), - Pair( - 4, - org.dhis2.composetable.model.TableCell( - id = "4", - value = "1", - error = "Error", - row = 0, - column = 4, - ), - ), - Pair( - 5, - org.dhis2.composetable.model.TableCell(id = "5", value = "12", row = 0, column = 5), - ), - Pair( - 6, - org.dhis2.composetable.model.TableCell(id = "6", value = "55", row = 0, column = 6), - ), - Pair( - 7, - org.dhis2.composetable.model.TableCell(id = "7", value = "12", row = 0, column = 7), - ), - Pair( - 8, - org.dhis2.composetable.model.TableCell(id = "8", value = "12", row = 0, column = 8), - ), - Pair( - 9, - org.dhis2.composetable.model.TableCell(id = "9", value = "12", row = 0, column = 9), - ), - Pair( - 10, - org.dhis2.composetable.model.TableCell( - id = "10", - value = "12", - row = 0, - column = 10, - ), - ), - Pair( - 11, - org.dhis2.composetable.model.TableCell( - id = "11", - value = "12", - row = 0, - column = 11, - ), - ), - ), - maxLines = 1, - ) - - val tableModel = TableModel( - "tableId", - "table title", - tableHeaderModel, - listOf(tableRows), - ) - val tableList = listOf(tableModel) - Table( - tableList = tableList, - ) -} diff --git a/compose-table/src/main/java/org/dhis2/composetable/ui/TableActions.kt b/compose-table/src/main/java/org/dhis2/composetable/ui/TableActions.kt deleted file mode 100644 index ca49c6fece..0000000000 --- a/compose-table/src/main/java/org/dhis2/composetable/ui/TableActions.kt +++ /dev/null @@ -1,43 +0,0 @@ -package org.dhis2.composetable.ui - -import androidx.compose.foundation.layout.Arrangement -import androidx.compose.foundation.layout.Row -import androidx.compose.material.Icon -import androidx.compose.material.Text -import androidx.compose.runtime.Composable -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.graphics.vector.ImageVector -import androidx.compose.ui.res.vectorResource -import androidx.compose.ui.text.TextStyle -import androidx.compose.ui.text.font.FontWeight -import androidx.compose.ui.unit.dp -import androidx.compose.ui.unit.sp -import org.dhis2.composetable.R - -@Composable -fun TableActions(modifier: Modifier, title: String, actionIcons: @Composable () -> Unit) { - Row( - modifier = modifier, - horizontalArrangement = Arrangement.Absolute.spacedBy(8.dp), - verticalAlignment = Alignment.CenterVertically, - ) { - Icon( - imageVector = ImageVector.vectorResource(id = R.drawable.ic_table), - contentDescription = "", - tint = TableTheme.colors.primary, - ) - Text( - modifier = Modifier.weight(1f), - text = title, - style = TextStyle( - color = Color.Black, - fontSize = 14.sp, - fontWeight = FontWeight.Normal, - lineHeight = 10.sp, - ), - ) - actionIcons() - } -} diff --git a/compose-table/src/main/java/org/dhis2/composetable/ui/TableCell.kt b/compose-table/src/main/java/org/dhis2/composetable/ui/TableCell.kt deleted file mode 100644 index 1760f6f350..0000000000 --- a/compose-table/src/main/java/org/dhis2/composetable/ui/TableCell.kt +++ /dev/null @@ -1,285 +0,0 @@ -package org.dhis2.composetable.ui - -import androidx.compose.foundation.ExperimentalFoundationApi -import androidx.compose.foundation.clickable -import androidx.compose.foundation.focusable -import androidx.compose.foundation.layout.defaultMinSize -import androidx.compose.foundation.layout.fillMaxHeight -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.layout.size -import androidx.compose.foundation.layout.width -import androidx.compose.foundation.relocation.BringIntoViewRequester -import androidx.compose.foundation.relocation.bringIntoViewRequester -import androidx.compose.material.Divider -import androidx.compose.material.Icon -import androidx.compose.material.Text -import androidx.compose.runtime.Composable -import androidx.compose.runtime.LaunchedEffect -import androidx.compose.runtime.derivedStateOf -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember -import androidx.compose.runtime.rememberCoroutineScope -import androidx.compose.runtime.setValue -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.geometry.Rect -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.layout.onSizeChanged -import androidx.compose.ui.platform.LocalDensity -import androidx.compose.ui.platform.testTag -import androidx.compose.ui.res.painterResource -import androidx.compose.ui.semantics.semantics -import androidx.compose.ui.text.TextStyle -import androidx.compose.ui.text.style.TextAlign -import androidx.compose.ui.text.style.TextOverflow -import androidx.compose.ui.unit.dp -import kotlinx.coroutines.launch -import org.dhis2.composetable.R -import org.dhis2.composetable.model.DropdownOption -import org.dhis2.composetable.model.TableCell -import org.dhis2.composetable.ui.compositions.LocalCurrentCellValue -import org.dhis2.composetable.ui.compositions.LocalInteraction -import org.dhis2.composetable.ui.compositions.LocalUpdatingCell -import org.dhis2.composetable.ui.extensions.isNumeric -import org.dhis2.composetable.ui.modifiers.cellBorder -import org.dhis2.composetable.ui.semantics.CELL_ERROR_UNDERLINE_TEST_TAG -import org.dhis2.composetable.ui.semantics.CELL_TEST_TAG -import org.dhis2.composetable.ui.semantics.CELL_VALUE_TEST_TAG -import org.dhis2.composetable.ui.semantics.MANDATORY_ICON_TEST_TAG -import org.dhis2.composetable.ui.semantics.cellSelected -import org.dhis2.composetable.ui.semantics.hasError -import org.dhis2.composetable.ui.semantics.isBlocked -import org.dhis2.composetable.ui.semantics.rowBackground - -@OptIn(ExperimentalFoundationApi::class) -@Composable -fun TableCell( - tableId: String, - cell: TableCell, - maxLines: Int, - headerExtraSize: Int, - options: List, - headerLabel: String, -) { - val localInteraction = LocalInteraction.current - val (dropDownExpanded, setExpanded) = remember { mutableStateOf(false) } - val (showMultiSelector, setShowMultiSelector) = remember { mutableStateOf(false) } - - var cellValue by remember { - mutableStateOf(null) - } - cellValue = when { - LocalUpdatingCell.current?.id == cell.id -> LocalUpdatingCell.current?.value - LocalTableSelection.current.isCellSelected(tableId, cell.column, cell.row ?: -1) -> - LocalCurrentCellValue.current() - - else -> cell.value - } - - val bringIntoViewRequester = remember { BringIntoViewRequester() } - - val backgroundColor = TableTheme.colors.disabledCellBackground - val coroutineScope = rememberCoroutineScope() - val isSelected = - TableTheme.tableSelection.isCellSelected(tableId, cell.column, cell.row ?: -1) - val isParentSelected = TableTheme.tableSelection.isCellParentSelected( - selectedTableId = tableId, - columnIndex = cell.column, - rowIndex = cell.row ?: -1, - ) - val colors = TableTheme.colors - - val style by remember(cellValue, isSelected, isParentSelected) { - derivedStateOf { - styleForCell( - tableColorProvider = { colors }, - isSelected = isSelected, - isParentSelected = isParentSelected, - hasError = cell.error != null, - hasWarning = cell.warning != null, - isEditable = cell.editable, - legendColor = cell.legendColor, - ) - } - } - val localDensity = LocalDensity.current - val dimensions = TableTheme.dimensions - - val cellWidth by remember(dimensions) { - derivedStateOf { - with(localDensity) { - dimensions - .columnWidthWithTableExtra( - tableId, - cell.column, - ) - .plus(headerExtraSize) - .toDp() - } - } - } - - var currentCellHeight = 0 - - CellLegendBox( - modifier = Modifier - .testTag("$tableId$CELL_TEST_TAG${cell.row}${cell.column}") - .onSizeChanged { currentCellHeight = it.height } - .width(cellWidth) - .fillMaxHeight() - .defaultMinSize(minHeight = dimensions.defaultCellHeight) - .semantics { - rowBackground = style.backgroundColor() - cellSelected = isSelected - hasError = cell.hasErrorOrWarning() - isBlocked = style.backgroundColor() == backgroundColor - } - .cellBorder( - borderColor = style.mainColor(), - backgroundColor = style.backgroundColor(), - ) - .bringIntoViewRequester(bringIntoViewRequester) - .focusable() - .fillMaxWidth() - .fillMaxHeight() - .clickable(cell.editable) { - when { - options.isNotEmpty() -> when { - cell.isMultiText -> setShowMultiSelector(true) - else -> setExpanded(true) - } - else -> { - localInteraction.onSelectionChange( - TableSelection.CellSelection( - tableId = tableId, - columnIndex = cell.column, - rowIndex = cell.row ?: -1, - globalIndex = 0, - ), - ) - localInteraction.onClick(cell) - } - } - }, - legendColor = cell.legendColor?.let { Color(it) }, - ) { - Text( - modifier = Modifier - .testTag(CELL_VALUE_TEST_TAG) - .align(Alignment.Center) - .fillMaxWidth() - .padding( - horizontal = TableTheme.dimensions.cellHorizontalPadding, - vertical = TableTheme.dimensions.cellVerticalPadding, - ), - text = cellValue ?: "", - maxLines = maxLines, - overflow = TextOverflow.Ellipsis, - style = TextStyle.Default.copy( - fontSize = TableTheme.dimensions.defaultCellTextSize, - textAlign = if (cellValue.isNumeric()) TextAlign.End else TextAlign.Start, - color = LocalTableColors.current.cellTextColor( - hasError = cell.error != null, - hasWarning = cell.warning != null, - isEditable = cell.editable, - ), - ), - ) - if (options.isNotEmpty()) { - DropDownOptions( - expanded = dropDownExpanded, - options = options, - onDismiss = { setExpanded(false) }, - onSelected = { code, label -> - setExpanded(false) - localInteraction.onSelectionChange( - TableSelection.CellSelection( - tableId = tableId, - columnIndex = cell.column, - rowIndex = cell.row ?: -1, - globalIndex = 0, - ), - ) - localInteraction.onOptionSelected(cell, code, label) - cellValue = label - }, - ) - if (showMultiSelector) { - MultiOptionSelector( - options = options, - cell = cell, - title = headerLabel, - onSave = { codes, values -> - localInteraction.onSelectionChange( - TableSelection.CellSelection( - tableId = tableId, - columnIndex = cell.column, - rowIndex = cell.row ?: -1, - globalIndex = 0, - ), - ) - cellValue = values - localInteraction.onOptionSelected(cell, codes, values) - setShowMultiSelector(false) - }, - onDismiss = { - setShowMultiSelector(false) - }, - ) - } - } - - if (cell.mandatory == true) { - Icon( - painter = painterResource(id = R.drawable.ic_mandatory), - contentDescription = "mandatory", - modifier = Modifier - .testTag(MANDATORY_ICON_TEST_TAG) - .padding(4.dp) - .size(6.dp) - .align( - alignment = mandatoryIconAlignment( - cellValue?.isNotEmpty() == true, - ), - ), - tint = LocalTableColors.current.cellMandatoryIconColor( - cellValue?.isNotEmpty() == true, - ), - ) - } - if (cell.hasErrorOrWarning()) { - Divider( - modifier = Modifier - .testTag(CELL_ERROR_UNDERLINE_TEST_TAG) - .align(Alignment.BottomCenter) - .fillMaxWidth(), - color = if (cell.error != null) { - TableTheme.colors.errorColor - } else { - TableTheme.colors.warningColor - }, - ) - } - } - - LaunchedEffect(key1 = isSelected) { - if (isSelected) { - val marginCoordinates = Rect( - 0f, - 0f, - dimensions.defaultCellWidth * 2f, - dimensions.textInputHeight.toFloat() + currentCellHeight, - ) - coroutineScope.launch { - bringIntoViewRequester.bringIntoView(marginCoordinates) - } - } - } -} - -private fun mandatoryIconAlignment(hasValue: Boolean) = when (hasValue) { - true -> Alignment.TopStart - false -> Alignment.CenterEnd -} diff --git a/compose-table/src/main/java/org/dhis2/composetable/ui/TableColors.kt b/compose-table/src/main/java/org/dhis2/composetable/ui/TableColors.kt deleted file mode 100644 index fe0515e527..0000000000 --- a/compose-table/src/main/java/org/dhis2/composetable/ui/TableColors.kt +++ /dev/null @@ -1,37 +0,0 @@ -package org.dhis2.composetable.ui - -import androidx.compose.runtime.Immutable -import androidx.compose.runtime.staticCompositionLocalOf -import androidx.compose.ui.graphics.Color - -@Immutable -data class TableColors( - val primary: Color = Color(0xFF2C98F0), - val primaryLight: Color = Color(0x332C98F0), - val headerText: Color = Color(0x8A000000), - val headerBackground1: Color = Color(0x05000000), - val headerBackground2: Color = Color(0x0A000000), - val cellText: Color = Color(0xDE000000), - val disabledCellText: Color = Color(0x61000000), - val disabledCellBackground: Color = Color(0x0A000000), - val disabledSelectedBackground: Color = Color(0x1F164C78), - val errorColor: Color = Color(0xFFE91E63), - val warningColor: Color = Color(0xFFFF9800), - val tableBackground: Color = Color(0xFFFFFFFF), - val iconColor: Color = Color.LightGray, - val onPrimary: Color = Color.White, -) { - fun cellTextColor(hasError: Boolean, hasWarning: Boolean, isEditable: Boolean) = when { - hasError -> errorColor - hasWarning -> warningColor - !isEditable -> disabledCellText - else -> cellText - } - - fun cellMandatoryIconColor(hasValue: Boolean) = when (hasValue) { - true -> iconColor - false -> errorColor - } -} - -val LocalTableColors = staticCompositionLocalOf { TableColors() } diff --git a/compose-table/src/main/java/org/dhis2/composetable/ui/TableConfiguration.kt b/compose-table/src/main/java/org/dhis2/composetable/ui/TableConfiguration.kt deleted file mode 100644 index 751a165dd2..0000000000 --- a/compose-table/src/main/java/org/dhis2/composetable/ui/TableConfiguration.kt +++ /dev/null @@ -1,13 +0,0 @@ -package org.dhis2.composetable.ui - -import androidx.compose.runtime.Immutable -import androidx.compose.runtime.staticCompositionLocalOf - -@Immutable -data class TableConfiguration( - val headerActionsEnabled: Boolean = true, - val editable: Boolean = true, - val textInputViewMode: Boolean = true, -) - -val LocalTableConfiguration = staticCompositionLocalOf { TableConfiguration() } diff --git a/compose-table/src/main/java/org/dhis2/composetable/ui/TableCorner.kt b/compose-table/src/main/java/org/dhis2/composetable/ui/TableCorner.kt deleted file mode 100644 index a90d7570d4..0000000000 --- a/compose-table/src/main/java/org/dhis2/composetable/ui/TableCorner.kt +++ /dev/null @@ -1,73 +0,0 @@ -package org.dhis2.composetable.ui - -import androidx.compose.foundation.clickable -import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.fillMaxHeight -import androidx.compose.foundation.layout.width -import androidx.compose.material.Divider -import androidx.compose.runtime.Composable -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.platform.LocalDensity -import androidx.compose.ui.unit.dp -import androidx.compose.ui.zIndex -import org.dhis2.composetable.model.TableCornerUiState -import org.dhis2.composetable.ui.modifiers.cornerBackground - -@Composable -fun TableCorner( - modifier: Modifier = Modifier, - tableCornerUiState: TableCornerUiState, - tableId: String, - onClick: () -> Unit, -) { - val isSelected = LocalTableSelection.current is TableSelection.AllCellSelection - Box( - modifier = modifier - .cornerBackground( - isSelected = isSelected, - selectedColor = LocalTableColors.current.primaryLight, - defaultColor = LocalTableColors.current.tableBackground, - ) - .width( - with(LocalDensity.current) { - TableTheme.dimensions - .rowHeaderWidth(tableId) - .toDp() - }, - ) - .clickable { onClick() }, - contentAlignment = Alignment.CenterEnd, - ) { - Divider( - modifier - .fillMaxHeight() - .width(1.dp), - color = TableTheme.colors.primary, - ) - if (isSelected) { - VerticalResizingRule( - modifier = Modifier - .align(Alignment.CenterEnd) - .zIndex(1f), - checkMaxMinCondition = { dimensions, currentOffsetX -> - if (tableCornerUiState.singleValueTable) { - dimensions.canUpdateRowHeaderWidth( - tableId = tableId, - widthOffset = currentOffsetX, - ) - } else { - dimensions.canUpdateAllWidths( - tableId = tableId, - widthOffset = currentOffsetX, - ) - } - }, - onHeaderResize = { newValue -> - tableCornerUiState.onTableResize(newValue) - }, - onResizing = tableCornerUiState.onResizing, - ) - } - } -} diff --git a/compose-table/src/main/java/org/dhis2/composetable/ui/TableDialog.kt b/compose-table/src/main/java/org/dhis2/composetable/ui/TableDialog.kt deleted file mode 100644 index 560b293855..0000000000 --- a/compose-table/src/main/java/org/dhis2/composetable/ui/TableDialog.kt +++ /dev/null @@ -1,36 +0,0 @@ -package org.dhis2.composetable.ui - -import androidx.compose.foundation.layout.padding -import androidx.compose.material.AlertDialog -import androidx.compose.material.Text -import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier -import androidx.compose.ui.res.stringResource -import androidx.compose.ui.unit.dp -import org.dhis2.composetable.R -import org.dhis2.composetable.model.TableDialogModel -import org.hisp.dhis.mobile.ui.designsystem.component.Button - -@Composable -fun TableDialog( - dialogModel: TableDialogModel, - onDismiss: () -> Unit, - onPrimaryButtonClick: () -> Unit, -) { - AlertDialog( - onDismissRequest = onDismiss, - title = { - Text(dialogModel.title) - }, - text = { - Text(dialogModel.message) - }, - confirmButton = { - Button( - modifier = Modifier.padding(bottom = 16.dp, end = 16.dp), - text = stringResource(R.string.dialog_option_accept), - onClick = onPrimaryButtonClick, - ) - }, - ) -} diff --git a/compose-table/src/main/java/org/dhis2/composetable/ui/TableDimensions.kt b/compose-table/src/main/java/org/dhis2/composetable/ui/TableDimensions.kt deleted file mode 100644 index 2593c2aef8..0000000000 --- a/compose-table/src/main/java/org/dhis2/composetable/ui/TableDimensions.kt +++ /dev/null @@ -1,213 +0,0 @@ -package org.dhis2.composetable.ui - -import androidx.annotation.VisibleForTesting -import androidx.compose.foundation.layout.PaddingValues -import androidx.compose.runtime.Immutable -import androidx.compose.runtime.compositionLocalOf -import androidx.compose.ui.unit.Dp -import androidx.compose.ui.unit.TextUnit -import androidx.compose.ui.unit.dp -import androidx.compose.ui.unit.sp - -@Immutable -data class TableDimensions( - val tableHorizontalPadding: Dp = 16.dp, - val tableVerticalPadding: Dp = 16.dp, - val defaultCellWidth: Int = 160, - val defaultCellHeight: Dp = 36.dp, - val defaultRowHeaderWidth: Int = 275, - val defaultHeaderHeight: Int = 36, - val defaultLegendCornerSize: Dp = 2.dp, - val defaultLegendBorderWidth: Dp = 8.dp, - val defaultHeaderTextSize: TextUnit = 12.sp, - val defaultRowHeaderTextSize: TextUnit = 12.sp, - val defaultCellTextSize: TextUnit = 12.sp, - val totalWidth: Int = 0, - val cellVerticalPadding: Dp = 4.dp, - val cellHorizontalPadding: Dp = 4.dp, - val headerCellPaddingValues: PaddingValues = PaddingValues(horizontal = 4.dp, vertical = 11.dp), - val tableBottomPadding: Dp = 200.dp, - val extraWidths: Map = emptyMap(), - val rowHeaderWidths: Map = emptyMap(), - val columnWidth: Map> = emptyMap(), - val minRowHeaderWidth: Int = 130, - val minColumnWidth: Int = 130, - val maxRowHeaderWidth: Int = Int.MAX_VALUE, - val maxColumnWidth: Int = Int.MAX_VALUE, - val tableEndExtraScroll: Dp = 6.dp, -) { - - private var currentExtraSize: MutableMap = mutableMapOf() - private fun extraWidthInTable(tableId: String): Int = extraWidths[tableId] ?: 0 - - var textInputHeight = 0 - - fun rowHeaderWidth(tableId: String): Int { - return (rowHeaderWidths[tableId] ?: defaultRowHeaderWidth) + extraWidthInTable(tableId) - } - - fun defaultCellWidthWithExtraSize( - tableId: String, - totalColumns: Int, - hasExtra: Boolean = false, - ): Int = defaultCellWidth + - extraSize(tableId, totalColumns, hasExtra) + - extraWidthInTable(tableId) - fun columnWidthWithTableExtra(tableId: String, column: Int? = null): Int = - (columnWidth[tableId]?.get(column) ?: defaultCellWidth) + extraWidthInTable(tableId) - - fun headerCellWidth( - tableId: String, - column: Int, - headerRowColumns: Int, - totalColumns: Int, - hasTotal: Boolean = false, - ): Int { - val rowHeaderRatio = totalColumns / headerRowColumns - - val result = when { - rowHeaderRatio != 1 -> { - val maxColumn = rowHeaderRatio * (1 + column) - 1 - val minColumn = rowHeaderRatio * column - (minColumn..maxColumn).sumOf { - columnWidthWithTableExtra(tableId, it) + - extraSize(tableId, totalColumns, hasTotal, column) - } - } - else -> columnWidthWithTableExtra(tableId, column) + - extraSize(tableId, totalColumns, hasTotal, column) - } - return result - } - - @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) - fun headerCellWidth(headerRowColumns: Int, totalColumns: Int): Int { - val fullWidth = defaultCellWidth * totalColumns - return fullWidth / headerRowColumns - } - - fun extraSize(tableId: String, totalColumns: Int, hasTotal: Boolean, column: Int? = null): Int { - val screenWidth = totalWidth - val tableWidth = tableWidth(tableId, totalColumns, hasTotal) - val columnHasResizedValue = column?.let { - columnWidth[tableId]?.containsKey(it) - } - - return if (tableWidth < screenWidth && columnHasResizedValue != true) { - val totalColumnCount = 1.takeIf { hasTotal } ?: 0 - val columnsCount = totalColumns + totalColumnCount - ((screenWidth - tableWidth) / columnsCount).also { - currentExtraSize[tableId] = it - } - } else { - 0 - } - } - - @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) - fun tableWidth(tableId: String, totalColumns: Int, hasTotal: Boolean): Int { - val totalCellWidth = defaultCellWidth.takeIf { hasTotal } ?: 0 - return rowHeaderWidth(tableId) + defaultCellWidth * totalColumns + totalCellWidth - } - - fun updateAllWidthBy(tableId: String, widthOffset: Float): TableDimensions { - val newWidth = (extraWidths[tableId] ?: 0) + widthOffset - 11 - val newMap = extraWidths.toMutableMap() - newMap[tableId] = newWidth.toInt() - return copy(extraWidths = newMap) - } - - fun updateHeaderWidth(tableId: String, widthOffset: Float): TableDimensions { - val newWidth = (rowHeaderWidths[tableId] ?: defaultRowHeaderWidth) + widthOffset - 11 - val newMap = rowHeaderWidths.toMutableMap() - newMap[tableId] = newWidth.toInt() - return copy(rowHeaderWidths = newMap) - } - - fun updateColumnWidth(tableId: String, column: Int, widthOffset: Float): TableDimensions { - val newWidth = ( - columnWidth[tableId]?.get(column) - ?: (defaultCellWidth + (currentExtraSize[tableId] ?: 0)) - ) + widthOffset - 11 - - val newMap = columnWidth.toMutableMap() - val tableColumnMap = columnWidth[tableId]?.toMutableMap() ?: mutableMapOf() - tableColumnMap[column] = newWidth.toInt() - newMap[tableId] = tableColumnMap - return this.copy(columnWidth = newMap) - } - - fun hasOverriddenWidths(tableId: String): Boolean { - return rowHeaderWidths.containsKey(tableId) || - columnWidth.containsKey(tableId) || - extraWidths.containsKey(tableId) - } - - fun resetWidth(tableId: String): TableDimensions { - val newExtraWidths = extraWidths.toMutableMap() - val newColumnMap = columnWidth.toMutableMap() - val newRowHeaderMap = rowHeaderWidths.toMutableMap() - newExtraWidths.remove(tableId) - newColumnMap.remove(tableId) - newRowHeaderMap.remove(tableId) - return this.copy( - extraWidths = newExtraWidths, - rowHeaderWidths = newRowHeaderMap, - columnWidth = newColumnMap, - ) - } - - fun canUpdateRowHeaderWidth(tableId: String, widthOffset: Float): Boolean { - val desiredDimension = updateHeaderWidth(tableId = tableId, widthOffset = widthOffset) - return desiredDimension.rowHeaderWidth(tableId) in minRowHeaderWidth..maxRowHeaderWidth - } - - fun canUpdateColumnHeaderWidth( - tableId: String, - currentOffsetX: Float, - columnIndex: Int, - totalColumns: Int, - hasTotal: Boolean, - ): Boolean { - val desiredDimension = updateColumnWidth( - tableId = tableId, - widthOffset = currentOffsetX, - column = columnIndex, - ) - return desiredDimension.columnWidthWithTableExtra( - tableId, - columnIndex, - ) + extraSize( - tableId = tableId, - totalColumns = totalColumns, - hasTotal = hasTotal, - column = columnIndex, - ) in minColumnWidth..maxColumnWidth - } - - fun canUpdateAllWidths(tableId: String, widthOffset: Float): Boolean { - val desiredDimension = updateAllWidthBy(tableId = tableId, widthOffset = widthOffset) - return desiredDimension.rowHeaderWidth(tableId) in minRowHeaderWidth..maxRowHeaderWidth && - desiredDimension.columnWidthWithTableExtra(tableId) in minColumnWidth..maxColumnWidth && - desiredDimension.columnWidth[tableId]?.all { (column, _) -> - desiredDimension.columnWidthWithTableExtra( - tableId, - column, - ) in minColumnWidth..maxColumnWidth - } ?: true - } - - fun getRowHeaderWidth(tableId: String): Int { - return rowHeaderWidths[tableId] ?: defaultRowHeaderWidth - } - - fun getColumnWidth(tableId: String, column: Int): Int { - return columnWidth[tableId]?.get(column) ?: defaultCellWidth - } - - fun getExtraWidths(tableId: String): Int { - return extraWidths[tableId] ?: 0 - } -} - -val LocalTableDimensions = compositionLocalOf { TableDimensions() } diff --git a/compose-table/src/main/java/org/dhis2/composetable/ui/TableHeader.kt b/compose-table/src/main/java/org/dhis2/composetable/ui/TableHeader.kt deleted file mode 100644 index 430cad2130..0000000000 --- a/compose-table/src/main/java/org/dhis2/composetable/ui/TableHeader.kt +++ /dev/null @@ -1,122 +0,0 @@ -package org.dhis2.composetable.ui - -import androidx.compose.foundation.ScrollState -import androidx.compose.foundation.horizontalScroll -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.IntrinsicSize -import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.Spacer -import androidx.compose.foundation.layout.height -import androidx.compose.foundation.layout.size -import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier -import androidx.compose.ui.zIndex -import org.dhis2.composetable.model.HeaderMeasures -import org.dhis2.composetable.model.ItemColumnHeaderUiState -import org.dhis2.composetable.model.ResizingCell -import org.dhis2.composetable.model.TableHeader -import org.dhis2.composetable.model.TableHeaderCell -import org.dhis2.composetable.ui.TableTheme.dimensions - -@Composable -fun TableHeader( - tableId: String?, - modifier: Modifier, - tableHeaderModel: TableHeader, - horizontalScrollState: ScrollState, - cellStyle: @Composable - (columnIndex: Int, rowIndex: Int) -> CellStyle, - onHeaderCellSelected: (columnIndex: Int, headerRowIndex: Int) -> Unit, - onHeaderResize: (Int, Float) -> Unit, - onResizing: (ResizingCell?) -> Unit, -) { - Row( - modifier = modifier - .horizontalScroll(state = horizontalScrollState) - .height(IntrinsicSize.Min), - ) { - Column( - modifier = Modifier - .height(IntrinsicSize.Min), - ) { - tableHeaderModel.rows.forEachIndexed { rowIndex, tableHeaderRow -> - Row( - modifier = Modifier - .height(IntrinsicSize.Min) - .zIndex(1f), - ) { - val totalColumns = tableHeaderModel.numberOfColumns(rowIndex) - val rowOptions = tableHeaderRow.cells.size - repeat( - times = totalColumns, - action = { columnIndex -> - val cellIndex = columnIndex % rowOptions - HeaderCell( - modifier = Modifier.zIndex((totalColumns - columnIndex) * 1f), - itemHeaderUiState = ItemColumnHeaderUiState( - tableId = tableId, - rowIndex = rowIndex, - columnIndex = columnIndex, - headerCell = tableHeaderRow.cells[cellIndex], - headerMeasures = HeaderMeasures( - width = dimensions.headerCellWidth( - tableId = tableId ?: "", - column = columnIndex, - headerRowColumns = tableHeaderModel.numberOfColumns(rowIndex), - totalColumns = tableHeaderModel.tableMaxColumns(), - hasTotal = tableHeaderModel.hasTotals, - ), - height = dimensions.defaultHeaderHeight, - ), - paddingValues = dimensions.headerCellPaddingValues, - cellStyle = cellStyle(columnIndex, rowIndex), - onCellSelected = { onHeaderCellSelected(it, rowIndex) }, - onHeaderResize = onHeaderResize, - onResizing = onResizing, - isLastRow = tableHeaderModel.rows.lastIndex == rowIndex, - ) { dimensions, currentOffsetX -> - dimensions.canUpdateColumnHeaderWidth( - tableId = tableId ?: "", - currentOffsetX = currentOffsetX, - columnIndex = columnIndex, - tableHeaderModel.tableMaxColumns(), - tableHeaderModel.hasTotals, - ) - }, - ) - }, - ) - if (tableHeaderModel.hasTotals) { - HeaderCell( - ItemColumnHeaderUiState( - tableId = tableId, - rowIndex = 0, - columnIndex = tableHeaderModel.rows.size, - headerCell = TableHeaderCell("Total"), - HeaderMeasures( - dimensions.defaultCellWidthWithExtraSize( - tableId = tableId ?: "", - totalColumns = tableHeaderModel.tableMaxColumns(), - hasExtra = true, - ), - dimensions.defaultHeaderHeight * tableHeaderModel.rows.size, - ), - paddingValues = dimensions.headerCellPaddingValues, - cellStyle = cellStyle( - tableHeaderModel.numberOfColumns(tableHeaderModel.rows.size - 1), - tableHeaderModel.rows.size - 1, - ), - onCellSelected = {}, - onHeaderResize = { _, _ -> }, - onResizing = {}, - isLastRow = false, - checkMaxCondition = { _, _ -> false }, - ), - ) - } - } - } - } - Spacer(Modifier.size(dimensions.tableEndExtraScroll)) - } -} diff --git a/compose-table/src/main/java/org/dhis2/composetable/ui/TableHeaderRow.kt b/compose-table/src/main/java/org/dhis2/composetable/ui/TableHeaderRow.kt deleted file mode 100644 index 89061cb547..0000000000 --- a/compose-table/src/main/java/org/dhis2/composetable/ui/TableHeaderRow.kt +++ /dev/null @@ -1,111 +0,0 @@ -package org.dhis2.composetable.ui - -import androidx.compose.foundation.ScrollState -import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.foundation.layout.padding -import androidx.compose.material.Icon -import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.graphics.vector.ImageVector -import androidx.compose.ui.res.vectorResource -import androidx.compose.ui.unit.dp -import androidx.compose.ui.zIndex -import androidx.constraintlayout.compose.ConstraintLayout -import androidx.constraintlayout.compose.Dimension -import org.dhis2.composetable.R -import org.dhis2.composetable.model.ResizingCell -import org.dhis2.composetable.model.TableCornerUiState -import org.dhis2.composetable.model.TableModel -import org.hisp.dhis.mobile.ui.designsystem.component.IconButton - -@Composable -fun TableHeaderRow( - modifier: Modifier = Modifier, - cornerUiState: TableCornerUiState, - tableModel: TableModel, - horizontalScrollState: ScrollState, - cellStyle: @Composable - (headerColumnIndex: Int, headerRowIndex: Int) -> CellStyle, - onTableCornerClick: () -> Unit = {}, - onHeaderCellClick: (headerColumnIndex: Int, headerRowIndex: Int) -> Unit = { _, _ -> }, - onHeaderResize: (Int, Float) -> Unit, - onResizing: (ResizingCell?) -> Unit, - onResetResize: () -> Unit = {}, -) { - ConstraintLayout( - modifier = modifier.fillMaxSize(), - ) { - val isHeaderActionEnabled = TableTheme.configuration.headerActionsEnabled - val (tableActions, tableCorner, header) = createRefs() - - if (isHeaderActionEnabled) { - TableActions( - modifier = Modifier - .padding(bottom = 24.dp) - .constrainAs(tableActions) { - top.linkTo(parent.top) - start.linkTo(parent.start) - end.linkTo(parent.end) - }, - title = tableModel.title, - actionIcons = { - if (TableTheme.dimensions.hasOverriddenWidths(tableModel.id ?: "")) { - IconButton( - onClick = onResetResize, - icon = { - Icon( - imageVector = ImageVector.vectorResource( - id = R.drawable.ic_restart_alt, - ), - contentDescription = "", - tint = Color.Black.copy(alpha = 0.87f), - ) - }, - ) - } - }, - ) - } - - TableCorner( - modifier = Modifier - .constrainAs(tableCorner) { - if (isHeaderActionEnabled) { - top.linkTo(tableActions.bottom) - } else { - top.linkTo(parent.top) - } - start.linkTo(parent.start) - end.linkTo(header.start) - bottom.linkTo(header.bottom) - height = Dimension.fillToConstraints - } - .zIndex(1f), - tableCornerUiState = cornerUiState, - tableId = tableModel.id ?: "", - onClick = onTableCornerClick, - ) - - TableHeader( - tableId = tableModel.id, - modifier = Modifier - .constrainAs(header) { - if (isHeaderActionEnabled) { - top.linkTo(tableActions.bottom) - } else { - top.linkTo(parent.top) - } - start.linkTo(tableCorner.end) - end.linkTo(parent.end) - width = Dimension.fillToConstraints - }, - tableHeaderModel = tableModel.tableHeaderModel, - horizontalScrollState = horizontalScrollState, - cellStyle = cellStyle, - onHeaderCellSelected = onHeaderCellClick, - onHeaderResize = onHeaderResize, - onResizing = onResizing, - ) - } -} diff --git a/compose-table/src/main/java/org/dhis2/composetable/ui/TableItemRow.kt b/compose-table/src/main/java/org/dhis2/composetable/ui/TableItemRow.kt deleted file mode 100644 index c33ab575f7..0000000000 --- a/compose-table/src/main/java/org/dhis2/composetable/ui/TableItemRow.kt +++ /dev/null @@ -1,84 +0,0 @@ -package org.dhis2.composetable.ui - -import androidx.compose.foundation.ScrollState -import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.IntrinsicSize -import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.fillMaxHeight -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.height -import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.layout.width -import androidx.compose.material.Divider -import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier -import androidx.compose.ui.platform.LocalDensity -import androidx.compose.ui.platform.testTag -import androidx.compose.ui.zIndex -import org.dhis2.composetable.model.ItemHeaderUiState -import org.dhis2.composetable.model.ResizingCell -import org.dhis2.composetable.model.TableDialogModel -import org.dhis2.composetable.model.TableModel -import org.dhis2.composetable.model.TableRowModel -import org.dhis2.composetable.ui.semantics.ROW_TEST_TAG - -@Composable -fun TableItemRow( - tableModel: TableModel, - horizontalScrollState: ScrollState, - rowModel: TableRowModel, - rowHeaderCellStyle: @Composable - (rowHeaderIndex: Int?) -> CellStyle, - onRowHeaderClick: (rowHeaderIndex: Int?) -> Unit, - onDecorationClick: (dialogModel: TableDialogModel) -> Unit, - onHeaderResize: (Float) -> Unit, - onResizing: (ResizingCell?) -> Unit, -) { - Column( - Modifier - .testTag("$ROW_TEST_TAG${rowModel.rowHeader.row}") - .width(IntrinsicSize.Min), - ) { - Row(Modifier.height(IntrinsicSize.Min)) { - Box( - modifier = Modifier - .fillMaxHeight() - .zIndex(1f), - ) { - ItemHeader( - ItemHeaderUiState( - tableId = tableModel.id ?: "", - rowHeader = rowModel.rowHeader, - cellStyle = rowHeaderCellStyle(rowModel.rowHeader.row), - width = with(LocalDensity.current) { - TableTheme.dimensions.rowHeaderWidth(tableModel.id ?: "").toDp() - }, - maxLines = rowModel.maxLines, - onCellSelected = onRowHeaderClick, - onDecorationClick = onDecorationClick, - onHeaderResize = onHeaderResize, - onResizing = onResizing, - ), - ) - } - ItemValues( - tableId = tableModel.id ?: "", - horizontalScrollState = horizontalScrollState, - cellValues = rowModel.values, - overridenValues = tableModel.overwrittenValues, - maxLines = rowModel.maxLines, - tableHeaderModel = tableModel.tableHeaderModel, - options = rowModel.dropDownOptions ?: emptyList(), - headerLabel = rowModel.rowHeader.title, - ) - } - if (!rowModel.isLastRow) { - Divider( - modifier = Modifier - .fillMaxWidth() - .padding(end = TableTheme.dimensions.tableEndExtraScroll), - ) - } - } -} diff --git a/compose-table/src/main/java/org/dhis2/composetable/ui/TableSelection.kt b/compose-table/src/main/java/org/dhis2/composetable/ui/TableSelection.kt deleted file mode 100644 index 1d1c157104..0000000000 --- a/compose-table/src/main/java/org/dhis2/composetable/ui/TableSelection.kt +++ /dev/null @@ -1,108 +0,0 @@ -package org.dhis2.composetable.ui - -import androidx.compose.runtime.staticCompositionLocalOf - -sealed class TableSelection(open val tableId: String) { - data class Unselected( - val previousSelectedTableId: String? = null, - ) : TableSelection(previousSelectedTableId ?: "") - - data class AllCellSelection( - override val tableId: String, - ) : TableSelection(tableId) - - data class RowSelection( - override val tableId: String, - val rowIndex: Int, - ) : TableSelection(tableId) - - data class ColumnSelection( - override val tableId: String, - val columnIndex: Int, - val columnHeaderRow: Int, - val childrenOfSelectedHeader: Map, - ) : TableSelection(tableId) - - data class HeaderCellRange(val size: Int, val firstIndex: Int, val lastIndex: Int) { - fun isInRange(columnIndex: Int): Boolean { - return columnIndex in firstIndex..lastIndex - } - } - - data class CellSelection( - override val tableId: String, - val columnIndex: Int, - val rowIndex: Int, - val globalIndex: Int, - ) : TableSelection(tableId) - - fun getSelectedCellRowIndex(selectedTableId: String): Int = - if (selectedTableId == tableId && this is CellSelection) { - this.rowIndex - } else { - -1 - } - - fun isCornerSelected(selectedTableId: String) = - selectedTableId == tableId && (this is AllCellSelection) - - fun isHeaderSelected(selectedTableId: String, columnIndex: Int, columnHeaderRowIndex: Int) = - this.isCornerSelected(selectedTableId) || - selectedTableId == tableId && (this is ColumnSelection) && - this.columnIndex == columnIndex && - this.columnHeaderRow == columnHeaderRowIndex - - fun isParentHeaderSelected( - selectedTableId: String, - columnIndex: Int, - columnHeaderRowIndex: Int, - ) = selectedTableId == tableId && (this is ColumnSelection) && - ( - when { - columnHeaderRowIndex < this.columnHeaderRow -> false - columnHeaderRowIndex == this.columnHeaderRow -> this.columnIndex != columnIndex - else -> this.childrenOfSelectedHeader[columnHeaderRowIndex]?.isInRange( - columnIndex, - ) ?: false - } - ) - - fun isRowSelected(selectedTableId: String, rowHeaderIndex: Int) = - this.isCornerSelected(selectedTableId) || - selectedTableId == tableId && (this is RowSelection) && - this.rowIndex == rowHeaderIndex - - fun isOtherRowSelected(selectedTableId: String, rowHeaderIndex: Int) = - selectedTableId == tableId && (this is RowSelection) && - this.rowIndex != rowHeaderIndex - - fun isCellSelected(selectedTableId: String, columnIndex: Int, rowIndex: Int) = - this.tableId == selectedTableId && (this is CellSelection) && - this.columnIndex == columnIndex && - this.rowIndex == rowIndex - - fun isCellParentSelected(selectedTableId: String, columnIndex: Int, rowIndex: Int) = - when (this) { - is AllCellSelection -> isCornerSelected(selectedTableId) - is ColumnSelection -> - if (childrenOfSelectedHeader.isEmpty()) { - isCellValid(columnIndex, rowIndex) && - this.columnIndex == columnIndex && - this.tableId == selectedTableId - } else { - isCellValid(columnIndex, rowIndex) && - this.tableId == selectedTableId && - this.childrenOfSelectedHeader.values.last().isInRange(columnIndex) - } - is RowSelection -> { - isRowSelected(selectedTableId, rowIndex) - } - else -> false - } - - private fun isCellValid(columnIndex: Int, rowIndex: Int): Boolean { - return columnIndex != -1 && rowIndex != -1 - } -} - -val LocalTableSelection = staticCompositionLocalOf { TableSelection.Unselected() } diff --git a/compose-table/src/main/java/org/dhis2/composetable/ui/TableTheme.kt b/compose-table/src/main/java/org/dhis2/composetable/ui/TableTheme.kt deleted file mode 100644 index 6e3af046c2..0000000000 --- a/compose-table/src/main/java/org/dhis2/composetable/ui/TableTheme.kt +++ /dev/null @@ -1,51 +0,0 @@ -package org.dhis2.composetable.ui - -import androidx.compose.material.MaterialTheme -import androidx.compose.runtime.Composable -import androidx.compose.runtime.CompositionLocalProvider -import org.dhis2.composetable.actions.DefaultValidator -import org.dhis2.composetable.actions.TableResizeActions -import org.dhis2.composetable.actions.Validator -import org.dhis2.composetable.ui.compositions.LocalTableResizeActions -import org.dhis2.composetable.ui.compositions.LocalValidator - -@Composable -fun TableTheme( - tableColors: TableColors?, - tableDimensions: TableDimensions? = LocalTableDimensions.current, - tableConfiguration: TableConfiguration? = LocalTableConfiguration.current, - tableValidator: Validator? = null, - tableResizeActions: TableResizeActions? = null, - content: @Composable - () -> Unit, -) { - CompositionLocalProvider( - LocalTableColors provides (tableColors ?: TableColors()), - LocalTableDimensions provides (tableDimensions ?: TableDimensions()), - LocalTableConfiguration provides (tableConfiguration ?: TableConfiguration()), - LocalValidator provides (tableValidator ?: DefaultValidator()), - LocalTableResizeActions provides (tableResizeActions ?: object : TableResizeActions {}), - ) { - MaterialTheme( - content = content, - ) - } -} - -object TableTheme { - val colors: TableColors - @Composable - get() = LocalTableColors.current - val dimensions: TableDimensions - @Composable - get() = LocalTableDimensions.current - val configuration: TableConfiguration - @Composable - get() = LocalTableConfiguration.current - val tableSelection - @Composable - get() = LocalTableSelection.current - val validator - @Composable - get() = LocalValidator.current -} diff --git a/compose-table/src/main/java/org/dhis2/composetable/ui/TextInput.kt b/compose-table/src/main/java/org/dhis2/composetable/ui/TextInput.kt deleted file mode 100644 index de38acc3d6..0000000000 --- a/compose-table/src/main/java/org/dhis2/composetable/ui/TextInput.kt +++ /dev/null @@ -1,396 +0,0 @@ -package org.dhis2.composetable.ui - -import android.graphics.Rect -import android.view.ViewTreeObserver -import androidx.compose.foundation.background -import androidx.compose.foundation.layout.Arrangement -import androidx.compose.foundation.layout.Arrangement.Absolute.spacedBy -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.Spacer -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.layout.size -import androidx.compose.foundation.layout.wrapContentHeight -import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.foundation.text.BasicTextField -import androidx.compose.foundation.text.KeyboardActions -import androidx.compose.foundation.text.KeyboardOptions -import androidx.compose.material.Divider -import androidx.compose.material.Icon -import androidx.compose.material.Text -import androidx.compose.runtime.Composable -import androidx.compose.runtime.DisposableEffect -import androidx.compose.runtime.State -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember -import androidx.compose.runtime.setValue -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.focus.FocusRequester -import androidx.compose.ui.focus.focusRequester -import androidx.compose.ui.focus.onFocusChanged -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.layout.onSizeChanged -import androidx.compose.ui.platform.LocalFocusManager -import androidx.compose.ui.platform.LocalView -import androidx.compose.ui.platform.testTag -import androidx.compose.ui.res.painterResource -import androidx.compose.ui.semantics.SemanticsPropertyKey -import androidx.compose.ui.semantics.SemanticsPropertyReceiver -import androidx.compose.ui.semantics.semantics -import androidx.compose.ui.text.AnnotatedString -import androidx.compose.ui.text.SpanStyle -import androidx.compose.ui.text.TextRange -import androidx.compose.ui.text.TextStyle -import androidx.compose.ui.text.buildAnnotatedString -import androidx.compose.ui.text.input.ImeAction -import androidx.compose.ui.text.input.TextFieldValue -import androidx.compose.ui.text.style.TextAlign -import androidx.compose.ui.text.withStyle -import androidx.compose.ui.tooling.preview.Preview -import androidx.compose.ui.unit.dp -import androidx.compose.ui.unit.sp -import org.dhis2.composetable.R -import org.dhis2.composetable.actions.TextInputInteractions -import org.dhis2.composetable.model.TextInputModel -import org.dhis2.composetable.model.extensions.keyboardCapitalization -import org.dhis2.composetable.model.extensions.toKeyboardType -import org.hisp.dhis.mobile.ui.designsystem.component.IconButton - -@Composable -fun TextInput( - textInputModel: TextInputModel, - textInputInteractions: TextInputInteractions, - focusRequester: FocusRequester, -) { - val tableDimensions = LocalTableDimensions.current - Column( - modifier = Modifier - .testTag(INPUT_TEST_TAG) - .onSizeChanged { tableDimensions.textInputHeight = it.height } - .fillMaxWidth() - .background( - color = Color.White, - shape = RoundedCornerShape(topStart = 16.dp, topEnd = 16.dp), - ) - .padding(start = 16.dp, end = 4.dp, top = 16.dp, bottom = 4.dp), - verticalArrangement = spacedBy(8.dp), - ) { - InputTitle(textInputModel.mainLabel, textInputModel.secondaryLabels) - TextInputContent( - textInputModel, - onTextChanged = textInputInteractions::onTextChanged, - onSave = textInputInteractions::onSave, - onNextSelected = textInputInteractions::onNextSelected, - focusRequester = focusRequester, - ) - } -} - -enum class Keyboard { - Opened, Closed -} - -@Composable -fun keyboardAsState(): State { - val keyboardState = remember { mutableStateOf(Keyboard.Closed) } - val view = LocalView.current - DisposableEffect(view) { - val onGlobalListener = ViewTreeObserver.OnGlobalLayoutListener { - val rect = Rect() - view.getWindowVisibleDisplayFrame(rect) - val screenHeight = view.rootView.height - val keypadHeight = screenHeight - rect.bottom - keyboardState.value = if (keypadHeight > screenHeight * 0.15) { - Keyboard.Opened - } else { - Keyboard.Closed - } - } - view.viewTreeObserver.addOnGlobalLayoutListener(onGlobalListener) - - onDispose { - view.viewTreeObserver.removeOnGlobalLayoutListener(onGlobalListener) - } - } - - return keyboardState -} - -@Composable -private fun InputTitle(mainTitle: String, secondaryTitle: List) { - Row( - modifier = Modifier - .padding(end = 12.dp) - .fillMaxWidth() - .semantics { - mainLabel = mainTitle - secondaryLabel = secondaryTitle.joinToString(separator = ",") - }, - ) { - Text( - text = displayName(mainTitle, secondaryTitle), - fontSize = 10.sp, - maxLines = 1, - ) - } -} - -@Composable -private fun TextInputContent( - textInputModel: TextInputModel, - onTextChanged: (TextInputModel) -> Unit, - onSave: () -> Unit, - onNextSelected: () -> Unit, - focusRequester: FocusRequester, -) { - val focusManager = LocalFocusManager.current - - var hasFocus by remember { mutableStateOf(false) } - - val dividerColor = dividerColor( - hasError = textInputModel.error != null, - hasWarning = textInputModel.warning != null, - hasFocus = hasFocus, - ) - - val keyboardOptions by remember(textInputModel.keyboardInputType) { - mutableStateOf( - KeyboardOptions( - capitalization = textInputModel.keyboardInputType.keyboardCapitalization(), - imeAction = ImeAction.Next, - keyboardType = textInputModel.keyboardInputType.toKeyboardType(), - ), - ) - } - - val onActionIconClick = remember { - { - if (textInputModel.actionIconCanBeClicked(hasFocus)) { - focusManager.clearFocus(force = true) - onSave() - } else { - focusRequester.requestFocus() - } - } - } - - var textFieldValueState by remember(textInputModel) { - mutableStateOf( - TextFieldValue( - text = textInputModel.currentValue ?: "", - selection = TextRange(textInputModel.currentValue?.length ?: 0), - ), - ) - } - - Column { - Row( - verticalAlignment = Alignment.CenterVertically, - ) { - Column( - modifier = Modifier - .fillMaxWidth() - .weight(1f), - ) { - BasicTextField( - modifier = Modifier - .testTag(INPUT_TEST_FIELD_TEST_TAG) - .focusRequester(focusRequester) - .fillMaxWidth() - .wrapContentHeight() - .onFocusChanged { - hasFocus = it.isFocused - if (!it.isFocused) { - onSave() - } - }, - value = textFieldValueState, - onValueChange = { - textFieldValueState = it - onTextChanged( - textInputModel.copy( - currentValue = it.text, - selection = it.selection, - error = null, - ), - ) - }, - textStyle = TextStyle.Default.copy( - fontSize = 12.sp, - textAlign = TextAlign.Start, - ), - keyboardOptions = keyboardOptions, - keyboardActions = KeyboardActions( - onNext = { - onNextSelected() - }, - ), - ) - Spacer(modifier = Modifier.size(3.dp)) - Divider( - color = dividerColor, - thickness = 1.dp, - ) - } - Spacer(modifier = Modifier.size(8.dp)) - TextInputContentActionIcon( - modifier = Modifier - .testTag(INPUT_ICON_TEST_TAG), - hasFocus = hasFocus, - onActionIconClick = onActionIconClick, - ) - } - if (textInputModel.hasErrorOrWarning()) { - Text( - modifier = Modifier.testTag(INPUT_ERROR_MESSAGE_TEST_TAG), - text = textInputModel.errorOrWarningMessage()!!, - style = TextStyle( - color = LocalTableColors.current.cellTextColor( - textInputModel.error != null, - textInputModel.warning != null, - true, - ), - fontSize = 10.sp, - ), - ) - } - if (textInputModel.hasHelperText()) { - Text( - modifier = Modifier - .testTag(INPUT_HELPER_TEXT_TEST_TAG), - text = textInputModel.helperText!!, - style = TextStyle( - color = LocalTableColors.current.headerText, - ), - fontSize = 10.sp, - ) - } - } -} - -@Composable -private fun dividerColor(hasError: Boolean, hasWarning: Boolean, hasFocus: Boolean) = when { - hasError -> LocalTableColors.current.errorColor - hasWarning -> LocalTableColors.current.warningColor - hasFocus -> LocalTableColors.current.primary - else -> LocalTableColors.current.disabledCellText -} - -@Composable -private fun TextInputContentActionIcon( - modifier: Modifier = Modifier, - hasFocus: Boolean, - onActionIconClick: () -> Unit, -) { - val icon = if (hasFocus) { - R.drawable.ic_finish_edit_input - } else { - R.drawable.ic_edit_input - } - - Row( - horizontalArrangement = Arrangement.SpaceAround, - verticalAlignment = Alignment.CenterVertically, - ) { - IconButton( - modifier = modifier - .semantics { - drawableId = icon - }, - onClick = onActionIconClick, - icon = { - Icon( - painter = painterResource(id = icon), - tint = LocalTableColors.current.primary, - contentDescription = "", - ) - }, - ) - } -} - -@Composable -fun displayName( - dataElementName: String, - categoryOptionComboOptionNames: List, -): AnnotatedString { - return buildAnnotatedString { - withStyle( - style = SpanStyle( - color = LocalTableColors.current.headerText, - ), - ) { - append(dataElementName) - } - - categoryOptionComboOptionNames.forEach { catOptionName -> - withStyle( - style = SpanStyle( - color = LocalTableColors.current.primary, - ), - ) { - append(" / ") - } - withStyle( - style = SpanStyle( - color = LocalTableColors.current.disabledCellText, - ), - ) { - append(catOptionName) - } - } - } -} - -@Preview -@Composable -fun DefaultTextInputStatusPreview() { - val previewTextInput = TextInputModel( - id = "", - mainLabel = "Row", - secondaryLabels = listOf("header 1", "header 2"), - helperText = "description", - currentValue = "Test", - ) - - TextInput( - textInputModel = previewTextInput, - textInputInteractions = object : TextInputInteractions {}, - focusRequester = FocusRequester(), - ) -} - -@Preview -@Composable -fun DefaultTextInputErrorStatusPreview() { - val previewTextInput = TextInputModel( - id = "", - mainLabel = "Row", - secondaryLabels = listOf("header 1", "header 2"), - error = "error message", - helperText = "description", - currentValue = "Test", - ) - - TextInput( - textInputModel = previewTextInput, - textInputInteractions = object : TextInputInteractions {}, - focusRequester = FocusRequester(), - ) -} - -const val INPUT_TEST_TAG = "INPUT_TEST_TAG" -const val INPUT_TEST_FIELD_TEST_TAG = "INPUT_TEST_FIELD_TEST_TAG" -const val INPUT_ERROR_MESSAGE_TEST_TAG = "INPUT_ERROR_MESSAGE_TEST_TAG" -const val INPUT_ICON_TEST_TAG = "INPUT_ICON_TEST_TAG" -const val INPUT_HELPER_TEXT_TEST_TAG = "INPUT_HELPER_TEXT_TEST_TAG" - -val DrawableId = SemanticsPropertyKey("DrawableResId") -var SemanticsPropertyReceiver.drawableId by DrawableId -val MainLabel = SemanticsPropertyKey("MainLabel") -var SemanticsPropertyReceiver.mainLabel by MainLabel -val SecondaryLabels = SemanticsPropertyKey("SecondaryLabels") -var SemanticsPropertyReceiver.secondaryLabel by SecondaryLabels diff --git a/compose-table/src/main/java/org/dhis2/composetable/ui/VerticalResizing.kt b/compose-table/src/main/java/org/dhis2/composetable/ui/VerticalResizing.kt deleted file mode 100644 index 772e5e213f..0000000000 --- a/compose-table/src/main/java/org/dhis2/composetable/ui/VerticalResizing.kt +++ /dev/null @@ -1,130 +0,0 @@ -package org.dhis2.composetable.ui - -import androidx.compose.foundation.background -import androidx.compose.foundation.gestures.detectDragGestures -import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.fillMaxHeight -import androidx.compose.foundation.layout.offset -import androidx.compose.foundation.layout.size -import androidx.compose.foundation.layout.width -import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.material.Icon -import androidx.compose.runtime.Composable -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember -import androidx.compose.runtime.setValue -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.draw.drawBehind -import androidx.compose.ui.geometry.Offset -import androidx.compose.ui.geometry.Size -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.graphics.graphicsLayer -import androidx.compose.ui.graphics.vector.ImageVector -import androidx.compose.ui.input.pointer.pointerInput -import androidx.compose.ui.layout.onGloballyPositioned -import androidx.compose.ui.layout.positionInRoot -import androidx.compose.ui.platform.LocalDensity -import androidx.compose.ui.res.vectorResource -import androidx.compose.ui.unit.IntOffset -import androidx.compose.ui.unit.dp -import org.dhis2.composetable.R -import org.dhis2.composetable.model.ResizingCell -import kotlin.math.abs -import kotlin.math.roundToInt - -@Composable -fun VerticalResizingView(modifier: Modifier = Modifier, provideResizingCell: () -> ResizingCell?) { - val colorPrimary = TableTheme.colors.primary - provideResizingCell()?.let { resizingCell -> - val offsetX = resizingCell.initialPosition.x + resizingCell.draggingOffsetX - Box( - modifier - .offset { IntOffset(offsetX.roundToInt(), 0) } - .fillMaxHeight() - .drawBehind { - drawRect( - color = colorPrimary, - topLeft = Offset(0f, 0f), - size = Size(2.dp.toPx(), size.height), - ) - } - .graphicsLayer(clip = false), - ) { - Icon( - modifier = Modifier - .align(Alignment.TopCenter) - .offset { - IntOffset( - -15.dp.value.toInt(), - resizingCell.initialPosition.y.roundToInt(), - ) - } - .background( - color = colorPrimary, - shape = RoundedCornerShape(16.dp), - ) - .size(14.dp), - imageVector = ImageVector.vectorResource(id = R.drawable.ic_row_widener), - contentDescription = "", - tint = Color.White, - ) - } - } -} - -@Composable -fun VerticalResizingRule( - modifier: Modifier = Modifier, - checkMaxMinCondition: (dimensions: TableDimensions, currentOffsetX: Float) -> Boolean, - onHeaderResize: (Float) -> Unit, - onResizing: (ResizingCell?) -> Unit, -) { - var dimensions by remember { mutableStateOf(null) } - dimensions = TableTheme.dimensions - - val minOffset = with(LocalDensity.current) { 5.dp.toPx() } - var offsetX by remember { mutableStateOf(minOffset) } - var positionInRoot by remember { mutableStateOf(Offset.Zero) } - - Box( - modifier - .fillMaxHeight() - .width(48.dp) - .offset(24.dp) - .pointerInput(Unit) { - detectDragGestures( - onDragEnd = { - if (abs(offsetX) > minOffset) { - onHeaderResize(offsetX) - } - offsetX = minOffset - onResizing(null) - }, - ) { change, dragAmount -> - change.consume() - if (checkMaxMinCondition(dimensions!!, offsetX + dragAmount.x)) { - offsetX += dragAmount.x - } - onResizing(ResizingCell(positionInRoot, offsetX)) - } - }, - ) { - Icon( - modifier = Modifier - .align(Alignment.Center) - .background( - color = TableTheme.colors.primary, - shape = RoundedCornerShape(16.dp), - ) - .size(14.dp) - .onGloballyPositioned { coordinates -> - positionInRoot = coordinates.positionInRoot() - }, - imageVector = ImageVector.vectorResource(id = R.drawable.ic_row_widener), - contentDescription = "", - tint = Color.White, - ) - } -} diff --git a/compose-table/src/main/java/org/dhis2/composetable/ui/compositions/TableCompositionLocal.kt b/compose-table/src/main/java/org/dhis2/composetable/ui/compositions/TableCompositionLocal.kt deleted file mode 100644 index 9df879e54d..0000000000 --- a/compose-table/src/main/java/org/dhis2/composetable/ui/compositions/TableCompositionLocal.kt +++ /dev/null @@ -1,16 +0,0 @@ -package org.dhis2.composetable.ui.compositions - -import androidx.compose.runtime.compositionLocalOf -import androidx.compose.runtime.staticCompositionLocalOf -import org.dhis2.composetable.actions.DefaultValidator -import org.dhis2.composetable.actions.TableInteractions -import org.dhis2.composetable.actions.TableResizeActions -import org.dhis2.composetable.actions.Validator -import org.dhis2.composetable.model.TableCell - -val LocalCurrentCellValue = compositionLocalOf<() -> String?> { { "" } } -val LocalUpdatingCell = compositionLocalOf { null } -val LocalInteraction = compositionLocalOf { object : TableInteractions {} } -val LocalTableResizeActions = - compositionLocalOf { object : TableResizeActions {} } -val LocalValidator = staticCompositionLocalOf { DefaultValidator() } diff --git a/compose-table/src/main/java/org/dhis2/composetable/ui/extensions/BottomSheetStateExceptions.kt b/compose-table/src/main/java/org/dhis2/composetable/ui/extensions/BottomSheetStateExceptions.kt deleted file mode 100644 index 62f364b877..0000000000 --- a/compose-table/src/main/java/org/dhis2/composetable/ui/extensions/BottomSheetStateExceptions.kt +++ /dev/null @@ -1,20 +0,0 @@ -package org.dhis2.composetable.ui.extensions - -import androidx.compose.material.BottomSheetState -import androidx.compose.material.ExperimentalMaterialApi - -@OptIn(ExperimentalMaterialApi::class) -suspend fun BottomSheetState.collapseIfExpanded(onCollapse: () -> Unit) { - if (isExpanded) { - onCollapse() - collapse() - } -} - -@OptIn(ExperimentalMaterialApi::class) -suspend fun BottomSheetState.expandIfCollapsed(onExpand: () -> Unit) { - if (isCollapsed) { - onExpand() - expand() - } -} diff --git a/compose-table/src/main/java/org/dhis2/composetable/ui/extensions/LazyListScopeExtensions.kt b/compose-table/src/main/java/org/dhis2/composetable/ui/extensions/LazyListScopeExtensions.kt deleted file mode 100644 index 300d871025..0000000000 --- a/compose-table/src/main/java/org/dhis2/composetable/ui/extensions/LazyListScopeExtensions.kt +++ /dev/null @@ -1,20 +0,0 @@ -package org.dhis2.composetable.ui.extensions - -import androidx.compose.foundation.ExperimentalFoundationApi -import androidx.compose.foundation.lazy.LazyItemScope -import androidx.compose.foundation.lazy.LazyListScope -import androidx.compose.runtime.Composable - -@ExperimentalFoundationApi -fun LazyListScope.fixedStickyHeader( - fixHeader: Boolean = true, - key: Any? = null, - contentType: Any? = null, - content: @Composable LazyItemScope.() -> Unit, -) { - if (fixHeader) { - stickyHeader("${key}_sticky", contentType = contentType, content = content) - } else { - item("${key}_non_sticky", contentType = contentType, content = content) - } -} diff --git a/compose-table/src/main/java/org/dhis2/composetable/ui/extensions/LazyListStateExtensions.kt b/compose-table/src/main/java/org/dhis2/composetable/ui/extensions/LazyListStateExtensions.kt deleted file mode 100644 index 9e28fdfe2d..0000000000 --- a/compose-table/src/main/java/org/dhis2/composetable/ui/extensions/LazyListStateExtensions.kt +++ /dev/null @@ -1,8 +0,0 @@ -package org.dhis2.composetable.ui.extensions - -import androidx.compose.foundation.gestures.animateScrollBy -import androidx.compose.foundation.lazy.LazyListState - -suspend fun LazyListState.animateScrollToVisibleItems() { - animateScrollBy(layoutInfo.viewportSize.height / 2f) -} diff --git a/compose-table/src/main/java/org/dhis2/composetable/ui/extensions/StringExtensions.kt b/compose-table/src/main/java/org/dhis2/composetable/ui/extensions/StringExtensions.kt deleted file mode 100644 index cfa069cd8d..0000000000 --- a/compose-table/src/main/java/org/dhis2/composetable/ui/extensions/StringExtensions.kt +++ /dev/null @@ -1,3 +0,0 @@ -package org.dhis2.composetable.ui.extensions - -fun String?.isNumeric() = this?.toDoubleOrNull() != null diff --git a/compose-table/src/main/java/org/dhis2/composetable/ui/modifiers/CellBorder.kt b/compose-table/src/main/java/org/dhis2/composetable/ui/modifiers/CellBorder.kt deleted file mode 100644 index 340b287756..0000000000 --- a/compose-table/src/main/java/org/dhis2/composetable/ui/modifiers/CellBorder.kt +++ /dev/null @@ -1,14 +0,0 @@ -package org.dhis2.composetable.ui.modifiers - -import androidx.compose.foundation.background -import androidx.compose.foundation.border -import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.unit.Dp -import androidx.compose.ui.unit.dp - -fun Modifier.cellBorder(borderWidth: Dp = 1.dp, borderColor: Color, backgroundColor: Color) = - this.then( - border(borderWidth, borderColor) - .background(backgroundColor), - ) diff --git a/compose-table/src/main/java/org/dhis2/composetable/ui/modifiers/CornerBackground.kt b/compose-table/src/main/java/org/dhis2/composetable/ui/modifiers/CornerBackground.kt deleted file mode 100644 index 8d8cc387ba..0000000000 --- a/compose-table/src/main/java/org/dhis2/composetable/ui/modifiers/CornerBackground.kt +++ /dev/null @@ -1,16 +0,0 @@ -package org.dhis2.composetable.ui.modifiers - -import androidx.compose.foundation.background -import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color - -fun Modifier.cornerBackground(isSelected: Boolean, selectedColor: Color, defaultColor: Color) = - this.then( - background( - color = if (isSelected) { - selectedColor - } else { - defaultColor - }, - ), - ) diff --git a/compose-table/src/main/java/org/dhis2/composetable/ui/semantics/TableSemantics.kt b/compose-table/src/main/java/org/dhis2/composetable/ui/semantics/TableSemantics.kt deleted file mode 100644 index 4fe5a206ab..0000000000 --- a/compose-table/src/main/java/org/dhis2/composetable/ui/semantics/TableSemantics.kt +++ /dev/null @@ -1,43 +0,0 @@ -package org.dhis2.composetable.ui.semantics - -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.semantics.SemanticsPropertyKey -import androidx.compose.ui.semantics.SemanticsPropertyReceiver -import androidx.compose.ui.unit.dp - -const val ROW_TEST_TAG = "ROW_TEST_TAG_" -const val CELL_TEST_TAG = "CELL_TEST_TAG_" -const val INFO_ICON = "infoIcon" -const val HEADER_CELL = "HEADER_CELL" -const val MANDATORY_ICON_TEST_TAG = "MANDATORY_ICON_TEST_TAG" -const val CELL_VALUE_TEST_TAG = "CELL_VALUE_TEST_TAG" -const val CELL_ERROR_UNDERLINE_TEST_TAG = "CELL_ERROR_UNDERLINE_TEST_TAG" -val MAX_CELL_WIDTH_SPACE = 96.dp - -/* Row Header Cell */ -val InfoIconId = SemanticsPropertyKey("InfoIconId") -var SemanticsPropertyReceiver.infoIconId by InfoIconId -val TableId = SemanticsPropertyKey("TableId") -var SemanticsPropertyReceiver.tableIdSemantic by TableId -val RowIndex = SemanticsPropertyKey("RowIndex") -var SemanticsPropertyReceiver.rowIndexSemantic by RowIndex -val RowBackground = SemanticsPropertyKey("RowBackground") -var SemanticsPropertyReceiver.rowBackground by RowBackground - -/* Column Header Cell */ -val ColumnBackground = SemanticsPropertyKey("ColumnBackground") -var SemanticsPropertyReceiver.columnBackground by ColumnBackground -val ColumnIndexHeader = SemanticsPropertyKey("ColumnIndexHeader") -var SemanticsPropertyReceiver.columnIndexHeader by ColumnIndexHeader -val RowIndexHeader = SemanticsPropertyKey("RowIndexHeader") -var SemanticsPropertyReceiver.rowIndexHeader by RowIndexHeader -val TableIdColumnHeader = SemanticsPropertyKey("TableIdColumnHeader") -var SemanticsPropertyReceiver.tableIdColumnHeader by TableIdColumnHeader - -/* Cell */ -val CellSelected = SemanticsPropertyKey("CellSelected") -var SemanticsPropertyReceiver.cellSelected by CellSelected -val HasError = SemanticsPropertyKey("HasError") -var SemanticsPropertyReceiver.hasError by HasError -val IsBlocked = SemanticsPropertyKey("IsBlocked") -var SemanticsPropertyReceiver.isBlocked by IsBlocked diff --git a/dhis_android_analytics/src/main/java/dhis2/org/analytics/charts/mappers/GraphToTable.kt b/dhis_android_analytics/src/main/java/dhis2/org/analytics/charts/mappers/GraphToTable.kt index efe1659177..158caf8ca7 100644 --- a/dhis_android_analytics/src/main/java/dhis2/org/analytics/charts/mappers/GraphToTable.kt +++ b/dhis_android_analytics/src/main/java/dhis2/org/analytics/charts/mappers/GraphToTable.kt @@ -30,24 +30,25 @@ import dhis2.org.analytics.charts.data.ChartType import dhis2.org.analytics.charts.data.Graph import dhis2.org.analytics.charts.data.SerieData import dhis2.org.analytics.charts.table.CellModel -import org.dhis2.composetable.actions.TableInteractions -import org.dhis2.composetable.actions.TableResizeActions -import org.dhis2.composetable.model.RowHeader -import org.dhis2.composetable.model.TableCell -import org.dhis2.composetable.model.TableHeader -import org.dhis2.composetable.model.TableHeaderCell -import org.dhis2.composetable.model.TableHeaderRow -import org.dhis2.composetable.model.TableModel -import org.dhis2.composetable.model.TableRowModel -import org.dhis2.composetable.ui.DataTable -import org.dhis2.composetable.ui.LocalTableSelection -import org.dhis2.composetable.ui.TableColors -import org.dhis2.composetable.ui.TableConfiguration -import org.dhis2.composetable.ui.TableDimensions -import org.dhis2.composetable.ui.TableSelection -import org.dhis2.composetable.ui.TableTheme -import org.dhis2.composetable.ui.compositions.LocalInteraction import org.hisp.dhis.android.core.arch.helpers.DateUtils +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.actions.TableInteractions +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.actions.TableResizeActions +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.model.RowHeader +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.model.TableCell +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.model.TableHeader +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.model.TableHeaderCell +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.model.TableHeaderRow +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.model.TableModel +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.model.TableRowModel +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.ui.DataTable +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.ui.LocalTableSelection +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.ui.TableColors +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.ui.TableConfiguration +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.ui.TableDimensions +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.ui.TableSelection +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.ui.TableTheme +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.ui.compositions.LocalInteraction +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.ui.semantics.MAX_CELL_WIDTH_SPACE import org.hisp.dhis.mobile.ui.designsystem.theme.TextColor import kotlin.math.roundToInt @@ -207,7 +208,7 @@ class GraphToTable { TableDimensions( cellVerticalPadding = 11.dp, maxRowHeaderWidth = with(localDensity) { - (conf.screenWidthDp.dp.toPx() - org.dhis2.composetable.ui.semantics.MAX_CELL_WIDTH_SPACE.toPx()) + (conf.screenWidthDp.dp.toPx() - MAX_CELL_WIDTH_SPACE.toPx()) .roundToInt() }, tableHorizontalPadding = 0.dp, @@ -222,7 +223,7 @@ class GraphToTable { defaultRowHeaderWidth = 0, cellVerticalPadding = 11.dp, maxRowHeaderWidth = with(localDensity) { - (conf.screenWidthDp.dp.toPx() - org.dhis2.composetable.ui.semantics.MAX_CELL_WIDTH_SPACE.toPx()) + (conf.screenWidthDp.dp.toPx() - MAX_CELL_WIDTH_SPACE.toPx()) .roundToInt() }, tableHorizontalPadding = 0.dp, diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 6801cecae2..bf28389330 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -207,8 +207,8 @@ deprecated-autoValueParcel = { group = "com.ryanharter.auto.value", name = "auto [plugins] kotlin-compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" } [bundles] -uicomponents-implementation = ["androidx-coreKtx", "androidx-material3", "androidx-material3-window","androidx-material3-adaptative-android", "androidx-material3-adaptative-android", "google-material", "lottie-compose", "dhis2-mobile-designsystem"] -uicomponents-api = ["dhis2-mobile-designsystem", "androidx-compose-constraintlayout", "androidx-compose-preview", "androidx-compose-ui", "google-material-themeadapter", "google-material3-themeadapter"] +uicomponents-implementation = ["androidx-coreKtx", "androidx-material3", "androidx-material3-window","androidx-material3-adaptative-android", "androidx-material3-adaptative-android", "google-material", "lottie-compose"] +uicomponents-api = ["androidx-compose-constraintlayout", "androidx-compose-preview", "androidx-compose-ui", "google-material-themeadapter", "google-material3-themeadapter"] uicomponents-debugapi = ["androidx-compose-uitooling"] uicomponents-androidtest = ["test-junit-ext"] analytics-implementation = ["androidx-cardview", "androidx-constraintlayout"] @@ -217,7 +217,6 @@ analytics-kapt = ["dagger-compiler"] analytics-test = ["test-mockitoCore", "test-mockitoInline", "test-mockitoKotlin", "test-kotlinCoroutines", "test-archCoreTesting"] form-test = ["test-mockitoCore", "test-mockitoInline", "test-mockitoKotlin", "test-testCore", "test-archCoreTesting", "test-kotlinCoroutines"] map-test = ["test-mockitoCore", "test-mockitoInline", "test-mockitoKotlin","test-turbine", "test-archCoreTesting", "test-kotlinCoroutines"] -table-implementation = ["kotlin-serialization-json", "androidx-appcompat", "androidx-activity-compose", "androidx-compose", "androidx-compose-constraintlayout", "androidx-compose-preview", "androidx-compose-ui", "androidx-compose-livedata"] table-debugImplementation = ["androidx-compose-uitooling", "test-ui-test-manifest"] table-test = ["test-junit"] table-androidTest = ["test-compose-ui-test", "test-uiautomator", "test-junitKtx", "test-espresso"] diff --git a/stock-usecase/src/main/java/org/dhis2/android/rtsm/services/StockTableDimensionStore.kt b/stock-usecase/src/main/java/org/dhis2/android/rtsm/services/StockTableDimensionStore.kt index 61027a5ca0..6d8c52f25f 100644 --- a/stock-usecase/src/main/java/org/dhis2/android/rtsm/services/StockTableDimensionStore.kt +++ b/stock-usecase/src/main/java/org/dhis2/android/rtsm/services/StockTableDimensionStore.kt @@ -1,7 +1,7 @@ package org.dhis2.android.rtsm.services -import org.dhis2.composetable.model.TableModel import org.hisp.dhis.android.core.D2 +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.model.TableModel import javax.inject.Inject class StockTableDimensionStore @Inject constructor( diff --git a/stock-usecase/src/main/java/org/dhis2/android/rtsm/ui/home/screens/components/MainContent.kt b/stock-usecase/src/main/java/org/dhis2/android/rtsm/ui/home/screens/components/MainContent.kt index 1165f55596..a2b4455b98 100644 --- a/stock-usecase/src/main/java/org/dhis2/android/rtsm/ui/home/screens/components/MainContent.kt +++ b/stock-usecase/src/main/java/org/dhis2/android/rtsm/ui/home/screens/components/MainContent.kt @@ -58,8 +58,8 @@ import org.dhis2.android.rtsm.ui.managestock.ManageStockViewModel import org.dhis2.android.rtsm.ui.managestock.STOCK_TABLE_ID import org.dhis2.android.rtsm.ui.managestock.components.ManageStockTable import org.dhis2.android.rtsm.ui.scanner.ScannerActivity -import org.dhis2.composetable.actions.TableResizeActions import org.hisp.dhis.mobile.ui.designsystem.component.IconButton +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.actions.TableResizeActions @OptIn(ExperimentalMaterialApi::class) @Composable diff --git a/stock-usecase/src/main/java/org/dhis2/android/rtsm/ui/managestock/ManageStockViewModel.kt b/stock-usecase/src/main/java/org/dhis2/android/rtsm/ui/managestock/ManageStockViewModel.kt index d7b70a3461..421cdd7994 100644 --- a/stock-usecase/src/main/java/org/dhis2/android/rtsm/ui/managestock/ManageStockViewModel.kt +++ b/stock-usecase/src/main/java/org/dhis2/android/rtsm/ui/managestock/ManageStockViewModel.kt @@ -41,15 +41,16 @@ import org.dhis2.android.rtsm.ui.home.model.SnackBarUiState import org.dhis2.android.rtsm.utils.Utils.Companion.isValidStockOnHand import org.dhis2.commons.resources.ResourceManager import org.dhis2.commons.viewmodel.DispatcherProvider -import org.dhis2.composetable.TableConfigurationState -import org.dhis2.composetable.TableScreenState -import org.dhis2.composetable.TableState -import org.dhis2.composetable.actions.Validator -import org.dhis2.composetable.model.KeyboardInputType -import org.dhis2.composetable.model.TableCell -import org.dhis2.composetable.model.TextInputModel -import org.dhis2.composetable.model.ValidationResult + import org.hisp.dhis.android.core.program.ProgramRuleActionType +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.TableConfigurationState +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.TableScreenState +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.TableState +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.actions.Validator +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.model.KeyboardInputType +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.model.TableCell +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.model.TextInputModel +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.model.ValidationResult import org.hisp.dhis.rules.models.RuleEffect import org.jetbrains.annotations.NotNull import java.util.Collections diff --git a/stock-usecase/src/main/java/org/dhis2/android/rtsm/ui/managestock/TableModelMapper.kt b/stock-usecase/src/main/java/org/dhis2/android/rtsm/ui/managestock/TableModelMapper.kt index 5bfd022043..53e6d3c7ec 100644 --- a/stock-usecase/src/main/java/org/dhis2/android/rtsm/ui/managestock/TableModelMapper.kt +++ b/stock-usecase/src/main/java/org/dhis2/android/rtsm/ui/managestock/TableModelMapper.kt @@ -3,16 +3,17 @@ package org.dhis2.android.rtsm.ui.managestock import org.dhis2.android.rtsm.R import org.dhis2.android.rtsm.data.models.StockEntry import org.dhis2.commons.resources.ResourceManager -import org.dhis2.composetable.model.RowHeader -import org.dhis2.composetable.model.TableCell -import org.dhis2.composetable.model.TableHeader -import org.dhis2.composetable.model.TableHeaderCell -import org.dhis2.composetable.model.TableHeaderRow -import org.dhis2.composetable.model.TableModel -import org.dhis2.composetable.model.TableRowModel + import org.hisp.dhis.android.core.arch.helpers.Result import org.hisp.dhis.android.core.common.ValueType import org.hisp.dhis.android.core.common.valuetype.validation.failures.IntegerZeroOrPositiveFailure +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.model.RowHeader +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.model.TableCell +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.model.TableHeader +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.model.TableHeaderCell +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.model.TableHeaderRow +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.model.TableModel +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.model.TableRowModel import javax.inject.Inject const val STOCK_TABLE_ID = "STOCK" diff --git a/stock-usecase/src/main/java/org/dhis2/android/rtsm/ui/managestock/components/ManageStockTable.kt b/stock-usecase/src/main/java/org/dhis2/android/rtsm/ui/managestock/components/ManageStockTable.kt index 158d7f3a7f..6925b715f3 100644 --- a/stock-usecase/src/main/java/org/dhis2/android/rtsm/ui/managestock/components/ManageStockTable.kt +++ b/stock-usecase/src/main/java/org/dhis2/android/rtsm/ui/managestock/components/ManageStockTable.kt @@ -25,14 +25,14 @@ import com.google.android.material.composethemeadapter.MdcTheme import org.dhis2.android.rtsm.R import org.dhis2.android.rtsm.ui.home.model.DataEntryStep import org.dhis2.android.rtsm.ui.managestock.ManageStockViewModel -import org.dhis2.composetable.TableScreenState -import org.dhis2.composetable.actions.TableResizeActions -import org.dhis2.composetable.ui.DataSetTableScreen -import org.dhis2.composetable.ui.TableColors -import org.dhis2.composetable.ui.TableConfiguration -import org.dhis2.composetable.ui.TableDimensions -import org.dhis2.composetable.ui.TableTheme -import org.dhis2.composetable.ui.semantics.MAX_CELL_WIDTH_SPACE +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.TableScreenState +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.actions.TableResizeActions +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.ui.DataSetTableScreen +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.ui.TableColors +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.ui.TableConfiguration +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.ui.TableDimensions +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.ui.TableTheme +import org.hisp.dhis.mobile.ui.designsystem.component.composetable.ui.semantics.MAX_CELL_WIDTH_SPACE import kotlin.math.roundToInt @Composable diff --git a/ui-components/build.gradle.kts b/ui-components/build.gradle.kts index 1021429abc..435804d9d4 100644 --- a/ui-components/build.gradle.kts +++ b/ui-components/build.gradle.kts @@ -57,6 +57,9 @@ dependencies { implementation(libs.bundles.uicomponents.implementation) api(libs.bundles.uicomponents.api) + implementation(libs.dhis2.mobile.designsystem){ + exclude(group = "tech.annexflow.compose", module = "constraintlayout-compose-multiplatform-android") + } debugApi(libs.bundles.uicomponents.debugapi) androidTestImplementation(libs.bundles.uicomponents.androidtest) }