Skip to content

Commit

Permalink
Merge pull request #644 from Orange-OpenSource/623-reduce-library-size
Browse files Browse the repository at this point in the history
623 - Reduce library size
  • Loading branch information
paulinea authored Sep 28, 2023
2 parents 94ae6a4 + a024d98 commit a98f1b3
Show file tree
Hide file tree
Showing 18 changed files with 110 additions and 99 deletions.
1 change: 0 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ dependencies {
implementation(project(":lib-xml"))
implementation(project(":theme-innovation-cup"))

implementation(Dependencies.accompanistFlowLayout)
implementation(Dependencies.accompanistSystemUiController)
implementation(Dependencies.activityCompose)
implementation(Dependencies.appCompat)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

package com.orange.ods.app.ui.components.chips

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.foundation.layout.FlowRow
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
Expand All @@ -25,7 +28,6 @@ import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import coil.compose.rememberAsyncImagePainter
import com.google.accompanist.flowlayout.FlowRow
import com.orange.ods.app.R
import com.orange.ods.app.domain.recipes.LocalRecipes
import com.orange.ods.app.ui.components.utilities.ComponentCustomizationBottomSheetScaffold
Expand All @@ -41,7 +43,7 @@ import com.orange.ods.compose.component.chip.OdsFilterChip
import com.orange.ods.compose.component.list.OdsListItem
import com.orange.ods.compose.component.list.OdsSwitchTrailing

@OptIn(ExperimentalMaterialApi::class)
@OptIn(ExperimentalMaterialApi::class, ExperimentalLayoutApi::class)
@Composable
fun ChipFilter() {
val chipCustomizationState = rememberChipCustomizationState(chipType = rememberSaveable { mutableStateOf(ChipCustomizationState.ChipType.Filter) })
Expand Down Expand Up @@ -73,7 +75,10 @@ fun ChipFilter() {
}) {
var selectedChipIndexes by rememberSaveable { mutableStateOf(emptySet<Int>()) }
ChipTypeDemo(chipType = chipType.value) {
FlowRow(modifier = Modifier.fillMaxWidth(), mainAxisSpacing = dimensionResource(id = com.orange.ods.R.dimen.spacing_s)) {
FlowRow(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.spacedBy(dimensionResource(id = com.orange.ods.R.dimen.spacing_s))
) {
recipe.ingredients.forEachIndexed { index, ingredient ->
OdsFilterChip(
text = ingredient.food.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.Colors
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
Expand Down Expand Up @@ -57,15 +56,10 @@ import com.orange.ods.compose.text.OdsTextCaption
import com.orange.ods.compose.text.OdsTextH5
import com.orange.ods.compose.text.OdsTextH6
import com.orange.ods.compose.theme.OdsTheme
import com.orange.ods.theme.colors.OdsColors
import com.orange.ods.theme.colors.OdsFunctionalColors
import com.orange.ods.theme.guideline.GuidelineColor
import com.orange.ods.theme.guideline.GuidelineColorType
import com.orange.ods.theme.guideline.toHexString
import com.orange.ods.theme.guideline.toRgbString
import kotlin.reflect.KProperty
import kotlin.reflect.full.extensionReceiverParameter
import kotlin.reflect.full.memberProperties

@Composable
fun GuidelineColorScreen() {
Expand Down Expand Up @@ -147,7 +141,7 @@ private fun RowScope.SmallColorItem(color: GuidelineColor) {
val openDialog = remember { mutableStateOf(false) }
val context = LocalContext.current
val clipboardManager = LocalClipboardManager.current
val colorValue = color.getValue()
val colorValue = color.getValue(OdsTheme.colors)
Column(
modifier = Modifier
.weight(0.33f)
Expand Down Expand Up @@ -179,7 +173,7 @@ private fun RowScope.BigColorItem(color: GuidelineColor) {
val openDialog = remember { mutableStateOf(false) }
val context = LocalContext.current
val clipboardManager = LocalClipboardManager.current
val colorValue = color.getValue()
val colorValue = color.getValue(OdsTheme.colors)
Column(
modifier = Modifier
.weight(0.5f)
Expand All @@ -203,7 +197,7 @@ private fun RowScope.BigColorItem(color: GuidelineColor) {
text = color.getName(),
modifier = Modifier.padding(top = dimensionResource(id = com.orange.ods.R.dimen.spacing_xs))
)
OdsTextBody1(text = color.callable.name)
OdsTextBody1(text = color.callableName)
OdsTextCaption(
modifier = Modifier.padding(top = dimensionResource(id = com.orange.ods.R.dimen.spacing_xs)),
text = colorValue.toHexString()
Expand All @@ -221,7 +215,7 @@ private fun RowScope.BigColorItem(color: GuidelineColor) {
fun DialogColor(color: GuidelineColor, openDialog: MutableState<Boolean>) {
val context = LocalContext.current
val clipboardManager = LocalClipboardManager.current
val colorValue = color.getValue()
val colorValue = color.getValue(OdsTheme.colors)
Dialog(
onDismissRequest = { openDialog.value = false },
) {
Expand All @@ -244,7 +238,7 @@ fun DialogColor(color: GuidelineColor, openDialog: MutableState<Boolean>) {
OdsTextH5(text = color.getName())
OdsTextBody1(
modifier = Modifier.padding(top = dimensionResource(id = com.orange.ods.R.dimen.spacing_xs)),
text = color.callable.name
text = color.callableName
)
OdsTextBody1(
modifier = Modifier.padding(top = dimensionResource(id = com.orange.ods.R.dimen.spacing_s)),
Expand Down Expand Up @@ -279,16 +273,3 @@ private fun copyColorToClipboard(context: Context, color: Color, clipboardManage
.makeText(context, text, Toast.LENGTH_SHORT)
.show()
}

@Composable
fun GuidelineColor.getValue(): Color {
val isColorsProperty = OdsColors::class.memberProperties.filterIsInstance<KProperty<Color>>().contains(callable)
val isFunctionalColorsProperty = OdsFunctionalColors::class.memberProperties.filterIsInstance<KProperty<Color>>().contains(callable)
val isColorsExtensionProperty = callable.extensionReceiverParameter?.type?.classifier == Colors::class

return when {
isColorsProperty || isColorsExtensionProperty -> callable.call(OdsTheme.colors)
isFunctionalColorsProperty -> callable.call(OdsTheme.colors.functional)
else -> callable.call()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ import com.orange.ods.app.ui.components.Component
import com.orange.ods.app.ui.components.Variant
import com.orange.ods.app.ui.components.components
import com.orange.ods.app.ui.guidelines.color.DialogColor
import com.orange.ods.app.ui.guidelines.color.getValue
import com.orange.ods.app.ui.guidelines.spacing.Spacing
import com.orange.ods.app.ui.utilities.DrawableManager
import com.orange.ods.compose.component.list.OdsListItem
import com.orange.ods.compose.component.list.OdsListItemIcon
import com.orange.ods.compose.component.list.OdsListItemIconType
import com.orange.ods.compose.component.list.iconType
import com.orange.ods.compose.theme.OdsTheme
import com.orange.ods.extension.orElse
import com.orange.ods.theme.guideline.GuidelineColor
import com.orange.ods.theme.guideline.toHexString
Expand Down Expand Up @@ -107,12 +107,13 @@ fun SearchScreen(
)
}
.plus(filteredGuidelineColors.map { guidelineColor ->
val color = guidelineColor.getValue(OdsTheme.colors)
SearchResult(
guidelineColor.getName(),
0,
image = null,
color = guidelineColor.getValue(),
subtitle = guidelineColor.getValue().toHexString(),
color = color,
subtitle = color.toHexString(),
data = guidelineColor
)
})
Expand Down Expand Up @@ -162,7 +163,7 @@ fun SearchScreen(
items(searchResults) { item ->
val openDialog = remember { mutableStateOf(false) }
val guidelineColor = filteredGuidelineColors.firstOrNull { guidelineColor ->
guidelineColor.getName() == item.title && guidelineColor.getValue() == item.color
guidelineColor.getName() == item.title && guidelineColor.getValue(OdsTheme.colors) == item.color
}
OdsListItem(
text = item.title,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ package com.orange.ods.gradle
object Dependencies {

const val accompanistDrawablePainter = "com.google.accompanist:accompanist-drawablepainter:${Versions.accompanist}"
const val accompanistFlowLayout = "com.google.accompanist:accompanist-flowlayout:${Versions.accompanist}"
const val accompanistPager = "com.google.accompanist:accompanist-pager:${Versions.accompanist}"
const val accompanistPagerIndicators = "com.google.accompanist:accompanist-pager-indicators:${Versions.accompanist}"
const val accompanistSystemUiController = "com.google.accompanist:accompanist-systemuicontroller:${Versions.accompanist}"
const val activityCompose = "androidx.activity:activity-compose:${Versions.activity}"
const val androidGradlePlugin = "com.android.tools.build:gradle:${Versions.androidGradlePlugin}"
Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

- \[Lib\] Update `OdsHorizontalCard`, `OdsSmallCard`, `OdsVerticalHeaderFirstCard` and `OdsVerticalImageFirstCard` APIs ([#597](https://github.com/Orange-OpenSource/ods-android/issues/597))
- \[Lib\] Remove several dependencies to reduce consumer app size ([#623](https://github.com/Orange-OpenSource/ods-android/issues/623))

### Fixed

Expand Down
2 changes: 0 additions & 2 deletions lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ dependencies {
api(project(":theme-contract"))
api(project(":theme-orange"))

implementation(Dependencies.accompanistFlowLayout)
implementation(Dependencies.appCompat)
implementation(platform(Dependencies.composeBom))
api(Dependencies.composeMaterial)
Expand All @@ -63,7 +62,6 @@ dependencies {
implementation(Dependencies.constraintLayoutCompose)
implementation(Dependencies.coreKtx)
implementation(Dependencies.customViewPoolingContainer) // This dependency is needed otherwise the compose preview does not work properly
implementation(Dependencies.kotlinReflect)
implementation(Dependencies.lifecycleRuntimeKtx)

testImplementation(Dependencies.jUnit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,4 @@ private fun PreviewOdsButton(@PreviewParameter(OdsButtonPreviewParameterProvider
OdsButton(text = "Text", onClick = {}, style = style)
}

private class OdsButtonPreviewParameterProvider : EnumPreviewParameterProvider(OdsButtonStyle::class)
private class OdsButtonPreviewParameterProvider : EnumPreviewParameterProvider(OdsButtonStyle::class.java)
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,4 @@ private fun PreviewOdsTextButton(@PreviewParameter(OdsTextButtonPreviewParameter
OdsTextButton(text = "Text", maxLines = 1, overflow = TextOverflow.Clip, onClick = {}, style = style)
}

private class OdsTextButtonPreviewParameterProvider : EnumPreviewParameterProvider(OdsTextButtonStyle::class)
private class OdsTextButtonPreviewParameterProvider : EnumPreviewParameterProvider(OdsTextButtonStyle::class.java)
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

package com.orange.ods.compose.component.chip

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.foundation.layout.FlowRow
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.selection.selectableGroup
Expand All @@ -23,7 +26,6 @@ import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.semantics.SemanticsPropertyReceiver
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.semantics.stateDescription
import com.google.accompanist.flowlayout.FlowRow
import com.orange.ods.R
import com.orange.ods.compose.component.OdsComposable
import com.orange.ods.compose.component.utilities.Preview
Expand All @@ -42,6 +44,7 @@ import com.orange.ods.compose.theme.OdsTheme
* @param modifier Modifier to be applied to the flow row.
* @param chips The list of [OdsChoiceChip]s displayed inside this OdsChoiceChipsFlowRow.
*/
@OptIn(ExperimentalLayoutApi::class)
@Composable
@OdsComposable
fun <T> OdsChoiceChipsFlowRow(
Expand All @@ -56,7 +59,7 @@ fun <T> OdsChoiceChipsFlowRow(
modifier = modifier
.fillMaxWidth()
.selectableGroup(),
mainAxisSpacing = dimensionResource(id = R.dimen.spacing_s),
horizontalArrangement = Arrangement.spacedBy(dimensionResource(id = R.dimen.spacing_s)),
content = {
chips.forEachIndexed { index, odsChoiceChip ->
odsChoiceChip.Content(selected = selectedChipValue == odsChoiceChip.value) { selected ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ import com.orange.ods.compose.theme.OdsTheme
import com.orange.ods.compose.utilities.extension.getElementOfType
import com.orange.ods.extension.isNotNullOrBlank
import com.orange.ods.extension.orElse
import kotlin.reflect.KClass

/**
* <a href="https://system.design.orange.com/0c1af118d/p/09a804-lists/b/669743" target="_blank">ODS Lists</a>.
Expand Down Expand Up @@ -505,14 +504,14 @@ private fun getTrailingPreview(parameter: OdsListItemPreviewParameter): @Composa
val checkedState = remember { mutableStateOf(false) }
val selectedRadio = remember { mutableStateOf(0) }
val trailing = when (parameter.previewTrailingType) {
OdsCheckboxTrailing::class -> OdsCheckboxTrailing(checked = checkedState, enabled = true)
OdsSwitchTrailing::class -> OdsSwitchTrailing(checked = checkedState)
OdsRadioButtonTrailing::class -> OdsRadioButtonTrailing(selectedRadio = selectedRadio, currentRadio = 0)
OdsIconTrailing::class -> OdsIconTrailing(
OdsCheckboxTrailing::class.java -> OdsCheckboxTrailing(checked = checkedState, enabled = true)
OdsSwitchTrailing::class.java -> OdsSwitchTrailing(checked = checkedState)
OdsRadioButtonTrailing::class.java -> OdsRadioButtonTrailing(selectedRadio = selectedRadio, currentRadio = 0)
OdsIconTrailing::class.java -> OdsIconTrailing(
painter = painterResource(id = android.R.drawable.ic_dialog_info),
contentDescription = null
)
OdsCaptionTrailing::class -> OdsCaptionTrailing(text = "caption")
OdsCaptionTrailing::class.java -> OdsCaptionTrailing(text = "caption")
else -> null
}

Expand Down Expand Up @@ -560,7 +559,7 @@ internal data class OdsListItemPreviewParameter(
val secondaryText: String?,
val singleLineSecondaryText: Boolean,
val iconType: OdsListItemIconType?,
val previewTrailingType: KClass<out OdsListItemTrailing>?
val previewTrailingType: Class<out OdsListItemTrailing>?
)

private class OdsListItemPreviewParameterProvider : BasicPreviewParameterProvider<OdsListItemPreviewParameter>(*previewParameterValues.toTypedArray())
Expand All @@ -572,10 +571,10 @@ private val previewParameterValues: List<OdsListItemPreviewParameter>

return listOf(
OdsListItemPreviewParameter(null, true, null, null),
OdsListItemPreviewParameter(longSecondaryText, true, null, OdsCheckboxTrailing::class),
OdsListItemPreviewParameter(shortSecondaryText, true, OdsListItemIconType.Icon, OdsIconTrailing::class),
OdsListItemPreviewParameter(longSecondaryText, false, OdsListItemIconType.SquareImage, OdsSwitchTrailing::class),
OdsListItemPreviewParameter(longSecondaryText, false, OdsListItemIconType.WideImage, OdsCaptionTrailing::class),
OdsListItemPreviewParameter(shortSecondaryText, true, OdsListItemIconType.CircularImage, OdsRadioButtonTrailing::class)
OdsListItemPreviewParameter(longSecondaryText, true, null, OdsCheckboxTrailing::class.java),
OdsListItemPreviewParameter(shortSecondaryText, true, OdsListItemIconType.Icon, OdsIconTrailing::class.java),
OdsListItemPreviewParameter(longSecondaryText, false, OdsListItemIconType.SquareImage, OdsSwitchTrailing::class.java),
OdsListItemPreviewParameter(longSecondaryText, false, OdsListItemIconType.WideImage, OdsCaptionTrailing::class.java),
OdsListItemPreviewParameter(shortSecondaryText, true, OdsListItemIconType.CircularImage, OdsRadioButtonTrailing::class.java)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import com.orange.ods.compose.component.utilities.BasicPreviewParameterProvider
import com.orange.ods.compose.component.utilities.DisabledInteractionSource
import com.orange.ods.compose.text.OdsTextCaption
import com.orange.ods.compose.theme.OdsTheme
import kotlin.reflect.KClass

/**
* A character counter to display below the text field
Expand Down Expand Up @@ -135,9 +134,9 @@ private fun OdsTextFieldErrorText(message: String) {
@Composable
internal fun getTrailingPreview(parameter: OdsTextFieldPreviewParameter, value: String): @Composable (() -> Unit)? {
val trailing = when (parameter.previewTrailingType) {
OdsTextTrailing::class -> OdsTextTrailing(text = "units")
OdsIconTrailing::class -> OdsIconTrailing(painter = painterResource(id = android.R.drawable.ic_input_add))
OdsExposedDropdownMenuTrailing::class -> OdsExposedDropdownMenuTrailing(expanded = false, enabled = true)
OdsTextTrailing::class.java -> OdsTextTrailing(text = "units")
OdsIconTrailing::class.java -> OdsIconTrailing(painter = painterResource(id = android.R.drawable.ic_input_add))
OdsExposedDropdownMenuTrailing::class.java -> OdsExposedDropdownMenuTrailing(expanded = false, enabled = true)
else -> null
}

Expand All @@ -148,15 +147,15 @@ internal data class OdsTextFieldPreviewParameter(
val hasCounter: Boolean,
val hasErrorMessage: Boolean,
val isVeryLongErrorMessage: Boolean,
val previewTrailingType: KClass<out OdsTextFieldTrailing>?
val previewTrailingType: Class<out OdsTextFieldTrailing>?
)

internal class OdsTextFieldPreviewParameterProvider : BasicPreviewParameterProvider<OdsTextFieldPreviewParameter>(*previewParameterValues.toTypedArray())

private val previewParameterValues: List<OdsTextFieldPreviewParameter>
get() {
val booleanValues = listOf(true, false)
val trailings = listOf(null, OdsTextTrailing::class, OdsIconTrailing::class, OdsExposedDropdownMenuTrailing::class)
val trailings = listOf(null, OdsTextTrailing::class.java, OdsIconTrailing::class.java, OdsExposedDropdownMenuTrailing::class.java)

return booleanValues.flatMap { hasCounter ->
booleanValues.flatMap { hasErrorMessage ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
import com.orange.ods.BuildConfig
import com.orange.ods.compose.theme.OdsTheme
import kotlin.reflect.KClass

/**
* Configures the Compose preview environment in Android Studio.
Expand Down Expand Up @@ -44,7 +43,7 @@ internal open class BasicPreviewParameterProvider<T>(vararg values: T) : Preview
*
* @param clazz The enum class.
*/
internal open class EnumPreviewParameterProvider(clazz: KClass<out Enum<*>>) : BasicPreviewParameterProvider<Enum<*>>(*clazz.java.enumConstants)
internal open class EnumPreviewParameterProvider(clazz: Class<out Enum<*>>) : BasicPreviewParameterProvider<Enum<*>>(*clazz.enumConstants)

/**
* Multipreview annotation classes used to display both light and dark mode previews.
Expand Down
1 change: 0 additions & 1 deletion theme-contract/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,5 @@ android {
dependencies {
implementation(platform(Dependencies.composeBom))
implementation(Dependencies.composeMaterial)
implementation(Dependencies.kotlinReflect)
implementation(Dependencies.material)
}
Loading

0 comments on commit a98f1b3

Please sign in to comment.