Skip to content

Commit

Permalink
PR changes
Browse files Browse the repository at this point in the history
  • Loading branch information
fjquileze committed Nov 15, 2023
1 parent 389e625 commit 32d6a21
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import android.widget.Button
import android.widget.Toast
import androidx.fragment.app.Fragment
import com.telefonica.mistica.callout.CalloutView
import com.telefonica.mistica.callout.CalloutViewImageConfig
import com.telefonica.mistica.catalog.R
import com.telefonica.mistica.input.CheckBoxInput
import com.telefonica.mistica.input.DropDownInput
Expand Down Expand Up @@ -63,18 +64,18 @@ class CalloutsCatalogFragment : Fragment() {
}

when (CalloutImageConfig.valueOf(view.findViewById<DropDownInput>(R.id.image_config_dropdown).dropDown.text.toString()).imageConfig) {
CalloutView.IMAGE_CONFIG_NONE -> {
CalloutViewImageConfig.IMAGE_CONFIG_NONE -> {
setIcon(null)
setImage(null)
setCircularImage(null)
}
CalloutView.IMAGE_CONFIG_ICON -> {
CalloutViewImageConfig.IMAGE_CONFIG_ICON -> {
setIcon(R.drawable.ic_callout)
}
CalloutView.IMAGE_CONFIG_SQUARE -> {
CalloutViewImageConfig.IMAGE_CONFIG_SQUARE -> {
setImage(R.drawable.media_card_sample_image)
}
CalloutView.IMAGE_CONFIG_CIRCULAR -> {
CalloutViewImageConfig.IMAGE_CONFIG_CIRCULAR -> {
setCircularImage(R.drawable.media_card_sample_image)
}
}
Expand Down Expand Up @@ -118,10 +119,10 @@ class CalloutsCatalogFragment : Fragment() {
LINK(CalloutView.BUTTONS_CONFIG_LINK),
}

private enum class CalloutImageConfig(@CalloutView.ImageConfig val imageConfig: Int) {
NONE(CalloutView.IMAGE_CONFIG_NONE),
ICON(CalloutView.IMAGE_CONFIG_ICON),
IMAGE(CalloutView.IMAGE_CONFIG_SQUARE),
CIRCULAR(CalloutView.IMAGE_CONFIG_CIRCULAR)
private enum class CalloutImageConfig(val imageConfig: CalloutViewImageConfig) {
NONE(CalloutViewImageConfig.IMAGE_CONFIG_NONE),
ICON(CalloutViewImageConfig.IMAGE_CONFIG_ICON),
IMAGE(CalloutViewImageConfig.IMAGE_CONFIG_SQUARE),
CIRCULAR(CalloutViewImageConfig.IMAGE_CONFIG_CIRCULAR)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.telefonica.mistica.catalog.ui.compose.components

import androidx.annotation.AttrRes
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
Expand All @@ -22,15 +21,12 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.telefonica.mistica.callout.CalloutView
import com.telefonica.mistica.callout.CalloutViewImageConfig
import com.telefonica.mistica.catalog.R
import com.telefonica.mistica.catalog.ui.compose.common.DropDown
import com.telefonica.mistica.compose.button.Button
import com.telefonica.mistica.compose.callout.Callout
import com.telefonica.mistica.compose.callout.CalloutButtonConfig
import com.telefonica.mistica.compose.card.datacard.IconType
import com.telefonica.mistica.compose.card.datacard.noIcon
import com.telefonica.mistica.compose.card.datacard.resourceIconPainter
import com.telefonica.mistica.compose.input.DropDownInput
import com.telefonica.mistica.compose.theme.MisticaTheme

Expand Down Expand Up @@ -155,12 +151,12 @@ fun Callouts() {
description = description.takeIf { it.isNotBlank() },
buttonConfig = buttonConfig,
imageConfig = when (iconType) {
ImageTypes.NONE -> CalloutView.IMAGE_CONFIG_NONE
ImageTypes.ICON -> CalloutView.IMAGE_CONFIG_ICON
ImageTypes.SQUARE_IMAGE -> CalloutView.IMAGE_CONFIG_SQUARE
ImageTypes.CIRCULAR_IMAGE -> CalloutView.IMAGE_CONFIG_CIRCULAR
ImageTypes.NONE -> CalloutViewImageConfig.IMAGE_CONFIG_NONE
ImageTypes.ICON -> CalloutViewImageConfig.IMAGE_CONFIG_ICON
ImageTypes.SQUARE_IMAGE -> CalloutViewImageConfig.IMAGE_CONFIG_SQUARE
ImageTypes.CIRCULAR_IMAGE -> CalloutViewImageConfig.IMAGE_CONFIG_CIRCULAR
},
imageRes = when (iconType) {
iconRes = when (iconType) {
ImageTypes.NONE -> null
ImageTypes.ICON -> R.drawable.ic_callout
ImageTypes.CIRCULAR_IMAGE -> R.drawable.media_card_sample_image
Expand Down Expand Up @@ -188,9 +184,9 @@ fun Callouts() {
}
}

private enum class ImageTypes(@AttrRes val iconType: Int) {
NONE(CalloutView.IMAGE_CONFIG_NONE),
ICON(CalloutView.IMAGE_CONFIG_ICON),
SQUARE_IMAGE(CalloutView.IMAGE_CONFIG_SQUARE),
CIRCULAR_IMAGE(CalloutView.IMAGE_CONFIG_CIRCULAR),
private enum class ImageTypes(val iconType: CalloutViewImageConfig) {
NONE(CalloutViewImageConfig.IMAGE_CONFIG_NONE),
ICON(CalloutViewImageConfig.IMAGE_CONFIG_ICON),
SQUARE_IMAGE(CalloutViewImageConfig.IMAGE_CONFIG_SQUARE),
CIRCULAR_IMAGE(CalloutViewImageConfig.IMAGE_CONFIG_CIRCULAR),
}
37 changes: 15 additions & 22 deletions library/src/main/java/com/telefonica/mistica/callout/CalloutView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,6 @@ class CalloutView @JvmOverloads constructor(
)
annotation class ButtonsConfig

@Retention(AnnotationRetention.SOURCE)
@IntDef(
IMAGE_CONFIG_NONE,
IMAGE_CONFIG_ICON,
IMAGE_CONFIG_SQUARE,
IMAGE_CONFIG_CIRCULAR
)
annotation class ImageConfig

private var icon: ImageView
private var image: ImageView
private var circularImage: ShapeableImageView
Expand Down Expand Up @@ -229,7 +220,7 @@ class CalloutView @JvmOverloads constructor(

fun setIcon(@DrawableRes iconRes: Int?) {
if (iconRes != null) {
setImageConfig(IMAGE_CONFIG_ICON)
setImageConfig(CalloutViewImageConfig.IMAGE_CONFIG_ICON)
icon.setImageResource(iconRes)
} else {
icon.visibility = GONE
Expand All @@ -238,7 +229,7 @@ class CalloutView @JvmOverloads constructor(

fun setImage(@DrawableRes imageRes: Int?) {
if (imageRes != null) {
setImageConfig(IMAGE_CONFIG_SQUARE)
setImageConfig(CalloutViewImageConfig.IMAGE_CONFIG_SQUARE)
image.setImageResource(imageRes)
} else {
image.visibility = GONE
Expand All @@ -247,7 +238,7 @@ class CalloutView @JvmOverloads constructor(

fun setCircularImage(@DrawableRes imageRes: Int?) {
if (imageRes != null) {
setImageConfig(IMAGE_CONFIG_CIRCULAR)
setImageConfig(CalloutViewImageConfig.IMAGE_CONFIG_CIRCULAR)
circularImage.setImageResource(imageRes)
} else {
circularImage.visibility = GONE
Expand Down Expand Up @@ -346,24 +337,24 @@ class CalloutView @JvmOverloads constructor(
}
}

private fun setImageConfig(@ImageConfig imageConfig: Int) {
private fun setImageConfig(imageConfig: CalloutViewImageConfig) {
when (imageConfig) {
IMAGE_CONFIG_NONE -> {
CalloutViewImageConfig.IMAGE_CONFIG_NONE -> {
icon.visibility = GONE
image.visibility = GONE
circularImage.visibility = GONE
}
IMAGE_CONFIG_ICON -> {
CalloutViewImageConfig.IMAGE_CONFIG_ICON -> {
icon.visibility = VISIBLE
image.visibility = GONE
circularImage.visibility = GONE
}
IMAGE_CONFIG_SQUARE -> {
CalloutViewImageConfig.IMAGE_CONFIG_SQUARE -> {
icon.visibility = GONE
image.visibility = VISIBLE
circularImage.visibility = GONE
}
IMAGE_CONFIG_CIRCULAR -> {
CalloutViewImageConfig.IMAGE_CONFIG_CIRCULAR -> {
icon.visibility = GONE
image.visibility = GONE
circularImage.visibility = VISIBLE
Expand All @@ -389,13 +380,15 @@ class CalloutView @JvmOverloads constructor(
const val BUTTONS_CONFIG_SECONDARY_LINK = 4
const val BUTTONS_CONFIG_LINK = 5

const val IMAGE_CONFIG_NONE = -1
const val IMAGE_CONFIG_ICON = 0
const val IMAGE_CONFIG_SQUARE = 1
const val IMAGE_CONFIG_CIRCULAR = 2

val NO_OP_CALLOUT_LISTENER = {}
val ANIMATION_INTERPOLATOR = PathInterpolator(0.77f, 0f, 0.175f, 1f)
const val ANIMATION_DURATION = 400L
}
}

enum class CalloutViewImageConfig {
IMAGE_CONFIG_NONE,
IMAGE_CONFIG_ICON,
IMAGE_CONFIG_SQUARE,
IMAGE_CONFIG_CIRCULAR
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,20 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
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.foundation.shape.RoundedCornerShape
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.telefonica.mistica.R
import com.telefonica.mistica.callout.CalloutView
import com.telefonica.mistica.callout.CalloutViewImageConfig
import com.telefonica.mistica.compose.button.Button
import com.telefonica.mistica.compose.button.ButtonStyle
import com.telefonica.mistica.compose.card.datacard.IconPainter
import com.telefonica.mistica.compose.card.datacard.IconType
import com.telefonica.mistica.compose.card.datacard.noIcon
import com.telefonica.mistica.compose.card.datacard.resourceIconPainter
Expand All @@ -38,8 +34,7 @@ fun Callout(
description: String?,
buttonConfig: CalloutButtonConfig,
@DrawableRes iconRes: Int? = null,
@CalloutView.ImageConfig imageConfig: Int = CalloutView.IMAGE_CONFIG_NONE,
@DrawableRes imageRes: Int? = null,
imageConfig: CalloutViewImageConfig = CalloutViewImageConfig.IMAGE_CONFIG_NONE,
dismissable: Boolean,
onDismiss: (() -> Unit)? = null,
inverse: Boolean,
Expand Down Expand Up @@ -67,33 +62,23 @@ fun Callout(
) {

if (iconRes != null) {
Image(
modifier = Modifier
.padding(end = 16.dp)
.width(24.dp)
.height(24.dp),
painter = painterResource(id = iconRes),
contentDescription = null,
colorFilter = ColorFilter.tint(MisticaTheme.colors.neutralHigh)
)
} else if (imageRes != null) {
val iconPainter = when (imageConfig) {
CalloutView.IMAGE_CONFIG_ICON -> {
CalloutViewImageConfig.IMAGE_CONFIG_ICON -> {
resourceIconPainter(
iconRes = imageRes,
iconRes = iconRes,
iconType = IconType.ICON,
modifier = Modifier.padding(end = 16.dp)
)
}
CalloutView.IMAGE_CONFIG_SQUARE -> {
CalloutViewImageConfig.IMAGE_CONFIG_SQUARE -> {
resourceIconPainter(
iconRes = imageRes, iconType = IconType.SQUARE_IMAGE,
iconRes = iconRes, iconType = IconType.SQUARE_IMAGE,
modifier = Modifier.padding(end = 16.dp)
)
}
CalloutView.IMAGE_CONFIG_CIRCULAR -> {
CalloutViewImageConfig.IMAGE_CONFIG_CIRCULAR -> {
resourceIconPainter(
iconRes = imageRes,
iconRes = iconRes,
iconType = IconType.CIRCULAR_ASSET,
modifier = Modifier.padding(end = 16.dp)
)
Expand Down
1 change: 0 additions & 1 deletion library/src/main/res/layout/callout_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
android:visibility="gone"
app:shapeAppearance="@style/CircleImageView"
tools:src="@tools:sample/avatars"
tools:visibility="gone"
/>

</FrameLayout>
Expand Down

0 comments on commit 32d6a21

Please sign in to comment.