Skip to content

Commit

Permalink
[#878] Properties of OdsComponentIcon are now private
Browse files Browse the repository at this point in the history
  • Loading branch information
florentmaitre committed Mar 11, 2024
1 parent 9a7e968 commit 1de863a
Show file tree
Hide file tree
Showing 13 changed files with 115 additions and 128 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ object OdsTopAppBar {
/**
* A navigation icon in an OdsTopAppBar.
*/
class NavigationIcon : OdsComponentIcon<Nothing> {
class NavigationIcon private constructor(
val graphicsObject: Any,
val contentDescription: String,
val onClick: () -> Unit
) : OdsComponentIcon<Nothing>(Nothing::class.java, graphicsObject, contentDescription, onClick = onClick) {

/**
* Creates an instance of [OdsTopAppBar.NavigationIcon].
Expand All @@ -67,12 +71,7 @@ object OdsTopAppBar {
* @param contentDescription The content description associated to this [OdsTopAppBar.NavigationIcon].
* @param onClick Will be called when the user clicks on the action icon button.
*/
constructor(painter: Painter, contentDescription: String, onClick: () -> Unit) : super(
Nothing::class.java,
painter,
contentDescription,
onClick = onClick
)
constructor(painter: Painter, contentDescription: String, onClick: () -> Unit) : this(painter as Any, contentDescription, onClick)

/**
* Creates an instance of [OdsTopAppBar.NavigationIcon].
Expand All @@ -81,12 +80,7 @@ object OdsTopAppBar {
* @param contentDescription The content description associated to this [OdsTopAppBar.NavigationIcon].
* @param onClick Will be called when the user clicks on the action icon button.
*/
constructor(imageVector: ImageVector, contentDescription: String, onClick: () -> Unit) : super(
Nothing::class.java,
imageVector,
contentDescription,
onClick = onClick
)
constructor(imageVector: ImageVector, contentDescription: String, onClick: () -> Unit) : this(imageVector as Any, contentDescription, onClick)

/**
* Creates an instance of [OdsTopAppBar.NavigationIcon].
Expand All @@ -95,12 +89,7 @@ object OdsTopAppBar {
* @param contentDescription The content description associated to this [OdsTopAppBar.NavigationIcon].
* @param onClick Will be called when the user clicks on the action icon button.
*/
constructor(bitmap: ImageBitmap, contentDescription: String, onClick: () -> Unit) : super(
Nothing::class.java,
bitmap,
contentDescription,
onClick = onClick
)
constructor(bitmap: ImageBitmap, contentDescription: String, onClick: () -> Unit) : this(bitmap as Any, contentDescription, onClick)

override val tint: Color?
@Composable
Expand All @@ -110,7 +99,12 @@ object OdsTopAppBar {
/**
* An action button displayed in an [OdsTopAppBar].
*/
class ActionButton : OdsComponentIcon<Nothing> {
class ActionButton private constructor(
val graphicsObject: Any,
val contentDescription: String,
enabled: Boolean = true,
val onClick: () -> Unit
) : OdsComponentIcon<Nothing>(Nothing::class.java, graphicsObject, contentDescription, enabled, onClick) {

/**
* Creates an instance of [OdsTopAppBar.ActionButton].
Expand All @@ -126,7 +120,7 @@ object OdsTopAppBar {
contentDescription: String,
enabled: Boolean = true,
onClick: () -> Unit
) : super(Nothing::class.java, painter, contentDescription, enabled, onClick)
) : this(painter as Any, contentDescription, enabled, onClick)

/**
* Creates an instance of [OdsTopAppBar.ActionButton].
Expand All @@ -142,7 +136,7 @@ object OdsTopAppBar {
contentDescription: String,
enabled: Boolean = true,
onClick: () -> Unit
) : super(Nothing::class.java, imageVector, contentDescription, enabled, onClick)
) : this(imageVector as Any, contentDescription, enabled, onClick)

/**
* Creates an instance of [OdsTopAppBar.ActionButton].
Expand All @@ -158,7 +152,10 @@ object OdsTopAppBar {
contentDescription: String,
enabled: Boolean = true,
onClick: () -> Unit
) : super(Nothing::class.java, bitmap, contentDescription, enabled, onClick)
) : this(bitmap as Any, contentDescription, enabled, onClick)

public override var enabled: Boolean = enabled
protected set

override val tint: Color
@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,31 +181,34 @@ object OdsBottomNavigation {
/**
* An icon in an [OdsBottomNavigation.Item].
*/
class Icon : OdsComponentIcon<Nothing> {
class Icon private constructor(
val graphicsObject: Any,
val contentDescription: String
) : OdsComponentIcon<Nothing>(Nothing::class.java, graphicsObject, contentDescription) {

/**
* Creates an instance of [OdsBottomNavigation.Item.Icon].
*
* @param painter Painter of the icon.
* @param contentDescription The content description associated to this [OdsBottomNavigation.Item.Icon].
*/
constructor(painter: Painter, contentDescription: String) : super(Nothing::class.java, painter, contentDescription)
constructor(painter: Painter, contentDescription: String) : this(painter as Any, contentDescription)

/**
* Creates an instance of [OdsBottomNavigation.Item.Icon].
*
* @param imageVector Image vector of the icon.
* @param contentDescription The content description associated to this [OdsBottomNavigation.Item.Icon].
*/
constructor(imageVector: ImageVector, contentDescription: String) : super(Nothing::class.java, imageVector, contentDescription)
constructor(imageVector: ImageVector, contentDescription: String) : this(imageVector as Any, contentDescription)

/**
* Creates an instance of [OdsBottomNavigation.Item.Icon].
*
* @param bitmap Image bitmap of the icon.
* @param contentDescription The content description associated to this [OdsBottomNavigation.Item.Icon].
*/
constructor(bitmap: ImageBitmap, contentDescription: String) : super(Nothing::class.java, bitmap, contentDescription)
constructor(bitmap: ImageBitmap, contentDescription: String) : this(bitmap as Any, contentDescription)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,30 @@ object OdsButton {
* A button icon in an [OdsButton].
* It is non-clickable and no content description is needed cause a button label is always present.
*/
class Icon : OdsComponentIcon<Nothing> {
class Icon private constructor(
val graphicsObject: Any
) : OdsComponentIcon<Nothing>(Nothing::class.java, graphicsObject, "") {

/**
* Creates an instance of [OdsButton.Icon].
*
* @param painter Painter of the icon.
*/
constructor(painter: Painter) : super(Nothing::class.java, painter, "")
constructor(painter: Painter) : this(painter as Any)

/**
* Creates an instance of [OdsButton.Icon].
*
* @param imageVector Image vector of the icon.
*/
constructor(imageVector: ImageVector) : super(Nothing::class.java, imageVector, "")
constructor(imageVector: ImageVector) : this(imageVector as Any)

/**
* Creates an instance of [OdsButton.Icon].
*
* @param bitmap Image bitmap of the icon.
*/
constructor(bitmap: ImageBitmap) : super(Nothing::class.java, bitmap, "")
constructor(bitmap: ImageBitmap) : this(bitmap as Any)

@Composable
override fun Content(modifier: Modifier) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,31 +116,34 @@ object OdsFloatingActionButton {
/**
* A button icon in an [OdsFloatingActionButton].
*/
class Icon : OdsComponentIcon<Nothing> {
class Icon private constructor(
val graphicsObject: Any,
val contentDescription: String
) : OdsComponentIcon<Nothing>(Nothing::class.java, graphicsObject, contentDescription) {

/**
* Creates an instance of [OdsFloatingActionButton.Icon].
*
* @param painter Painter of the icon.
* @param contentDescription The content description associated to this [OdsFloatingActionButton.Icon].
*/
constructor(painter: Painter, contentDescription: String) : super(Nothing::class.java, painter, contentDescription)
constructor(painter: Painter, contentDescription: String) : this(painter as Any, contentDescription)

/**
* Creates an instance of [OdsFloatingActionButton.Icon].
*
* @param imageVector Image vector of the icon.
* @param contentDescription The content description associated to this [OdsFloatingActionButton.Icon].
*/
constructor(imageVector: ImageVector, contentDescription: String) : super(Nothing::class.java, imageVector, contentDescription)
constructor(imageVector: ImageVector, contentDescription: String) : this(imageVector as Any, contentDescription)

/**
* Creates an instance of [OdsFloatingActionButton.Icon].
*
* @param bitmap Image bitmap of the icon.
* @param contentDescription The content description associated to this [OdsFloatingActionButton.Icon].
*/
constructor(bitmap: ImageBitmap, contentDescription: String) : super(Nothing::class.java, bitmap, contentDescription)
constructor(bitmap: ImageBitmap, contentDescription: String) : this(bitmap as Any, contentDescription)

@Composable
override fun Content(modifier: Modifier) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ object OdsIconButton {
/**
* An icon in an [OdsIconButton].
*/
class Icon : OdsComponentIcon<Icon.ExtraParameters> {
class Icon private constructor(
val graphicsObject: Any,
val contentDescription: String
) : OdsComponentIcon<Icon.ExtraParameters>(ExtraParameters::class.java, graphicsObject, contentDescription) {

data class ExtraParameters internal constructor(
internal val enabled: Boolean
Expand All @@ -91,23 +94,23 @@ object OdsIconButton {
* @param painter Painter of the icon.
* @param contentDescription The content description associated to this [OdsIconButton.Icon].
*/
constructor(painter: Painter, contentDescription: String) : super(ExtraParameters::class.java, painter, contentDescription)
constructor(painter: Painter, contentDescription: String) : this(painter as Any, contentDescription)

/**
* Creates an instance of [OdsIconButton.Icon].
*
* @param imageVector Image vector of the icon.
* @param contentDescription The content description associated to this [OdsIconButton.Icon].
*/
constructor(imageVector: ImageVector, contentDescription: String) : super(ExtraParameters::class.java, imageVector, contentDescription)
constructor(imageVector: ImageVector, contentDescription: String) : this(imageVector as Any, contentDescription)

/**
* Creates an instance of [OdsIconButton.Icon].
*
* @param bitmap Image bitmap of the icon.
* @param contentDescription The content description associated to this [OdsIconButton.Icon].
*/
constructor(bitmap: ImageBitmap, contentDescription: String) : super(ExtraParameters::class.java, bitmap, contentDescription)
constructor(bitmap: ImageBitmap, contentDescription: String) : this(bitmap as Any, contentDescription)

override val tint: Color
@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ object OdsIconToggleButtonsRow {
* An icon button in an [OdsIconToggleButtonsRow].
*/
class IconButton private constructor(
graphicsObject: Any,
contentDescription: String,
onClick: () -> Unit,
val graphicsObject: Any,
val contentDescription: String,
val onClick: () -> Unit,
enabled: Boolean = true
) : OdsComponentIcon<IconButton.ExtraParameters>(ExtraParameters::class.java, graphicsObject, contentDescription, enabled, onClick) {
) : OdsComponentIcon<IconButton.ExtraParameters>(ExtraParameters::class.java, graphicsObject, contentDescription, enabled) {

data class ExtraParameters internal constructor(
internal val index: Int,
Expand Down Expand Up @@ -154,6 +154,9 @@ object OdsIconToggleButtonsRow {
enabled: Boolean = true
) : this(bitmap as Any, contentDescription, onClick, enabled)

public override var enabled: Boolean = enabled
protected set

override val tint: Color
@Composable
get() {
Expand All @@ -171,7 +174,7 @@ object OdsIconToggleButtonsRow {
.background(color = buttonToggleBackgroundColor().copy(alpha = backgroundAlpha))
.padding(12.dp)
.run {
if (enabled && onClick != null) {
if (enabled) {
clickable(interactionSource = remember { DisabledInteractionSource() }, indication = null, onClick = onClick)
} else {
this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,31 +43,34 @@ object OdsChip {
/**
* A leading icon in an [OdsChip].
*/
class LeadingIcon : OdsComponentIcon<Nothing>, Leading {
class LeadingIcon private constructor(
val graphicsObject: Any,
val contentDescription: String
) : OdsComponentIcon<Nothing>(Nothing::class.java, graphicsObject, contentDescription), Leading {

/**
* Creates an instance of [OdsChip.LeadingIcon].
*
* @param painter The painter to draw.
* @param contentDescription The content description associated to this [OdsChip.LeadingIcon].
*/
constructor(painter: Painter, contentDescription: String) : super(Nothing::class.java, painter, contentDescription)
constructor(painter: Painter, contentDescription: String) : this(painter as Any, contentDescription)

/**
* Creates an instance of [OdsChip.LeadingIcon].
*
* @param imageVector The image vector to draw.
* @param contentDescription The content description associated to this [OdsChip.LeadingIcon].
*/
constructor(imageVector: ImageVector, contentDescription: String) : super(Nothing::class.java, imageVector, contentDescription)
constructor(imageVector: ImageVector, contentDescription: String) : this(imageVector as Any, contentDescription)

/**
* Creates an instance of [OdsChip.LeadingIcon].
*
* @param bitmap The image bitmap to draw.
* @param contentDescription The content description associated to this [OdsChip.LeadingIcon].
*/
constructor(bitmap: ImageBitmap, contentDescription: String) : super(Nothing::class.java, bitmap, contentDescription)
constructor(bitmap: ImageBitmap, contentDescription: String) : this(bitmap as Any, contentDescription)

@Composable
override fun Content(modifier: Modifier) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,14 @@ import com.orange.ods.compose.extension.orElse
/**
* An icon in a component.
*/
abstract class OdsComponentIcon<T> internal constructor(
abstract class OdsComponentIcon<T> protected constructor(
extraParametersClass: Class<T>,
val graphicsObject: Any,
val contentDescription: String,
enabled: Boolean = true,
val onClick: (() -> Unit)? = null,
private val graphicsObject: Any,
private val contentDescription: String,
protected open var enabled: Boolean = true,
private val onClick: (() -> Unit)? = null,
) : OdsComponentContent<T>(extraParametersClass) where T : OdsComponentContent.ExtraParameters {

var enabled = enabled
protected set

val painter: Painter? = graphicsObject as? Painter
val imageVector: ImageVector? = graphicsObject as? ImageVector
val bitmap: ImageBitmap? = graphicsObject as? ImageBitmap
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,31 +213,34 @@ object OdsSlider {
/**
* An icon in an [OdsSlider] or an [OdsSliderLockups].
*/
class Icon : OdsComponentIcon<Nothing> {
class Icon private constructor(
val graphicsObject: Any,
val contentDescription: String,
) : OdsComponentIcon<Nothing>(Nothing::class.java, graphicsObject, contentDescription) {

/**
* Creates an instance of [OdsSlider.Icon].
*
* @param painter Painter of the icon.
* @param contentDescription The content description associated to this [OdsSlider.Icon].
*/
constructor(painter: Painter, contentDescription: String) : super(Nothing::class.java, painter, contentDescription)
constructor(painter: Painter, contentDescription: String) : this(painter as Any, contentDescription)

/**
* Creates an instance of [OdsSlider.Icon].
*
* @param imageVector Image vector of the icon.
* @param contentDescription The content description associated to this [OdsSlider.Icon].
*/
constructor(imageVector: ImageVector, contentDescription: String) : super(Nothing::class.java, imageVector, contentDescription)
constructor(imageVector: ImageVector, contentDescription: String) : this(imageVector as Any, contentDescription)

/**
* Creates an instance of [OdsSlider.Icon].
*
* @param bitmap Image bitmap of the icon.
* @param contentDescription The content description associated to this [OdsSlider.Icon].
*/
constructor(bitmap: ImageBitmap, contentDescription: String) : super(Nothing::class.java, bitmap, contentDescription)
constructor(bitmap: ImageBitmap, contentDescription: String) : this(bitmap as Any, contentDescription)

override val tint: Color?
@Composable
Expand Down
Loading

0 comments on commit 1de863a

Please sign in to comment.