feat(content): 랭킹 변동 숨김 처리를 추가한다
This commit is contained in:
@@ -80,6 +80,9 @@ open class ContentRankingGridCardView @JvmOverloads constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun bindDelta(item: ContentRankingItem) {
|
private fun bindDelta(item: ContentRankingItem) {
|
||||||
|
requireNotNull(deltaGroup).visibility = if (item.showRankChange) View.VISIBLE else View.GONE
|
||||||
|
if (!item.showRankChange) return
|
||||||
|
|
||||||
val presentation = ContentRankingDeltaPresentation.from(item.rankChangeType, item.rankChangeAmount)
|
val presentation = ContentRankingDeltaPresentation.from(item.rankChangeType, item.rankChangeAmount)
|
||||||
applyDeltaContainer(presentation)
|
applyDeltaContainer(presentation)
|
||||||
requireNotNull(deltaIcon).apply {
|
requireNotNull(deltaIcon).apply {
|
||||||
@@ -150,7 +153,10 @@ open class ContentRankingGridCardView @JvmOverloads constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun placeLabel(width: Int, top: Int, scale: Float, size: ContentRankingCardSize) {
|
private fun placeLabel(width: Int, top: Int, scale: Float, size: ContentRankingCardSize) {
|
||||||
findViewById<View>(R.id.ll_content_ranking_label).layoutParams = LayoutParams((width * scale).roundToInt(), ViewGroup.LayoutParams.WRAP_CONTENT).apply {
|
findViewById<View>(R.id.ll_content_ranking_label).layoutParams = LayoutParams(
|
||||||
|
(width * scale).roundToInt(),
|
||||||
|
ViewGroup.LayoutParams.WRAP_CONTENT
|
||||||
|
).apply {
|
||||||
leftMargin = ((size.widthPx - (width * scale)) / 2f).roundToInt()
|
leftMargin = ((size.widthPx - (width * scale)) / 2f).roundToInt()
|
||||||
topMargin = (top * scale).roundToInt()
|
topMargin = (top * scale).roundToInt()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,6 +79,10 @@ class ContentRankingHorizontalCardView @JvmOverloads constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun bindDelta(item: ContentRankingItem) {
|
private fun bindDelta(item: ContentRankingItem) {
|
||||||
|
val deltaGroup = findViewById<View>(R.id.ll_content_ranking_delta)
|
||||||
|
deltaGroup.visibility = if (item.showRankChange) View.VISIBLE else View.GONE
|
||||||
|
if (!item.showRankChange) return
|
||||||
|
|
||||||
val presentation = ContentRankingDeltaPresentation.from(item.rankChangeType, item.rankChangeAmount)
|
val presentation = ContentRankingDeltaPresentation.from(item.rankChangeType, item.rankChangeAmount)
|
||||||
applyDeltaContainer(presentation)
|
applyDeltaContainer(presentation)
|
||||||
requireNotNull(deltaIcon).apply {
|
requireNotNull(deltaIcon).apply {
|
||||||
@@ -111,7 +115,10 @@ class ContentRankingHorizontalCardView @JvmOverloads constructor(
|
|||||||
|
|
||||||
private fun positionViews(size: ContentRankingCardSize) {
|
private fun positionViews(size: ContentRankingCardSize) {
|
||||||
val scale = size.widthPx / 374f
|
val scale = size.widthPx / 374f
|
||||||
requireNotNull(rankGroup).layoutParams = LayoutParams((49 * scale).roundToInt(), ViewGroup.LayoutParams.WRAP_CONTENT).apply {
|
requireNotNull(rankGroup).layoutParams = LayoutParams(
|
||||||
|
(49 * scale).roundToInt(),
|
||||||
|
ViewGroup.LayoutParams.WRAP_CONTENT
|
||||||
|
).apply {
|
||||||
leftMargin = (14 * scale).roundToInt()
|
leftMargin = (14 * scale).roundToInt()
|
||||||
topMargin = (14 * scale).roundToInt()
|
topMargin = (14 * scale).roundToInt()
|
||||||
}
|
}
|
||||||
@@ -120,11 +127,17 @@ class ContentRankingHorizontalCardView @JvmOverloads constructor(
|
|||||||
leftMargin = (77 * scale).roundToInt()
|
leftMargin = (77 * scale).roundToInt()
|
||||||
topMargin = (10 * scale).roundToInt()
|
topMargin = (10 * scale).roundToInt()
|
||||||
}
|
}
|
||||||
findViewById<View>(R.id.ll_content_ranking_label).layoutParams = LayoutParams((189 * scale).roundToInt(), ViewGroup.LayoutParams.WRAP_CONTENT).apply {
|
findViewById<View>(R.id.ll_content_ranking_label).layoutParams = LayoutParams(
|
||||||
|
(189 * scale).roundToInt(),
|
||||||
|
ViewGroup.LayoutParams.WRAP_CONTENT
|
||||||
|
).apply {
|
||||||
leftMargin = (171 * scale).roundToInt()
|
leftMargin = (171 * scale).roundToInt()
|
||||||
topMargin = (31 * scale).roundToInt()
|
topMargin = (31 * scale).roundToInt()
|
||||||
}
|
}
|
||||||
requireNotNull(inaccessibleText).layoutParams = LayoutParams((189 * scale).roundToInt(), ViewGroup.LayoutParams.WRAP_CONTENT).apply {
|
requireNotNull(inaccessibleText).layoutParams = LayoutParams(
|
||||||
|
(189 * scale).roundToInt(),
|
||||||
|
ViewGroup.LayoutParams.WRAP_CONTENT
|
||||||
|
).apply {
|
||||||
leftMargin = (171 * scale).roundToInt()
|
leftMargin = (171 * scale).roundToInt()
|
||||||
topMargin = (38 * scale).roundToInt()
|
topMargin = (38 * scale).roundToInt()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,6 +84,9 @@ class ContentRankingLargeCardView @JvmOverloads constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun bindDelta(item: ContentRankingItem) {
|
private fun bindDelta(item: ContentRankingItem) {
|
||||||
|
requireNotNull(deltaGroup).visibility = if (item.showRankChange) View.VISIBLE else View.GONE
|
||||||
|
if (!item.showRankChange) return
|
||||||
|
|
||||||
val presentation = ContentRankingDeltaPresentation.from(item.rankChangeType, item.rankChangeAmount)
|
val presentation = ContentRankingDeltaPresentation.from(item.rankChangeType, item.rankChangeAmount)
|
||||||
applyDeltaContainer(presentation)
|
applyDeltaContainer(presentation)
|
||||||
requireNotNull(deltaIcon).apply {
|
requireNotNull(deltaIcon).apply {
|
||||||
@@ -128,7 +131,10 @@ class ContentRankingLargeCardView @JvmOverloads constructor(
|
|||||||
leftMargin = (20 * scale).roundToInt()
|
leftMargin = (20 * scale).roundToInt()
|
||||||
topMargin = (109 * scale).roundToInt()
|
topMargin = (109 * scale).roundToInt()
|
||||||
}
|
}
|
||||||
findViewById<View>(R.id.ll_content_ranking_label).layoutParams = LayoutParams((165 * scale).roundToInt(), ViewGroup.LayoutParams.WRAP_CONTENT).apply {
|
findViewById<View>(R.id.ll_content_ranking_label).layoutParams = LayoutParams(
|
||||||
|
(165 * scale).roundToInt(),
|
||||||
|
ViewGroup.LayoutParams.WRAP_CONTENT
|
||||||
|
).apply {
|
||||||
leftMargin = ((size.widthPx - (165 * scale)) / 2f).roundToInt()
|
leftMargin = ((size.widthPx - (165 * scale)) / 2f).roundToInt()
|
||||||
topMargin = (182 * scale).roundToInt()
|
topMargin = (182 * scale).roundToInt()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,86 @@
|
|||||||
|
package kr.co.vividnext.sodalive.v2.widget.contentranking
|
||||||
|
|
||||||
|
import android.app.Application
|
||||||
|
import android.content.Context
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import androidx.test.core.app.ApplicationProvider
|
||||||
|
import kr.co.vividnext.sodalive.R
|
||||||
|
import kr.co.vividnext.sodalive.v2.widget.ranking.RankingChangeType.Increase
|
||||||
|
import org.junit.Assert.assertEquals
|
||||||
|
import org.junit.Test
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
import org.robolectric.RobolectricTestRunner
|
||||||
|
import org.robolectric.annotation.Config
|
||||||
|
|
||||||
|
@RunWith(RobolectricTestRunner::class)
|
||||||
|
@Config(sdk = [28], application = Application::class)
|
||||||
|
class ContentRankingCardViewTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `large card는 showRankChange가 false이면 rank num을 숨긴다`() {
|
||||||
|
val view = inflateView<ContentRankingLargeCardView>(R.layout.view_content_ranking_large_card)
|
||||||
|
|
||||||
|
view.bind(sampleItem(showRankChange = false))
|
||||||
|
|
||||||
|
assertEquals(View.GONE, view.findViewById<View>(R.id.ll_content_ranking_delta).visibility)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `medium grid card는 showRankChange가 false이면 rank num을 숨긴다`() {
|
||||||
|
val view = inflateView<ContentRankingMediumGridCardView>(R.layout.view_content_ranking_medium_grid_card)
|
||||||
|
|
||||||
|
view.bind(sampleItem(rank = 2, showRankChange = false))
|
||||||
|
|
||||||
|
assertEquals(View.GONE, view.findViewById<View>(R.id.ll_content_ranking_delta).visibility)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `small grid card는 showRankChange가 false이면 rank num을 숨긴다`() {
|
||||||
|
val view = inflateView<ContentRankingSmallGridCardView>(R.layout.view_content_ranking_small_grid_card)
|
||||||
|
|
||||||
|
view.bind(sampleItem(rank = 8, showRankChange = false))
|
||||||
|
|
||||||
|
assertEquals(View.GONE, view.findViewById<View>(R.id.ll_content_ranking_delta).visibility)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `horizontal card는 showRankChange가 false이면 rank num을 숨긴다`() {
|
||||||
|
val view = inflateView<ContentRankingHorizontalCardView>(R.layout.view_content_ranking_horizontal_card)
|
||||||
|
|
||||||
|
view.bind(sampleItem(rank = 11, showRankChange = false))
|
||||||
|
|
||||||
|
assertEquals(View.GONE, view.findViewById<View>(R.id.ll_content_ranking_delta).visibility)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `card는 showRankChange가 true이면 rank num을 보여준다`() {
|
||||||
|
val view = inflateView<ContentRankingLargeCardView>(R.layout.view_content_ranking_large_card)
|
||||||
|
|
||||||
|
view.bind(sampleItem(showRankChange = true))
|
||||||
|
|
||||||
|
assertEquals(View.VISIBLE, view.findViewById<View>(R.id.ll_content_ranking_delta).visibility)
|
||||||
|
}
|
||||||
|
|
||||||
|
private inline fun <reified T : View> inflateView(layoutResId: Int): T {
|
||||||
|
val context = ApplicationProvider.getApplicationContext<Context>()
|
||||||
|
return LayoutInflater.from(context).inflate(layoutResId, null, false) as T
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun sampleItem(
|
||||||
|
rank: Int = 1,
|
||||||
|
showRankChange: Boolean = true
|
||||||
|
) = ContentRankingItem(
|
||||||
|
contentId = "content-1",
|
||||||
|
creatorId = "creator-1",
|
||||||
|
rank = rank,
|
||||||
|
previousRank = 5,
|
||||||
|
rankChangeType = Increase,
|
||||||
|
rankChangeAmount = 4,
|
||||||
|
contentName = "콘텐츠 이름",
|
||||||
|
creatorName = "크리에이터 이름",
|
||||||
|
imageUrl = "https://example.com/image.png",
|
||||||
|
isBlocked = false,
|
||||||
|
showRankChange = showRankChange
|
||||||
|
)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user