feat: 메인 홈
- 요일별 시리즈 UI 추가
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
package kr.co.vividnext.sodalive.home
|
||||
|
||||
data class DayOfWeek(
|
||||
val dayOfWeekStr: String,
|
||||
val dayOfWeek: SeriesPublishedDaysOfWeek
|
||||
)
|
||||
@@ -0,0 +1,86 @@
|
||||
package kr.co.vividnext.sodalive.home
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import kr.co.vividnext.sodalive.databinding.ItemDayOfWeekBinding
|
||||
import java.util.Calendar
|
||||
|
||||
class DayOfWeekAdapter(
|
||||
private val screenWidth: Int,
|
||||
private val onClickItem: (SeriesPublishedDaysOfWeek) -> Unit,
|
||||
) : RecyclerView.Adapter<DayOfWeekAdapter.ViewHolder>() {
|
||||
|
||||
inner class ViewHolder(
|
||||
private val binding: ItemDayOfWeekBinding
|
||||
) : RecyclerView.ViewHolder(binding.root) {
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
fun bind(dayOfWeek: DayOfWeek) {
|
||||
binding.tvDayOfWeek.text = dayOfWeek.dayOfWeekStr
|
||||
binding.tvDayOfWeek.isSelected = dayOfWeek.dayOfWeek == selectedDayOfWeek
|
||||
|
||||
val lp = binding.tvDayOfWeek.layoutParams
|
||||
lp.height = screenWidth * 38 / 400
|
||||
|
||||
if (dayOfWeek.dayOfWeek == SeriesPublishedDaysOfWeek.RANDOM) {
|
||||
lp.width = screenWidth * 54 / 400
|
||||
} else {
|
||||
lp.width = screenWidth * 38 / 400
|
||||
}
|
||||
|
||||
binding.tvDayOfWeek.layoutParams = lp
|
||||
|
||||
binding.root.setOnClickListener {
|
||||
onClickItem(dayOfWeek.dayOfWeek)
|
||||
selectedDayOfWeek = dayOfWeek.dayOfWeek
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var selectedDayOfWeek = SeriesPublishedDaysOfWeek.RANDOM
|
||||
|
||||
private val dayOfWeekItems = listOf(
|
||||
DayOfWeek(dayOfWeekStr = "월", dayOfWeek = SeriesPublishedDaysOfWeek.MON),
|
||||
DayOfWeek(dayOfWeekStr = "화", dayOfWeek = SeriesPublishedDaysOfWeek.TUE),
|
||||
DayOfWeek(dayOfWeekStr = "수", dayOfWeek = SeriesPublishedDaysOfWeek.WED),
|
||||
DayOfWeek(dayOfWeekStr = "목", dayOfWeek = SeriesPublishedDaysOfWeek.THU),
|
||||
DayOfWeek(dayOfWeekStr = "금", dayOfWeek = SeriesPublishedDaysOfWeek.FRI),
|
||||
DayOfWeek(dayOfWeekStr = "토", dayOfWeek = SeriesPublishedDaysOfWeek.SAT),
|
||||
DayOfWeek(dayOfWeekStr = "일", dayOfWeek = SeriesPublishedDaysOfWeek.SUN),
|
||||
DayOfWeek(dayOfWeekStr = "랜덤", dayOfWeek = SeriesPublishedDaysOfWeek.RANDOM),
|
||||
)
|
||||
|
||||
// 요일 숫자에 맞춰 배열
|
||||
private val dayOfWeeks = listOf(
|
||||
SeriesPublishedDaysOfWeek.RANDOM,
|
||||
SeriesPublishedDaysOfWeek.SUN,
|
||||
SeriesPublishedDaysOfWeek.MON,
|
||||
SeriesPublishedDaysOfWeek.TUE,
|
||||
SeriesPublishedDaysOfWeek.WED,
|
||||
SeriesPublishedDaysOfWeek.THU,
|
||||
SeriesPublishedDaysOfWeek.FRI,
|
||||
SeriesPublishedDaysOfWeek.SAT
|
||||
)
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = ViewHolder(
|
||||
ItemDayOfWeekBinding.inflate(
|
||||
LayoutInflater.from(parent.context),
|
||||
parent,
|
||||
false
|
||||
)
|
||||
)
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
holder.bind(dayOfWeekItems[position])
|
||||
}
|
||||
|
||||
override fun getItemCount() = dayOfWeekItems.count()
|
||||
|
||||
init {
|
||||
val calendar = Calendar.getInstance()
|
||||
val dayIndex = calendar.get(Calendar.DAY_OF_WEEK)
|
||||
selectedDayOfWeek = dayOfWeeks[dayIndex]
|
||||
}
|
||||
}
|
||||
@@ -69,8 +69,8 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>(FragmentHomeBinding::infl
|
||||
private lateinit var homeContentAdapter: HomeContentAdapter
|
||||
private lateinit var contentBannerAdapter: AudioContentMainBannerAdapter
|
||||
private lateinit var originalSeriesAdapter: HomeSeriesAdapter
|
||||
|
||||
private lateinit var auditionAdapter: AuditionBannerAdapter
|
||||
private lateinit var seriesDayOfWeekAdapter: HomeSeriesAdapter
|
||||
|
||||
private val handler = Handler(Looper.getMainLooper())
|
||||
|
||||
@@ -162,6 +162,7 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>(FragmentHomeBinding::infl
|
||||
setupContentBanner()
|
||||
setupOriginalSeries()
|
||||
setupAudition()
|
||||
setupSeriesDayOfWeek()
|
||||
}
|
||||
|
||||
private fun setupLiveView() {
|
||||
@@ -656,6 +657,117 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>(FragmentHomeBinding::infl
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupSeriesDayOfWeek() {
|
||||
val spSectionTitle = SpannableString(binding.tvSeriesDayOfWeek.text)
|
||||
spSectionTitle.setSpan(
|
||||
ForegroundColorSpan(
|
||||
ContextCompat.getColor(
|
||||
requireContext(),
|
||||
R.color.color_3bb9f1
|
||||
)
|
||||
),
|
||||
0,
|
||||
3,
|
||||
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
|
||||
)
|
||||
binding.tvSeriesDayOfWeek.text = spSectionTitle
|
||||
|
||||
seriesDayOfWeekAdapter = HomeSeriesAdapter {
|
||||
startActivity(
|
||||
Intent(requireContext(), SeriesDetailActivity::class.java).apply {
|
||||
putExtra(Constants.EXTRA_SERIES_ID, it)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
val recyclerView = binding.rvSeriesDayOfWeek
|
||||
recyclerView.layoutManager = LinearLayoutManager(
|
||||
context,
|
||||
LinearLayoutManager.HORIZONTAL,
|
||||
false
|
||||
)
|
||||
|
||||
recyclerView.addItemDecoration(object : RecyclerView.ItemDecoration() {
|
||||
override fun getItemOffsets(
|
||||
outRect: Rect,
|
||||
view: View,
|
||||
parent: RecyclerView,
|
||||
state: RecyclerView.State
|
||||
) {
|
||||
super.getItemOffsets(outRect, view, parent, state)
|
||||
|
||||
when (parent.getChildAdapterPosition(view)) {
|
||||
0 -> {
|
||||
outRect.left = 0
|
||||
outRect.right = 8f.dpToPx().toInt()
|
||||
}
|
||||
|
||||
seriesDayOfWeekAdapter.itemCount - 1 -> {
|
||||
outRect.left = 8f.dpToPx().toInt()
|
||||
outRect.right = 0
|
||||
}
|
||||
|
||||
else -> {
|
||||
outRect.left = 8f.dpToPx().toInt()
|
||||
outRect.right = 8f.dpToPx().toInt()
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
recyclerView.adapter = seriesDayOfWeekAdapter
|
||||
|
||||
viewModel.dayOfWeekSeriesListLiveData.observe(viewLifecycleOwner) {
|
||||
if (it.isNotEmpty()) {
|
||||
seriesDayOfWeekAdapter.clear()
|
||||
seriesDayOfWeekAdapter.addItems(it)
|
||||
}
|
||||
}
|
||||
|
||||
val dayOfWeekAdapter = DayOfWeekAdapter(screenWidth = screenWidth) {
|
||||
viewModel.getDayOfWeekSeriesList(it)
|
||||
}
|
||||
|
||||
val rvDayOfWeek = binding.rvSeriesDayOfWeekDay
|
||||
val layoutManager = object : LinearLayoutManager(
|
||||
context,
|
||||
HORIZONTAL,
|
||||
false
|
||||
) {
|
||||
override fun canScrollVertically() = false
|
||||
override fun canScrollHorizontally() = false
|
||||
}
|
||||
rvDayOfWeek.layoutManager = layoutManager
|
||||
|
||||
rvDayOfWeek.addItemDecoration(object : RecyclerView.ItemDecoration() {
|
||||
override fun getItemOffsets(
|
||||
outRect: Rect,
|
||||
view: View,
|
||||
parent: RecyclerView,
|
||||
state: RecyclerView.State
|
||||
) {
|
||||
super.getItemOffsets(outRect, view, parent, state)
|
||||
|
||||
when (parent.getChildAdapterPosition(view)) {
|
||||
0 -> {
|
||||
outRect.left = 0
|
||||
outRect.right = 2.5f.dpToPx().toInt()
|
||||
}
|
||||
|
||||
seriesDayOfWeekAdapter.itemCount - 1 -> {
|
||||
outRect.left = 2.5f.dpToPx().toInt()
|
||||
outRect.right = 0
|
||||
}
|
||||
|
||||
else -> {
|
||||
outRect.left = 2.5f.dpToPx().toInt()
|
||||
outRect.right = 2.5f.dpToPx().toInt()
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
rvDayOfWeek.adapter = dayOfWeekAdapter
|
||||
}
|
||||
|
||||
private fun bindData() {
|
||||
viewModel.isLoading.observe(viewLifecycleOwner) {
|
||||
if (it) {
|
||||
|
||||
@@ -83,7 +83,7 @@ class HomeSeriesAdapter(
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
fun isVisibleRecyclerView(): Boolean {
|
||||
return items.isNotEmpty()
|
||||
fun clear() {
|
||||
this.items.clear()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,6 +162,9 @@ class HomeViewModel(private val repository: HomeRepository) : BaseViewModel() {
|
||||
.subscribe(
|
||||
{
|
||||
_isLoading.value = false
|
||||
if (it.success && it.data != null) {
|
||||
_dayOfWeekSeriesListLiveData.value = it.data!!
|
||||
}
|
||||
},
|
||||
{
|
||||
_isLoading.value = false
|
||||
|
||||
12
app/src/main/res/drawable/bg_selectable_day_of_week.xml
Normal file
12
app/src/main/res/drawable/bg_selectable_day_of_week.xml
Normal file
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<!-- 선택된 경우: 4dp 테두리 -->
|
||||
<item android:state_selected="true" android:drawable="@drawable/gradient_overlay_day_of_week" />
|
||||
|
||||
<item>
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="#263238" />
|
||||
<corners android:radius="16dp" />
|
||||
</shape>
|
||||
</item>
|
||||
</selector>
|
||||
28
app/src/main/res/drawable/gradient_overlay_day_of_week.xml
Normal file
28
app/src/main/res/drawable/gradient_overlay_day_of_week.xml
Normal file
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<!-- 테두리 역할: Gradient 사각형 -->
|
||||
<item>
|
||||
<shape android:shape="rectangle">
|
||||
<gradient
|
||||
android:type="linear"
|
||||
android:angle="270"
|
||||
android:startColor="@color/color_80d8ff"
|
||||
android:endColor="#6D5ED7" />
|
||||
<corners android:radius="16dp" />
|
||||
</shape>
|
||||
</item>
|
||||
|
||||
<!-- 내용 배경: 내부에 살짝 inset된 검정 배경 -->
|
||||
<item
|
||||
android:left="4dp"
|
||||
android:top="4dp"
|
||||
android:right="4dp"
|
||||
android:bottom="4dp">
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="#263238" />
|
||||
<corners android:radius="12dp" />
|
||||
</shape>
|
||||
</item>
|
||||
|
||||
</layer-list>
|
||||
@@ -240,8 +240,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="48dp"
|
||||
android:orientation="vertical"
|
||||
android:visibility="gone">
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_series_day_of_week"
|
||||
@@ -257,6 +256,7 @@
|
||||
android:id="@+id/rv_series_day_of_week_day"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:nestedScrollingEnabled="false"
|
||||
android:layout_marginTop="16dp"
|
||||
android:clipToPadding="false"
|
||||
android:paddingHorizontal="24dp" />
|
||||
|
||||
19
app/src/main/res/layout/item_day_of_week.xml
Normal file
19
app/src/main/res/layout/item_day_of_week.xml
Normal file
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_day_of_week"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/bg_selectable_day_of_week"
|
||||
android:fontFamily="@font/pretendard_regular"
|
||||
android:gravity="center"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="18sp"
|
||||
tools:text="월" />
|
||||
</LinearLayout>
|
||||
Reference in New Issue
Block a user