Skip to content

Commit

Permalink
PR changes
Browse files Browse the repository at this point in the history
  • Loading branch information
fjquileze committed Nov 24, 2023
1 parent 9dc79ea commit ad03053
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ class CalloutsCatalogFragment : Fragment() {
DropDownInput.Adapter(
view.context,
R.layout.dropdown_menu_popup_item,
CalloutImageConfig.values().map { it.name },
CalloutViewImageConfig.values().map { it.name },
)
)
setText(CalloutImageConfig.ICON.name)
setText(CalloutViewImageConfig.ICON.name)
}
view.findViewById<Button>(R.id.update_button).setOnClickListener {
updateCalloutView(view)
Expand All @@ -63,23 +63,24 @@ class CalloutsCatalogFragment : Fragment() {
visibility = VISIBLE
}

val imageConfig = CalloutImageConfig.valueOf(
val imageConfig = CalloutViewImageConfig.valueOf(
view.findViewById<DropDownInput>(R.id.image_config_dropdown).dropDown.text.toString()
).imageConfig
)

when (imageConfig) {
CalloutViewImageConfig.IMAGE_CONFIG_NONE -> {
CalloutViewImageConfig.NONE -> {
setAssetType(imageConfig)
}
CalloutViewImageConfig.IMAGE_CONFIG_ICON -> {
CalloutViewImageConfig.ICON -> {
setAsset(R.drawable.ic_callout)
setAssetType(imageConfig)
}
CalloutViewImageConfig.IMAGE_CONFIG_SQUARE,
CalloutViewImageConfig.IMAGE_CONFIG_CIRCULAR -> {
CalloutViewImageConfig.SQUARE_IMAGE,
CalloutViewImageConfig.CIRCULAR_IMAGE -> {
setAsset(R.drawable.media_card_sample_image)
setAssetType(imageConfig)
}
}
setAssetType(imageConfig)

setDismissable(view.findViewById<CheckBoxInput>(R.id.dismiss_input).isChecked())
val inverse = view.findViewById<CheckBoxInput>(R.id.inverse_input).isChecked()
Expand Down Expand Up @@ -119,11 +120,4 @@ class CalloutsCatalogFragment : Fragment() {
SECONDARY_AND_LINK(CalloutView.BUTTONS_CONFIG_SECONDARY_LINK),
LINK(CalloutView.BUTTONS_CONFIG_LINK),
}

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
Expand Up @@ -49,14 +49,14 @@ fun Callouts() {
Text("Inverse variant")
}

var iconType: ImageTypes by remember { mutableStateOf(ImageTypes.ICON) }
var iconType: CalloutViewImageConfig by remember { mutableStateOf(CalloutViewImageConfig.ICON) }
DropDownInput(
modifier = Modifier
.fillMaxWidth()
.padding(40.dp, 8.dp),
items = ImageTypes.values().map { it.name },
currentItemIndex = ImageTypes.values().indexOf(iconType),
onItemSelected = { index -> iconType = ImageTypes.values()[index] },
items = CalloutViewImageConfig.values().map { it.name },
currentItemIndex = CalloutViewImageConfig.values().indexOf(iconType),
onItemSelected = { index -> iconType = CalloutViewImageConfig.values()[index] },
hint = "Icon type",
)

Expand Down Expand Up @@ -151,16 +151,16 @@ fun Callouts() {
description = description.takeIf { it.isNotBlank() },
buttonConfig = buttonConfig,
imageConfig = when (iconType) {
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
CalloutViewImageConfig.NONE -> CalloutViewImageConfig.NONE
CalloutViewImageConfig.ICON -> CalloutViewImageConfig.ICON
CalloutViewImageConfig.SQUARE_IMAGE -> CalloutViewImageConfig.SQUARE_IMAGE
CalloutViewImageConfig.CIRCULAR_IMAGE -> CalloutViewImageConfig.CIRCULAR_IMAGE
},
iconRes = when (iconType) {
ImageTypes.NONE -> null
ImageTypes.ICON -> R.drawable.ic_callout
ImageTypes.CIRCULAR_IMAGE -> R.drawable.media_card_sample_image
ImageTypes.SQUARE_IMAGE -> R.drawable.card_image_sample
CalloutViewImageConfig.NONE -> null
CalloutViewImageConfig.ICON -> R.drawable.ic_callout
CalloutViewImageConfig.CIRCULAR_IMAGE -> R.drawable.media_card_sample_image
CalloutViewImageConfig.SQUARE_IMAGE -> R.drawable.card_image_sample
},
dismissable = dismissable,
inverse = inverse,
Expand All @@ -183,10 +183,3 @@ fun Callouts() {
}
}
}

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),
}
85 changes: 33 additions & 52 deletions library/src/main/java/com/telefonica/mistica/callout/CalloutView.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.telefonica.mistica.callout

import android.content.Context
import android.graphics.drawable.Drawable
import android.util.AttributeSet
import android.util.TypedValue
import android.view.LayoutInflater
Expand Down Expand Up @@ -37,12 +36,12 @@ import com.telefonica.mistica.util.getThemeColor
),
BindingMethod(
type = CalloutView::class,
attribute = "calloutIcon",
attribute = "calloutAsset",
method = "setAsset",
),
BindingMethod(
type = CalloutView::class,
attribute = "calloutImage",
attribute = "calloutAssetType",
method = "setAssetType",
),
BindingMethod(
Expand Down Expand Up @@ -120,7 +119,7 @@ class CalloutView @JvmOverloads constructor(
private var linkButton: Button
private var closeButton: ImageView
private var asset: Int? = null
private var assetType: CalloutViewImageConfig
private var assetType: CalloutViewImageConfig = CalloutViewImageConfig.ICON

private var onDismissed: () -> Unit = NO_OP_CALLOUT_LISTENER

Expand All @@ -130,7 +129,7 @@ class CalloutView @JvmOverloads constructor(
icon = findViewById(R.id.callout_icon)
icon.setColorFilter(context.getThemeColor(R.attr.colorNeutralHigh))
image = findViewById(R.id.callout_image)
circularImage = findViewById(R.id.data_card_circular_icon)
circularImage = findViewById(R.id.callout_circular_image)
title = findViewById(R.id.callout_title)
description = findViewById(R.id.callout_description)
buttonsContainer = findViewById(R.id.callout_buttons_container)
Expand All @@ -143,7 +142,7 @@ class CalloutView @JvmOverloads constructor(
var buttonsConfig: Int = BUTTONS_CONFIG_PRIMARY
var dismissable = false
var inverse = false
assetType = CalloutViewImageConfig.IMAGE_CONFIG_NONE
assetType = CalloutViewImageConfig.NONE

if (attrs != null) {
val styledAttrs = context.theme.obtainStyledAttributes(attrs, R.styleable.CalloutView, defStyleAttr, 0)
Expand All @@ -156,7 +155,7 @@ class CalloutView @JvmOverloads constructor(
styledAttrs.getString(R.styleable.CalloutView_calloutSecondaryButtonText)?.let { setSecondaryButtonText(it) }
styledAttrs.getString(R.styleable.CalloutView_calloutLinkButtonText)?.let { setLinkButtonText(it) }
assetType = CalloutViewImageConfig.getConfigByValue(
styledAttrs.getInteger(R.styleable.CalloutView_calloutAssetType, CalloutViewImageConfig.IMAGE_CONFIG_NONE.value)
styledAttrs.getInteger(R.styleable.CalloutView_calloutAssetType, CalloutViewImageConfig.NONE.value)
)
styledAttrs.getResourceId(R.styleable.CalloutView_calloutAsset, TypedValue.TYPE_NULL).takeIf { it != TypedValue.TYPE_NULL }
?.let { setAsset(it) }
Expand Down Expand Up @@ -220,37 +219,34 @@ class CalloutView @JvmOverloads constructor(
asset = assetRes
if (assetRes != null) {
when (assetType) {
CalloutViewImageConfig.IMAGE_CONFIG_NONE -> noAsset()
CalloutViewImageConfig.IMAGE_CONFIG_ICON -> setIcon(assetRes)
CalloutViewImageConfig.IMAGE_CONFIG_SQUARE -> setImage(assetRes)
CalloutViewImageConfig.IMAGE_CONFIG_CIRCULAR -> setCircularImage(assetRes)
}
} else {
noAsset()
}
}

fun setAssetType(type: CalloutViewImageConfig) {
asset?.also {
when (type) {
CalloutViewImageConfig.IMAGE_CONFIG_NONE -> noAsset()
CalloutViewImageConfig.IMAGE_CONFIG_ICON -> {
setIcon(it)
CalloutViewImageConfig.NONE -> noAsset()
CalloutViewImageConfig.ICON -> {
icon.setImageResource(assetRes)
icon.visibility = VISIBLE
image.visibility = GONE
circularImage.visibility = GONE
}
CalloutViewImageConfig.IMAGE_CONFIG_SQUARE -> {
setImage(it)
CalloutViewImageConfig.SQUARE_IMAGE -> {
image.setImageResource(assetRes)
image.visibility = VISIBLE
icon.visibility = GONE
circularImage.visibility = GONE
}
CalloutViewImageConfig.IMAGE_CONFIG_CIRCULAR -> {
setCircularImage(it)
CalloutViewImageConfig.CIRCULAR_IMAGE -> {
circularImage.setImageResource(assetRes)
circularImage.visibility = VISIBLE
icon.visibility = GONE
image.visibility = GONE
}
}
} ?: noAsset()
} else {
noAsset()
}
}

fun setAssetType(value: CalloutViewImageConfig) {
assetType = value
setAsset(asset)
}

private fun noAsset() {
Expand All @@ -259,21 +255,6 @@ class CalloutView @JvmOverloads constructor(
circularImage.visibility = GONE
}

private fun setIcon(@DrawableRes iconRes: Int) {
setImageConfig(CalloutViewImageConfig.IMAGE_CONFIG_ICON)
icon.setImageResource(iconRes)
}

private fun setImage(@DrawableRes imageRes: Int) {
setImageConfig(CalloutViewImageConfig.IMAGE_CONFIG_SQUARE)
image.setImageResource(imageRes)
}

private fun setCircularImage(@DrawableRes imageRes: Int) {
setImageConfig(CalloutViewImageConfig.IMAGE_CONFIG_CIRCULAR)
circularImage.setImageResource(imageRes)
}

fun setTitle(text: String) {
if (text.isNotBlank()) {
title.text = text
Expand Down Expand Up @@ -369,25 +350,25 @@ class CalloutView @JvmOverloads constructor(

private fun setImageConfig(imageConfig: CalloutViewImageConfig) {
when (imageConfig) {
CalloutViewImageConfig.IMAGE_CONFIG_NONE -> {
CalloutViewImageConfig.NONE -> {
icon.visibility = GONE
image.visibility = GONE
circularImage.visibility = GONE
}

CalloutViewImageConfig.IMAGE_CONFIG_ICON -> {
CalloutViewImageConfig.ICON -> {
icon.visibility = VISIBLE
image.visibility = GONE
circularImage.visibility = GONE
}

CalloutViewImageConfig.IMAGE_CONFIG_SQUARE -> {
CalloutViewImageConfig.SQUARE_IMAGE -> {
icon.visibility = GONE
image.visibility = VISIBLE
circularImage.visibility = GONE
}

CalloutViewImageConfig.IMAGE_CONFIG_CIRCULAR -> {
CalloutViewImageConfig.CIRCULAR_IMAGE -> {
icon.visibility = GONE
image.visibility = GONE
circularImage.visibility = VISIBLE
Expand Down Expand Up @@ -420,14 +401,14 @@ class CalloutView @JvmOverloads constructor(
}

enum class CalloutViewImageConfig(val value: Int) {
IMAGE_CONFIG_NONE(-1),
IMAGE_CONFIG_ICON(0),
IMAGE_CONFIG_SQUARE(1),
IMAGE_CONFIG_CIRCULAR(2);
NONE(-1),
ICON(0),
SQUARE_IMAGE(1),
CIRCULAR_IMAGE(2);

companion object {
fun getConfigByValue(item: Int): CalloutViewImageConfig {
return values().firstOrNull { it.value == item } ?: IMAGE_CONFIG_NONE
return values().firstOrNull { it.value == item } ?: NONE
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fun Callout(
description: String?,
buttonConfig: CalloutButtonConfig,
@DrawableRes iconRes: Int? = null,
imageConfig: CalloutViewImageConfig = CalloutViewImageConfig.IMAGE_CONFIG_NONE,
imageConfig: CalloutViewImageConfig = CalloutViewImageConfig.NONE,
dismissable: Boolean,
onDismiss: (() -> Unit)? = null,
inverse: Boolean,
Expand Down Expand Up @@ -201,31 +201,31 @@ private fun Icon(
imageConfig: CalloutViewImageConfig,
) {
val iconPainter = when (imageConfig) {
CalloutViewImageConfig.IMAGE_CONFIG_ICON -> {
CalloutViewImageConfig.ICON -> {
resourceIconPainter(
iconRes = iconRes,
iconType = IconType.ICON,
modifier = Modifier.padding(end = 16.dp)
)
}

CalloutViewImageConfig.IMAGE_CONFIG_SQUARE -> {
CalloutViewImageConfig.SQUARE_IMAGE -> {
resourceIconPainter(
iconRes = iconRes,
iconType = IconType.SQUARE_IMAGE,
modifier = Modifier.padding(end = 16.dp)
)
}

CalloutViewImageConfig.IMAGE_CONFIG_CIRCULAR -> {
CalloutViewImageConfig.CIRCULAR_IMAGE -> {
resourceIconPainter(
iconRes = iconRes,
iconType = IconType.CIRCULAR_ASSET,
modifier = Modifier.padding(end = 16.dp)
)
}

CalloutViewImageConfig.IMAGE_CONFIG_NONE -> noIcon()
CalloutViewImageConfig.NONE -> noIcon()
}

iconPainter.Paint()
Expand Down
9 changes: 6 additions & 3 deletions library/src/main/res/layout/callout_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,18 @@
/>

<FrameLayout
android:id="@+id/callout_image_layout"
android:id="@+id/callout_image_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="16dp">
>

<ImageView
android:id="@+id/callout_icon"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginStart="16dp"
android:importantForAccessibility="no"
tools:src="@tools:sample/avatars"
/>
Expand All @@ -42,17 +43,19 @@
android:id="@+id/callout_image"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginStart="16dp"
android:importantForAccessibility="no"
android:scaleType="centerCrop"
tools:src="@tools:sample/avatars"
tools:visibility="gone"
/>

<com.google.android.material.imageview.ShapeableImageView
android:id="@+id/data_card_circular_icon"
android:id="@+id/callout_circular_image"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_marginStart="16dp"
android:importantForAccessibility="no"
android:scaleType="centerCrop"
android:visibility="gone"
Expand Down

0 comments on commit ad03053

Please sign in to comment.