콘텐츠 메인 - 인기 콘텐츠 정렬 추가
This commit is contained in:
parent
b68b4eb8da
commit
63483a2099
|
@ -174,6 +174,7 @@ interface AudioContentApi {
|
|||
fun getContentRanking(
|
||||
@Query("page") page: Int,
|
||||
@Query("size") size: Int,
|
||||
@Query("sort-type") sortType: String,
|
||||
@Header("Authorization") authHeader: String
|
||||
): Single<ApiResponse<GetAudioContentRanking>>
|
||||
}
|
||||
|
|
|
@ -167,10 +167,12 @@ class AudioContentRepository(
|
|||
fun getContentRanking(
|
||||
page: Int,
|
||||
size: Int,
|
||||
sortType: String = "매출",
|
||||
token: String
|
||||
) = api.getContentRanking(
|
||||
page = page - 1,
|
||||
size = size,
|
||||
sortType = sortType,
|
||||
authHeader = token
|
||||
)
|
||||
}
|
||||
|
|
|
@ -50,6 +50,7 @@ class AudioContentMainFragment : BaseFragment<FragmentAudioContentMainBinding>(
|
|||
private lateinit var orderListAdapter: AudioContentMainContentAdapter
|
||||
private lateinit var newContentThemeAdapter: AudioContentMainNewContentThemeAdapter
|
||||
private lateinit var newContentAdapter: AudioContentMainContentAdapter
|
||||
private lateinit var contentRankingSortAdapter: AudioContentMainNewContentThemeAdapter
|
||||
private lateinit var contentRankingAdapter: AudioContentMainRankingAdapter
|
||||
private lateinit var curationAdapter: AudioContentMainCurationAdapter
|
||||
|
||||
|
@ -87,6 +88,7 @@ class AudioContentMainFragment : BaseFragment<FragmentAudioContentMainBinding>(
|
|||
setupOrderList()
|
||||
setupNewContentTheme()
|
||||
setupNewContent()
|
||||
setupContentRankingSortType()
|
||||
setupContentRanking()
|
||||
setupCuration()
|
||||
|
||||
|
@ -367,6 +369,48 @@ class AudioContentMainFragment : BaseFragment<FragmentAudioContentMainBinding>(
|
|||
binding.rvNewContent.adapter = newContentAdapter
|
||||
}
|
||||
|
||||
private fun setupContentRankingSortType() {
|
||||
contentRankingSortAdapter = AudioContentMainNewContentThemeAdapter {
|
||||
viewModel.getContentRanking(sort = it)
|
||||
}
|
||||
|
||||
binding.rvContentRankingSort.layoutManager = LinearLayoutManager(
|
||||
context,
|
||||
LinearLayoutManager.HORIZONTAL,
|
||||
false
|
||||
)
|
||||
|
||||
binding.rvContentRankingSort.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 = 4f.dpToPx().toInt()
|
||||
}
|
||||
|
||||
newContentThemeAdapter.itemCount - 1 -> {
|
||||
outRect.left = 4f.dpToPx().toInt()
|
||||
outRect.right = 0
|
||||
}
|
||||
|
||||
else -> {
|
||||
outRect.left = 4f.dpToPx().toInt()
|
||||
outRect.right = 4f.dpToPx().toInt()
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
binding.rvContentRankingSort.adapter = contentRankingSortAdapter
|
||||
}
|
||||
|
||||
private fun setupContentRanking() {
|
||||
binding.ivContentRankingAll.setOnClickListener {
|
||||
startActivity(Intent(requireContext(), AudioContentRankingAllActivity::class.java))
|
||||
|
@ -537,6 +581,11 @@ class AudioContentMainFragment : BaseFragment<FragmentAudioContentMainBinding>(
|
|||
}
|
||||
}
|
||||
|
||||
viewModel.contentRankingSortListLiveData.observe(viewLifecycleOwner) {
|
||||
binding.llContentRanking.visibility = View.VISIBLE
|
||||
contentRankingSortAdapter.addItems(it)
|
||||
}
|
||||
|
||||
viewModel.contentRankingLiveData.observe(viewLifecycleOwner) {
|
||||
binding.llContentRanking.visibility = View.VISIBLE
|
||||
binding.tvDate.text = "${it.startDate}~${it.endDate}"
|
||||
|
|
|
@ -22,7 +22,11 @@ class AudioContentMainNewContentThemeAdapter(
|
|||
) : RecyclerView.ViewHolder(binding.root) {
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
fun bind(theme: String) {
|
||||
if (theme == selectedTheme || (selectedTheme == "" && theme == "전체")) {
|
||||
if (
|
||||
theme == selectedTheme ||
|
||||
(selectedTheme == "" && theme == "전체") ||
|
||||
(selectedTheme == "" && theme == "매출")
|
||||
) {
|
||||
binding.tvTheme.setBackgroundResource(
|
||||
R.drawable.bg_round_corner_16_7_transparent_9970ff
|
||||
)
|
||||
|
|
|
@ -45,6 +45,10 @@ class AudioContentMainViewModel(
|
|||
val curationListLiveData: LiveData<List<GetAudioContentCurationResponse>>
|
||||
get() = _curationListLiveData
|
||||
|
||||
private var _contentRankingSortListLiveData = MutableLiveData<List<String>>()
|
||||
val contentRankingSortListLiveData: LiveData<List<String>>
|
||||
get() = _contentRankingSortListLiveData
|
||||
|
||||
private var _contentRankingLiveData = MutableLiveData<GetAudioContentRanking>()
|
||||
val contentRankingLiveData: LiveData<GetAudioContentRanking>
|
||||
get() = _contentRankingLiveData
|
||||
|
@ -66,6 +70,7 @@ class AudioContentMainViewModel(
|
|||
_bannerLiveData.value = data.bannerList
|
||||
_curationListLiveData.value = data.curationList
|
||||
_contentRankingLiveData.value = data.contentRanking
|
||||
_contentRankingSortListLiveData.value = data.contentRankingSortTypeList
|
||||
|
||||
val themeList = listOf("전체").union(data.themeList).toList()
|
||||
_themeListLiveData.value = themeList
|
||||
|
@ -123,4 +128,39 @@ class AudioContentMainViewModel(
|
|||
)
|
||||
)
|
||||
}
|
||||
|
||||
fun getContentRanking(sort: String) {
|
||||
_isLoading.value = true
|
||||
compositeDisposable.add(
|
||||
repository.getContentRanking(
|
||||
page = 0,
|
||||
size = 12,
|
||||
sortType = sort,
|
||||
token = "Bearer ${SharedPreferenceManager.token}"
|
||||
)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(
|
||||
{
|
||||
if (it.success && it.data != null) {
|
||||
_isLoading.value = false
|
||||
_contentRankingLiveData.value = it.data!!
|
||||
} else {
|
||||
_isLoading.value = false
|
||||
if (it.message != null) {
|
||||
_toastLiveData.postValue(it.message)
|
||||
} else {
|
||||
_toastLiveData.postValue(
|
||||
"알 수 없는 오류가 발생했습니다. 다시 시도해 주세요."
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
it.message?.let { message -> Logger.e(message) }
|
||||
_toastLiveData.postValue("알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.")
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ data class GetAudioContentMainResponse(
|
|||
@SerializedName("themeList") val themeList: List<String>,
|
||||
@SerializedName("newContentList") val newContentList: List<GetAudioContentMainItem>,
|
||||
@SerializedName("curationList") val curationList: List<GetAudioContentCurationResponse>,
|
||||
@SerializedName("contentRankingSortTypeList") val contentRankingSortTypeList: List<String>,
|
||||
@SerializedName("contentRanking") val contentRanking: GetAudioContentRanking
|
||||
)
|
||||
|
||||
|
|
|
@ -216,6 +216,14 @@
|
|||
android:textSize="13.3sp" />
|
||||
</LinearLayout>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/rv_content_ranking_sort"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="13.3dp"
|
||||
android:clipToPadding="false"
|
||||
android:paddingHorizontal="13.3dp" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/rv_content_ranking"
|
||||
android:layout_width="match_parent"
|
||||
|
|
Loading…
Reference in New Issue