feat(feed): 랭킹 피드 뷰를 추가한다
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
package kr.co.vividnext.sodalive.v2.widget.feed
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Outline
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.ViewOutlineProvider
|
||||
import android.widget.ImageView
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import androidx.core.content.ContextCompat
|
||||
import kr.co.vividnext.sodalive.R
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
class FeedRankView @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
defStyleAttr: Int = 0
|
||||
) : LinearLayout(context, attrs, defStyleAttr) {
|
||||
|
||||
private var image: ImageView? = null
|
||||
private var rankText: TextView? = null
|
||||
private var messageText: TextView? = null
|
||||
private var currentItem: FeedItem.Rank? = null
|
||||
private var clickListener: ((FeedItem) -> Unit)? = null
|
||||
|
||||
override fun onFinishInflate() {
|
||||
super.onFinishInflate()
|
||||
image = findViewById(R.id.iv_feed_rank_image)
|
||||
rankText = findViewById(R.id.tv_feed_rank_overlay)
|
||||
messageText = findViewById(R.id.tv_feed_rank_message)
|
||||
imageView().clipToOutline = true
|
||||
imageView().outlineProvider = roundedOutlineProvider()
|
||||
}
|
||||
|
||||
fun bind(item: FeedItem.Rank) {
|
||||
currentItem = item
|
||||
requireNotNull(rankText).text = item.rankText
|
||||
requireNotNull(messageText).text = FeedRankTextStyler.style(
|
||||
text = item.message,
|
||||
highlightRanges = item.highlightRanges,
|
||||
highlightColor = ContextCompat.getColor(context, R.color.soda_400)
|
||||
)
|
||||
applyClickState(item)
|
||||
}
|
||||
|
||||
fun imageView(): ImageView = requireNotNull(image)
|
||||
|
||||
fun setFeedSize(size: FeedSize) {
|
||||
updateRootWidth(size.rootWidthDp.dpToPx())
|
||||
}
|
||||
|
||||
fun setOnFeedClick(listener: ((FeedItem) -> Unit)?) {
|
||||
clickListener = listener
|
||||
currentItem?.let(::applyClickState)
|
||||
}
|
||||
|
||||
private fun applyClickState(item: FeedItem.Rank) {
|
||||
val listener = clickListener
|
||||
setOnClickListener(if (listener == null) null else View.OnClickListener { listener(item) })
|
||||
isClickable = listener != null
|
||||
}
|
||||
|
||||
private fun updateRootWidth(width: Int) {
|
||||
val currentLayoutParams = layoutParams
|
||||
layoutParams = if (currentLayoutParams == null) {
|
||||
ViewGroup.LayoutParams(width, ViewGroup.LayoutParams.WRAP_CONTENT)
|
||||
} else {
|
||||
currentLayoutParams.apply { this.width = width }
|
||||
}
|
||||
}
|
||||
|
||||
private fun roundedOutlineProvider() = object : ViewOutlineProvider() {
|
||||
override fun getOutline(view: View, outline: Outline) {
|
||||
outline.setRoundRect(0, 0, view.width, view.height, resources.getDimension(R.dimen.radius_14))
|
||||
}
|
||||
}
|
||||
|
||||
private fun Int.dpToPx(): Int = (this * resources.displayMetrics.density).roundToInt()
|
||||
}
|
||||
58
app/src/main/res/layout/view_feed_rank.xml
Normal file
58
app/src/main/res/layout/view_feed_rank.xml
Normal file
@@ -0,0 +1,58 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<kr.co.vividnext.sodalive.v2.widget.feed.FeedRankView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="374dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/bg_feed_card"
|
||||
android:clipChildren="false"
|
||||
android:clipToPadding="false"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:padding="@dimen/spacing_14">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/fl_feed_rank_image_container"
|
||||
android:layout_width="80dp"
|
||||
android:layout_height="80dp"
|
||||
android:clipChildren="false"
|
||||
android:clipToPadding="false">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/iv_feed_rank_image"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:contentDescription="@string/a11y_feed_rank_image"
|
||||
android:scaleType="centerCrop"
|
||||
tools:src="@drawable/ic_launcher_background" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_feed_rank_overlay"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="end|bottom"
|
||||
android:layout_marginEnd="-6dp"
|
||||
android:layout_marginBottom="-22dp"
|
||||
android:fontFamily="@font/pattaya_regular"
|
||||
android:includeFontPadding="false"
|
||||
android:shadowColor="#7A000000"
|
||||
android:shadowDx="0"
|
||||
android:shadowDy="0"
|
||||
android:shadowRadius="4"
|
||||
android:textColor="#EEEEEE"
|
||||
android:textSize="40sp"
|
||||
tools:text="2" />
|
||||
</FrameLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_feed_rank_message"
|
||||
style="@style/Typography.Body2"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="@dimen/spacing_14"
|
||||
android:layout_weight="1"
|
||||
android:ellipsize="end"
|
||||
android:includeFontPadding="false"
|
||||
android:maxLines="2"
|
||||
android:textColor="@color/white"
|
||||
tools:text="{{크리에이터 이름}}님이 5월 2주차 크리에이터 12위를 차지하였어요!" />
|
||||
</kr.co.vividnext.sodalive.v2.widget.feed.FeedRankView>
|
||||
Reference in New Issue
Block a user