Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ import com.personalization.ui.PersonalizationTheme
* Крестик стоит **всегда** и живёт в самом попапе, а не в контейнере картинки: в макете
* виды «только текст» и «иконка» картинки не имеют, но крестик у них нарисован. Он круглый
* (компонент Close: кнопка MD с радиусом Rounded) и лежит поверх содержимого в углу, на
* отступе попапа; над фотографией — в тёмном варианте.
* отступе попапа. Над фотографией макет рисует его в тёмном варианте (белая иконка на белой
* подложке 5%), но на светлом фото — а фото товара почти всегда на белом — такой крестик
* пропадает. Поэтому крестик везде обычный вторичный и лежит на круге цвета карточки: на
* любом фото виден либо круг, либо иконка.
*
* Картинка сверху вписывается целиком, с полями цвета карточки: обрезка срезала бы сам
* товар. Картинка фоном заполняет попап и обрезается — на то она и фон.
* Текстовая кнопка закрытия ([closeText]) в макете не нарисована — её даёт админка
* отдельным тумблером рядом с кнопкой действия, поэтому она здесь вторичной кнопкой
* под основной. Пустой текст — кнопки нет, остаётся один крестик.
Expand Down Expand Up @@ -66,6 +72,9 @@ class PersonalizationInAppPopup @JvmOverloads constructor(
private val closeButton = PersonalizationButton(context)
private val closeIcon = PersonalizationButton(context)

/** Круг цвета карточки под полупрозрачным крестиком — чтобы тот был виден на любом фото. */
private val closeBacking = FrameLayout(context)

private val column = LinearLayout(context)
private val body = LinearLayout(context)
private val content = LinearLayout(context)
Expand Down Expand Up @@ -133,7 +142,7 @@ class PersonalizationInAppPopup @JvmOverloads constructor(

init {
backgroundImage.scaleType = ImageView.ScaleType.CENTER_CROP
topImage.scaleType = ImageView.ScaleType.CENTER_CROP
topImage.scaleType = ImageView.ScaleType.FIT_CENTER
iconView.adjustViewBounds = true

titleView.includeFontPadding = false
Expand All @@ -154,6 +163,11 @@ class PersonalizationInAppPopup @JvmOverloads constructor(
closeIcon.rounded = true
closeIcon.iconStart = R.drawable.personalization_ic_cross_large
closeIcon.setOnClickListener { onClose?.invoke() }
closeBacking.background = GradientDrawable().apply {
shape = GradientDrawable.OVAL
setColor(PersonalizationTheme.color(context, R.color.personalization_background_card))
}
closeBacking.addView(closeIcon, LayoutParams(WRAP, WRAP))

column.orientation = LinearLayout.VERTICAL
body.orientation = LinearLayout.VERTICAL
Expand Down Expand Up @@ -244,17 +258,15 @@ class PersonalizationInAppPopup @JvmOverloads constructor(

// Крестик всегда на месте — у видов без картинки тоже, накладкой поверх содержимого.
addView(
closeIcon,
closeBacking,
LayoutParams(WRAP, WRAP, Gravity.TOP or Gravity.END).also {
it.topMargin = pad
it.marginEnd = pad
}
)

// Поверх картинки контролы берут инвертированную палитру, иначе тёмная подпись
// вторичной кнопки тонет в фотографии. Крестик над фотографией и у вида с картинкой
// сверху: в макете у него там тёмный режим.
closeIcon.onDark = overImage || contentView == ContentView.IMAGE
// Поверх картинки текстовая кнопка закрытия берёт инвертированную палитру, иначе её
// тёмная подпись тонет в фотографии. Крестику хватает круга под ним.
closeButton.onDark = overImage

imageLoader?.invoke(if (overImage) backgroundImage else topImage)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package com.personalization.ui.components

import android.content.Context
import android.content.res.ColorStateList
import android.graphics.drawable.GradientDrawable
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.test.core.app.ApplicationProvider
import android.view.ViewGroup.MarginLayoutParams
import com.personalization.R
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertSame
import org.junit.Assert.assertTrue
import org.junit.Test
Expand Down Expand Up @@ -69,11 +73,40 @@ class PersonalizationInAppPopupTest {

val cross = buttons(popup).single { it.iconStart != null }

assertSame("$view: the cross lies over the content", popup, cross.parent)
assertSame("$view: the cross lies over the content", popup, (cross.parent as View).parent)
assertTrue("$view: the cross is round", cross.rounded)
}
}

// The design's dark cross over a photo (white on white 5%) vanishes on the light product
// photos shops send; on a disc of the card colour either the disc or the icon shows.
@Test
fun `the cross sits on a card-coloured disc over a photo too`() {
val card = context.getColor(R.color.personalization_background_card)
for (view in PersonalizationInAppPopup.ContentView.values()) {
val popup = PersonalizationInAppPopup(context).apply { contentView = view }
val cross = buttons(popup).single { it.iconStart != null }

assertFalse("$view: no dark variant", cross.onDark)
val disc = (cross.parent as View).background as GradientDrawable
assertEquals("$view", GradientDrawable.OVAL, disc.shape)
assertEquals("$view", ColorStateList.valueOf(card), disc.color)
}
}

@Test
fun `the top picture is never cropped, a background one fills`() {
fun scale(view: PersonalizationInAppPopup.ContentView) =
imageViews(PersonalizationInAppPopup(context).apply { contentView = view })
.single().scaleType

assertEquals(ImageView.ScaleType.FIT_CENTER, scale(PersonalizationInAppPopup.ContentView.IMAGE))
assertEquals(
ImageView.ScaleType.CENTER_CROP,
scale(PersonalizationInAppPopup.ContentView.IMAGE_BACKGROUND),
)
}

@Test
fun `buttons are 12 apart in a modal and 16 in a fullscreen popup`() {
val popup = PersonalizationInAppPopup(context).apply {
Expand All @@ -92,6 +125,14 @@ class PersonalizationInAppPopupTest {

private fun dimen(id: Int): Int = context.resources.getDimensionPixelSize(id)

// The popup's pictures, not the icons inside its buttons.
private fun imageViews(root: View): List<ImageView> = when (root) {
is PersonalizationButton -> emptyList()
is ImageView -> listOf(root)
is ViewGroup -> (0 until root.childCount).flatMap { imageViews(root.getChildAt(it)) }
else -> emptyList()
}

private fun buttons(root: View): List<PersonalizationButton> = when (root) {
is PersonalizationButton -> listOf(root)
is ViewGroup -> (0 until root.childCount).flatMap { buttons(root.getChildAt(it)) }
Expand Down
Loading