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.TextView
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import kr.co.vividnext.sodalive.R
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
class FeedLiveView @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
defStyleAttr: Int = 0
|
||||
) : ConstraintLayout(context, attrs, defStyleAttr) {
|
||||
|
||||
private var profileImage: ImageView? = null
|
||||
private var endedMessageText: TextView? = null
|
||||
private var titleText: TextView? = null
|
||||
private var createdAtText: TextView? = null
|
||||
private var currentItem: FeedItem.Live? = null
|
||||
private var clickListener: ((FeedItem) -> Unit)? = null
|
||||
|
||||
override fun onFinishInflate() {
|
||||
super.onFinishInflate()
|
||||
profileImage = findViewById(R.id.iv_feed_live_profile)
|
||||
endedMessageText = findViewById(R.id.tv_feed_live_ended_message)
|
||||
titleText = findViewById(R.id.tv_feed_live_title)
|
||||
createdAtText = findViewById(R.id.tv_feed_live_created_at)
|
||||
profileImageView().clipToOutline = true
|
||||
profileImageView().outlineProvider = circleOutlineProvider()
|
||||
}
|
||||
|
||||
fun bind(item: FeedItem.Live) {
|
||||
currentItem = item
|
||||
endedMessageTextView().text = item.endedMessage
|
||||
requireNotNull(titleText).text = item.liveTitle
|
||||
requireNotNull(createdAtText).text = item.createdAtText
|
||||
applyClickState(item)
|
||||
}
|
||||
|
||||
fun profileImageView(): ImageView = requireNotNull(profileImage)
|
||||
|
||||
fun endedMessageTextView(): TextView = requireNotNull(endedMessageText)
|
||||
|
||||
fun setFeedSize(size: FeedSize) {
|
||||
updateRootWidth(size.rootWidthDp.dpToPx())
|
||||
}
|
||||
|
||||
fun setOnFeedClick(listener: ((FeedItem) -> Unit)?) {
|
||||
clickListener = listener
|
||||
currentItem?.let(::applyClickState)
|
||||
}
|
||||
|
||||
private fun applyClickState(item: FeedItem.Live) {
|
||||
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 circleOutlineProvider() = object : ViewOutlineProvider() {
|
||||
override fun getOutline(view: View, outline: Outline) {
|
||||
outline.setOval(0, 0, view.width, view.height)
|
||||
}
|
||||
}
|
||||
|
||||
private fun Int.dpToPx(): Int = (this * resources.displayMetrics.density).roundToInt()
|
||||
}
|
||||
72
app/src/main/res/layout/view_feed_live.xml
Normal file
72
app/src/main/res/layout/view_feed_live.xml
Normal file
@@ -0,0 +1,72 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<kr.co.vividnext.sodalive.v2.widget.feed.FeedLiveView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="374dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/bg_feed_card"
|
||||
android:clipToOutline="true"
|
||||
android:padding="@dimen/spacing_14">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/ll_feed_live_header"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="20dp"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/iv_feed_live_profile"
|
||||
android:layout_width="20dp"
|
||||
android:layout_height="20dp"
|
||||
android:contentDescription="@string/a11y_feed_profile_image"
|
||||
android:scaleType="centerCrop"
|
||||
tools:src="@drawable/ic_launcher_background" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_feed_live_ended_message"
|
||||
style="@style/Typography.Caption3"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="@dimen/spacing_4"
|
||||
android:layout_weight="1"
|
||||
android:ellipsize="end"
|
||||
android:includeFontPadding="false"
|
||||
android:maxLines="1"
|
||||
android:textColor="@color/white"
|
||||
tools:text="크리에이터이름님의 라이브 방송이 종료되었습니다." />
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_feed_live_title"
|
||||
style="@style/Typography.Heading4"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/spacing_6"
|
||||
android:layout_marginEnd="@dimen/spacing_20"
|
||||
android:ellipsize="end"
|
||||
android:includeFontPadding="false"
|
||||
android:maxLines="1"
|
||||
android:textColor="@color/white"
|
||||
app:layout_constraintEnd_toStartOf="@+id/tv_feed_live_created_at"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/ll_feed_live_header"
|
||||
tools:text="라이브 방송 이름" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_feed_live_created_at"
|
||||
style="@style/Typography.Body6"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:ellipsize="end"
|
||||
android:includeFontPadding="false"
|
||||
android:maxLines="1"
|
||||
android:textColor="@color/gray_500"
|
||||
app:layout_constraintBottom_toBottomOf="@id/tv_feed_live_title"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@id/tv_feed_live_title"
|
||||
tools:text="2분 전" />
|
||||
</kr.co.vividnext.sodalive.v2.widget.feed.FeedLiveView>
|
||||
Reference in New Issue
Block a user