fix(widget): 캐릭터 채팅 썸네일 clipping을 Kotlin에서 설정한다
This commit is contained in:
@@ -33,8 +33,7 @@ class CharacterChatThumbnailView @JvmOverloads constructor(
|
|||||||
characterNameText = findViewById(R.id.tv_character_chat_name)
|
characterNameText = findViewById(R.id.tv_character_chat_name)
|
||||||
characterDescriptionText = findViewById(R.id.tv_character_chat_description)
|
characterDescriptionText = findViewById(R.id.tv_character_chat_description)
|
||||||
originalTitleText = findViewById(R.id.tv_character_chat_original_title)
|
originalTitleText = findViewById(R.id.tv_character_chat_original_title)
|
||||||
clipToOutline = true
|
setCardOutline()
|
||||||
outlineProvider = roundedCardOutlineProvider()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun bind(item: CharacterChatThumbnailItem) {
|
fun bind(item: CharacterChatThumbnailItem) {
|
||||||
@@ -63,10 +62,12 @@ class CharacterChatThumbnailView @JvmOverloads constructor(
|
|||||||
isClickable = listener != null
|
isClickable = listener != null
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun roundedCardOutlineProvider() = object : ViewOutlineProvider() {
|
private fun setCardOutline() {
|
||||||
override fun getOutline(view: View, outline: Outline) {
|
clipToOutline = true
|
||||||
val radius = resources.getDimension(R.dimen.radius_14)
|
outlineProvider = object : ViewOutlineProvider() {
|
||||||
outline.setRoundRect(0, 0, view.width, view.height, radius)
|
override fun getOutline(view: View, outline: Outline) {
|
||||||
|
outline.setRoundRect(0, 0, view.width, view.height, resources.getDimension(R.dimen.radius_14))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,8 +3,7 @@
|
|||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="185dp"
|
android:layout_width="185dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="@drawable/bg_character_chat_thumbnail"
|
android:background="@drawable/bg_character_chat_thumbnail">
|
||||||
android:clipToOutline="true">
|
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/iv_character_chat_thumbnail_image"
|
android:id="@+id/iv_character_chat_thumbnail_image"
|
||||||
|
|||||||
@@ -10,7 +10,9 @@ import androidx.test.core.app.ApplicationProvider
|
|||||||
import kr.co.vividnext.sodalive.R
|
import kr.co.vividnext.sodalive.R
|
||||||
import org.junit.Assert.assertEquals
|
import org.junit.Assert.assertEquals
|
||||||
import org.junit.Assert.assertFalse
|
import org.junit.Assert.assertFalse
|
||||||
|
import org.junit.Assert.assertNotNull
|
||||||
import org.junit.Assert.assertSame
|
import org.junit.Assert.assertSame
|
||||||
|
import org.junit.Assert.assertTrue
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.runner.RunWith
|
import org.junit.runner.RunWith
|
||||||
import org.robolectric.RobolectricTestRunner
|
import org.robolectric.RobolectricTestRunner
|
||||||
@@ -51,6 +53,30 @@ class CharacterChatThumbnailViewTest {
|
|||||||
assertSame(view.findViewById<ImageView>(R.id.iv_character_chat_thumbnail_image), view.imageView())
|
assertSame(view.findViewById<ImageView>(R.id.iv_character_chat_thumbnail_image), view.imageView())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Config(sdk = [23])
|
||||||
|
fun `card clipping is configured from Kotlin outline provider`() {
|
||||||
|
val view = inflateView()
|
||||||
|
|
||||||
|
assertTrue(view.clipToOutline)
|
||||||
|
assertNotNull(view.outlineProvider)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `layout does not declare xml clipToOutline`() {
|
||||||
|
val context = ApplicationProvider.getApplicationContext<Context>()
|
||||||
|
val parser = context.resources.getXml(R.layout.view_character_chat_thumbnail)
|
||||||
|
while (parser.eventType != org.xmlpull.v1.XmlPullParser.START_TAG) {
|
||||||
|
parser.next()
|
||||||
|
}
|
||||||
|
|
||||||
|
val hasClipToOutline = (0 until parser.attributeCount).any { index ->
|
||||||
|
parser.getAttributeName(index) == "clipToOutline"
|
||||||
|
}
|
||||||
|
|
||||||
|
assertFalse(hasClipToOutline)
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `setOnCharacterClick invokes listener with bound item`() {
|
fun `setOnCharacterClick invokes listener with bound item`() {
|
||||||
val view = inflateView()
|
val view = inflateView()
|
||||||
|
|||||||
Reference in New Issue
Block a user