인기 콘텐츠 전체 보기 - 정렬 추가
This commit is contained in:
parent
63483a2099
commit
81bdd52edd
|
@ -170,6 +170,11 @@ interface AudioContentApi {
|
|||
@Header("Authorization") authHeader: String
|
||||
): Single<ApiResponse<List<String>>>
|
||||
|
||||
@GET("/audio-content/ranking-sort-type")
|
||||
fun getContentRankingSortType(
|
||||
@Header("Authorization") authHeader: String
|
||||
): Single<ApiResponse<List<String>>>
|
||||
|
||||
@GET("/audio-content/ranking")
|
||||
fun getContentRanking(
|
||||
@Query("page") page: Int,
|
||||
|
|
|
@ -164,6 +164,8 @@ class AudioContentRepository(
|
|||
authHeader = token
|
||||
)
|
||||
|
||||
fun getContentRankingSortType(token: String) = api.getContentRankingSortType(authHeader = token)
|
||||
|
||||
fun getContentRanking(
|
||||
page: Int,
|
||||
size: Int,
|
||||
|
|
|
@ -9,6 +9,7 @@ import android.widget.Toast
|
|||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import kr.co.vividnext.sodalive.audio_content.detail.AudioContentDetailActivity
|
||||
import kr.co.vividnext.sodalive.audio_content.main.AudioContentMainNewContentThemeAdapter
|
||||
import kr.co.vividnext.sodalive.base.BaseActivity
|
||||
import kr.co.vividnext.sodalive.common.Constants
|
||||
import kr.co.vividnext.sodalive.common.LoadingDialog
|
||||
|
@ -23,11 +24,13 @@ class AudioContentRankingAllActivity : BaseActivity<ActivityAudioContentRankingA
|
|||
|
||||
private lateinit var loadingDialog: LoadingDialog
|
||||
private lateinit var adapter: AudioContentRankingAllAdapter
|
||||
private lateinit var sortAdapter: AudioContentMainNewContentThemeAdapter
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
bindData()
|
||||
viewModel.getAudioContentRankingSortType()
|
||||
viewModel.getAudioContentRanking()
|
||||
}
|
||||
|
||||
|
@ -99,6 +102,53 @@ class AudioContentRankingAllActivity : BaseActivity<ActivityAudioContentRankingA
|
|||
})
|
||||
|
||||
binding.rvContentRanking.adapter = adapter
|
||||
|
||||
setupContentRankingSortType()
|
||||
}
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
private fun setupContentRankingSortType() {
|
||||
sortAdapter = AudioContentMainNewContentThemeAdapter {
|
||||
adapter.items.clear()
|
||||
adapter.notifyDataSetChanged()
|
||||
viewModel.selectSort(sort = it)
|
||||
}
|
||||
|
||||
binding.rvContentRankingSort.layoutManager = LinearLayoutManager(
|
||||
this,
|
||||
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()
|
||||
}
|
||||
|
||||
sortAdapter.itemCount - 1 -> {
|
||||
outRect.left = 4f.dpToPx().toInt()
|
||||
outRect.right = 0
|
||||
}
|
||||
|
||||
else -> {
|
||||
outRect.left = 4f.dpToPx().toInt()
|
||||
outRect.right = 4f.dpToPx().toInt()
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
binding.rvContentRankingSort.adapter = sortAdapter
|
||||
}
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
|
@ -120,12 +170,16 @@ class AudioContentRankingAllActivity : BaseActivity<ActivityAudioContentRankingA
|
|||
}
|
||||
|
||||
viewModel.contentRankingItemsLiveData.observe(this) {
|
||||
if (viewModel.page == 0) {
|
||||
if (viewModel.page == 2) {
|
||||
adapter.items.clear()
|
||||
}
|
||||
|
||||
adapter.items.addAll(it)
|
||||
adapter.notifyDataSetChanged()
|
||||
}
|
||||
|
||||
viewModel.contentRankingSortListLiveData.observe(this) {
|
||||
sortAdapter.addItems(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,10 @@ class AudioContentRankingAllViewModel(
|
|||
val dateStringLiveData: LiveData<String>
|
||||
get() = _dateStringLiveData
|
||||
|
||||
private var _contentRankingSortListLiveData = MutableLiveData<List<String>>()
|
||||
val contentRankingSortListLiveData: LiveData<List<String>>
|
||||
get() = _contentRankingSortListLiveData
|
||||
|
||||
private var _contentRankingItemsLiveData = MutableLiveData<List<GetAudioContentRankingItem>>()
|
||||
val contentRankingItemsLiveData: LiveData<List<GetAudioContentRankingItem>>
|
||||
get() = _contentRankingItemsLiveData
|
||||
|
@ -33,6 +37,8 @@ class AudioContentRankingAllViewModel(
|
|||
private var pageSize = 10
|
||||
private var isLast = false
|
||||
|
||||
private var selectedSort = "매출"
|
||||
|
||||
fun getAudioContentRanking() {
|
||||
if (!_isLoading.value!! && !isLast && page <= 5) {
|
||||
_isLoading.value = true
|
||||
|
@ -40,6 +46,7 @@ class AudioContentRankingAllViewModel(
|
|||
repository.getContentRanking(
|
||||
page = page,
|
||||
size = pageSize,
|
||||
sortType = selectedSort,
|
||||
token = "Bearer ${SharedPreferenceManager.token}"
|
||||
)
|
||||
.subscribeOn(Schedulers.io())
|
||||
|
@ -56,7 +63,6 @@ class AudioContentRankingAllViewModel(
|
|||
_contentRankingItemsLiveData.value = it.data.items
|
||||
} else {
|
||||
isLast = true
|
||||
_contentRankingItemsLiveData.value = listOf()
|
||||
}
|
||||
} else {
|
||||
_isLoading.value = false
|
||||
|
@ -77,4 +83,38 @@ class AudioContentRankingAllViewModel(
|
|||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun getAudioContentRankingSortType() {
|
||||
compositeDisposable.add(
|
||||
repository.getContentRankingSortType(token = "Bearer ${SharedPreferenceManager.token}")
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(
|
||||
{
|
||||
if (it.success && it.data != null) {
|
||||
_contentRankingSortListLiveData.value = it.data!!
|
||||
} else {
|
||||
if (it.message != null) {
|
||||
_toastLiveData.postValue(it.message)
|
||||
} else {
|
||||
_toastLiveData.postValue(
|
||||
"알 수 없는 오류가 발생했습니다. 다시 시도해 주세요."
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
it.message?.let { message -> Logger.e(message) }
|
||||
_toastLiveData.postValue("알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.")
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
fun selectSort(sort: String) {
|
||||
page = 1
|
||||
isLast = false
|
||||
selectedSort = sort
|
||||
getAudioContentRanking()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -395,7 +395,7 @@ class AudioContentMainFragment : BaseFragment<FragmentAudioContentMainBinding>(
|
|||
outRect.right = 4f.dpToPx().toInt()
|
||||
}
|
||||
|
||||
newContentThemeAdapter.itemCount - 1 -> {
|
||||
contentRankingSortAdapter.itemCount - 1 -> {
|
||||
outRect.left = 4f.dpToPx().toInt()
|
||||
outRect.right = 0
|
||||
}
|
||||
|
|
|
@ -36,11 +36,19 @@
|
|||
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"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="13.3dp"
|
||||
android:clipToPadding="false"
|
||||
android:paddingHorizontal="6.7dp"
|
||||
android:paddingVertical="13.3dp" />
|
||||
android:paddingHorizontal="6.7dp" />
|
||||
</LinearLayout>
|
||||
|
|
Loading…
Reference in New Issue