feat(creator): 라이브 정렬 팝업 UI를 추가한다
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
package kr.co.vividnext.sodalive.v2.creator.channel.live.ui
|
||||
|
||||
import android.graphics.Color
|
||||
import android.graphics.Rect
|
||||
import android.graphics.Outline
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.PopupWindow
|
||||
import android.widget.TextView
|
||||
import android.widget.FrameLayout
|
||||
import android.view.ViewOutlineProvider
|
||||
import androidx.core.graphics.drawable.toDrawable
|
||||
import kr.co.vividnext.sodalive.R
|
||||
import kr.co.vividnext.sodalive.v2.common.data.ContentSort
|
||||
import kr.co.vividnext.sodalive.v2.creator.channel.live.model.toSortOptionUiModel
|
||||
|
||||
class CreatorChannelLiveSortPopup(
|
||||
private val anchor: View,
|
||||
private val selectedSort: ContentSort,
|
||||
private val onSortSelected: (ContentSort) -> Unit
|
||||
) {
|
||||
|
||||
private val popupWindow: PopupWindow = PopupWindow(anchor.context).apply {
|
||||
contentView = createContentView()
|
||||
width = ViewGroup.LayoutParams.WRAP_CONTENT
|
||||
height = ViewGroup.LayoutParams.WRAP_CONTENT
|
||||
isOutsideTouchable = true
|
||||
isFocusable = true
|
||||
setBackgroundDrawable(Color.TRANSPARENT.toDrawable())
|
||||
}
|
||||
|
||||
fun show() {
|
||||
val content = popupWindow.contentView
|
||||
content.measure(
|
||||
View.MeasureSpec.makeMeasureSpec(anchor.rootView.width, View.MeasureSpec.AT_MOST),
|
||||
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)
|
||||
)
|
||||
popupWindow.showAsDropDown(anchor, calculateHorizontalOffset(content.measuredWidth), 0)
|
||||
}
|
||||
|
||||
fun dismiss() {
|
||||
popupWindow.dismiss()
|
||||
}
|
||||
|
||||
private fun createContentView(): View {
|
||||
val root = FrameLayout(anchor.context)
|
||||
val view = LayoutInflater.from(anchor.context).inflate(
|
||||
R.layout.view_creator_channel_live_sort_menu,
|
||||
root,
|
||||
false
|
||||
)
|
||||
view.clipToOutline = true
|
||||
view.outlineProvider = object : ViewOutlineProvider() {
|
||||
override fun getOutline(view: View, outline: Outline) {
|
||||
outline.setRoundRect(0, 0, view.width, view.height, view.resources.getDimension(R.dimen.radius_14))
|
||||
}
|
||||
}
|
||||
val container = view.findViewById<LinearLayout>(R.id.layout_creator_channel_live_sort_options)
|
||||
val sample = view.findViewById<TextView>(R.id.tv_creator_channel_live_sort_option_sample)
|
||||
container.removeView(sample)
|
||||
|
||||
ContentSort.entries.map { it.toSortOptionUiModel(selectedSort) }.forEach { option ->
|
||||
val row = TextView(anchor.context).apply {
|
||||
layoutParams = LinearLayout.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT
|
||||
)
|
||||
typeface = sample.typeface
|
||||
includeFontPadding = false
|
||||
setPadding(sample.paddingStart, sample.paddingTop, sample.paddingEnd, sample.paddingBottom)
|
||||
setText(option.labelResId)
|
||||
setTextColor(sample.currentTextColor)
|
||||
textSize = 16f
|
||||
if (option.isSelected) {
|
||||
setBackgroundResource(R.drawable.bg_creator_channel_live_sort_selected)
|
||||
}
|
||||
setOnClickListener {
|
||||
if (option.sort != selectedSort) {
|
||||
onSortSelected(option.sort)
|
||||
}
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
container.addView(row)
|
||||
}
|
||||
|
||||
return view
|
||||
}
|
||||
|
||||
private fun calculateHorizontalOffset(popupWidth: Int): Int {
|
||||
val visibleDisplayFrame = Rect()
|
||||
anchor.rootView.getWindowVisibleDisplayFrame(visibleDisplayFrame)
|
||||
|
||||
val anchorLocation = IntArray(2)
|
||||
anchor.getLocationOnScreen(anchorLocation)
|
||||
val popupRight = anchorLocation[0] + popupWidth
|
||||
return if (popupRight > visibleDisplayFrame.right) {
|
||||
visibleDisplayFrame.right - popupRight
|
||||
} else {
|
||||
0
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<solid android:color="@color/gray_900" />
|
||||
<stroke
|
||||
android:width="1dp"
|
||||
android:color="@color/gray_700" />
|
||||
<corners android:radius="@dimen/radius_14" />
|
||||
</shape>
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<solid android:color="@color/gray_800" />
|
||||
</shape>
|
||||
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/layout_creator_channel_live_sort_options"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/bg_creator_channel_live_sort_popup"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_creator_channel_live_sort_option_sample"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:fontFamily="@font/medium"
|
||||
android:includeFontPadding="false"
|
||||
android:paddingHorizontal="@dimen/spacing_12"
|
||||
android:paddingVertical="@dimen/spacing_8"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="16sp" />
|
||||
</LinearLayout>
|
||||
Reference in New Issue
Block a user