인기 콘텐츠 전체 보기 - 정렬 추가
This commit is contained in:
		@@ -170,6 +170,11 @@ interface AudioContentApi {
 | 
				
			|||||||
        @Header("Authorization") authHeader: String
 | 
					        @Header("Authorization") authHeader: String
 | 
				
			||||||
    ): Single<ApiResponse<List<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")
 | 
					    @GET("/audio-content/ranking")
 | 
				
			||||||
    fun getContentRanking(
 | 
					    fun getContentRanking(
 | 
				
			||||||
        @Query("page") page: Int,
 | 
					        @Query("page") page: Int,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -164,6 +164,8 @@ class AudioContentRepository(
 | 
				
			|||||||
        authHeader = token
 | 
					        authHeader = token
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    fun getContentRankingSortType(token: String) = api.getContentRankingSortType(authHeader = token)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    fun getContentRanking(
 | 
					    fun getContentRanking(
 | 
				
			||||||
        page: Int,
 | 
					        page: Int,
 | 
				
			||||||
        size: Int,
 | 
					        size: Int,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -9,6 +9,7 @@ import android.widget.Toast
 | 
				
			|||||||
import androidx.recyclerview.widget.LinearLayoutManager
 | 
					import androidx.recyclerview.widget.LinearLayoutManager
 | 
				
			||||||
import androidx.recyclerview.widget.RecyclerView
 | 
					import androidx.recyclerview.widget.RecyclerView
 | 
				
			||||||
import kr.co.vividnext.sodalive.audio_content.detail.AudioContentDetailActivity
 | 
					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.base.BaseActivity
 | 
				
			||||||
import kr.co.vividnext.sodalive.common.Constants
 | 
					import kr.co.vividnext.sodalive.common.Constants
 | 
				
			||||||
import kr.co.vividnext.sodalive.common.LoadingDialog
 | 
					import kr.co.vividnext.sodalive.common.LoadingDialog
 | 
				
			||||||
@@ -23,11 +24,13 @@ class AudioContentRankingAllActivity : BaseActivity<ActivityAudioContentRankingA
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    private lateinit var loadingDialog: LoadingDialog
 | 
					    private lateinit var loadingDialog: LoadingDialog
 | 
				
			||||||
    private lateinit var adapter: AudioContentRankingAllAdapter
 | 
					    private lateinit var adapter: AudioContentRankingAllAdapter
 | 
				
			||||||
 | 
					    private lateinit var sortAdapter: AudioContentMainNewContentThemeAdapter
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    override fun onCreate(savedInstanceState: Bundle?) {
 | 
					    override fun onCreate(savedInstanceState: Bundle?) {
 | 
				
			||||||
        super.onCreate(savedInstanceState)
 | 
					        super.onCreate(savedInstanceState)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        bindData()
 | 
					        bindData()
 | 
				
			||||||
 | 
					        viewModel.getAudioContentRankingSortType()
 | 
				
			||||||
        viewModel.getAudioContentRanking()
 | 
					        viewModel.getAudioContentRanking()
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -99,6 +102,53 @@ class AudioContentRankingAllActivity : BaseActivity<ActivityAudioContentRankingA
 | 
				
			|||||||
        })
 | 
					        })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        binding.rvContentRanking.adapter = adapter
 | 
					        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")
 | 
					    @SuppressLint("NotifyDataSetChanged")
 | 
				
			||||||
@@ -120,12 +170,16 @@ class AudioContentRankingAllActivity : BaseActivity<ActivityAudioContentRankingA
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        viewModel.contentRankingItemsLiveData.observe(this) {
 | 
					        viewModel.contentRankingItemsLiveData.observe(this) {
 | 
				
			||||||
            if (viewModel.page == 0) {
 | 
					            if (viewModel.page == 2) {
 | 
				
			||||||
                adapter.items.clear()
 | 
					                adapter.items.clear()
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            adapter.items.addAll(it)
 | 
					            adapter.items.addAll(it)
 | 
				
			||||||
            adapter.notifyDataSetChanged()
 | 
					            adapter.notifyDataSetChanged()
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        viewModel.contentRankingSortListLiveData.observe(this) {
 | 
				
			||||||
 | 
					            sortAdapter.addItems(it)
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -25,6 +25,10 @@ class AudioContentRankingAllViewModel(
 | 
				
			|||||||
    val dateStringLiveData: LiveData<String>
 | 
					    val dateStringLiveData: LiveData<String>
 | 
				
			||||||
        get() = _dateStringLiveData
 | 
					        get() = _dateStringLiveData
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private var _contentRankingSortListLiveData = MutableLiveData<List<String>>()
 | 
				
			||||||
 | 
					    val contentRankingSortListLiveData: LiveData<List<String>>
 | 
				
			||||||
 | 
					        get() = _contentRankingSortListLiveData
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private var _contentRankingItemsLiveData = MutableLiveData<List<GetAudioContentRankingItem>>()
 | 
					    private var _contentRankingItemsLiveData = MutableLiveData<List<GetAudioContentRankingItem>>()
 | 
				
			||||||
    val contentRankingItemsLiveData: LiveData<List<GetAudioContentRankingItem>>
 | 
					    val contentRankingItemsLiveData: LiveData<List<GetAudioContentRankingItem>>
 | 
				
			||||||
        get() = _contentRankingItemsLiveData
 | 
					        get() = _contentRankingItemsLiveData
 | 
				
			||||||
@@ -33,6 +37,8 @@ class AudioContentRankingAllViewModel(
 | 
				
			|||||||
    private var pageSize = 10
 | 
					    private var pageSize = 10
 | 
				
			||||||
    private var isLast = false
 | 
					    private var isLast = false
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private var selectedSort = "매출"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    fun getAudioContentRanking() {
 | 
					    fun getAudioContentRanking() {
 | 
				
			||||||
        if (!_isLoading.value!! && !isLast && page <= 5) {
 | 
					        if (!_isLoading.value!! && !isLast && page <= 5) {
 | 
				
			||||||
            _isLoading.value = true
 | 
					            _isLoading.value = true
 | 
				
			||||||
@@ -40,6 +46,7 @@ class AudioContentRankingAllViewModel(
 | 
				
			|||||||
                repository.getContentRanking(
 | 
					                repository.getContentRanking(
 | 
				
			||||||
                    page = page,
 | 
					                    page = page,
 | 
				
			||||||
                    size = pageSize,
 | 
					                    size = pageSize,
 | 
				
			||||||
 | 
					                    sortType = selectedSort,
 | 
				
			||||||
                    token = "Bearer ${SharedPreferenceManager.token}"
 | 
					                    token = "Bearer ${SharedPreferenceManager.token}"
 | 
				
			||||||
                )
 | 
					                )
 | 
				
			||||||
                    .subscribeOn(Schedulers.io())
 | 
					                    .subscribeOn(Schedulers.io())
 | 
				
			||||||
@@ -56,7 +63,6 @@ class AudioContentRankingAllViewModel(
 | 
				
			|||||||
                                    _contentRankingItemsLiveData.value = it.data.items
 | 
					                                    _contentRankingItemsLiveData.value = it.data.items
 | 
				
			||||||
                                } else {
 | 
					                                } else {
 | 
				
			||||||
                                    isLast = true
 | 
					                                    isLast = true
 | 
				
			||||||
                                    _contentRankingItemsLiveData.value = listOf()
 | 
					 | 
				
			||||||
                                }
 | 
					                                }
 | 
				
			||||||
                            } else {
 | 
					                            } else {
 | 
				
			||||||
                                _isLoading.value = false
 | 
					                                _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()
 | 
					                        outRect.right = 4f.dpToPx().toInt()
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    newContentThemeAdapter.itemCount - 1 -> {
 | 
					                    contentRankingSortAdapter.itemCount - 1 -> {
 | 
				
			||||||
                        outRect.left = 4f.dpToPx().toInt()
 | 
					                        outRect.left = 4f.dpToPx().toInt()
 | 
				
			||||||
                        outRect.right = 0
 | 
					                        outRect.right = 0
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -36,11 +36,19 @@
 | 
				
			|||||||
            android:textSize="13.3sp" />
 | 
					            android:textSize="13.3sp" />
 | 
				
			||||||
    </LinearLayout>
 | 
					    </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
 | 
					    <androidx.recyclerview.widget.RecyclerView
 | 
				
			||||||
        android:id="@+id/rv_content_ranking"
 | 
					        android:id="@+id/rv_content_ranking"
 | 
				
			||||||
        android:layout_width="match_parent"
 | 
					        android:layout_width="match_parent"
 | 
				
			||||||
        android:layout_height="wrap_content"
 | 
					        android:layout_height="wrap_content"
 | 
				
			||||||
 | 
					        android:layout_marginTop="13.3dp"
 | 
				
			||||||
        android:clipToPadding="false"
 | 
					        android:clipToPadding="false"
 | 
				
			||||||
        android:paddingHorizontal="6.7dp"
 | 
					        android:paddingHorizontal="6.7dp" />
 | 
				
			||||||
        android:paddingVertical="13.3dp" />
 | 
					 | 
				
			||||||
</LinearLayout>
 | 
					</LinearLayout>
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user