재생목록 리스트 페이지

This commit is contained in:
2024-11-28 17:58:10 +09:00
parent cf4854c78d
commit f72f894727
9 changed files with 395 additions and 0 deletions

View File

@@ -0,0 +1,58 @@
package kr.co.vividnext.sodalive.audio_content.playlist
import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import coil.load
import coil.transform.RoundedCornersTransformation
import kr.co.vividnext.sodalive.R
import kr.co.vividnext.sodalive.databinding.ItemPlaylistListBinding
import kr.co.vividnext.sodalive.extensions.dpToPx
class AudioContentPlaylistListAdapter(
private val onClickItem: (Long) -> Unit
) : RecyclerView.Adapter<AudioContentPlaylistListAdapter.ViewHolder>() {
val items = mutableListOf<GetPlaylistsItem>()
inner class ViewHolder(
private val binding: ItemPlaylistListBinding
) : RecyclerView.ViewHolder(binding.root) {
@SuppressLint("SetTextI18n")
fun bind(item: GetPlaylistsItem) {
binding.ivCover.load(item.coverImageUrl) {
crossfade(true)
placeholder(R.drawable.bg_placeholder)
transformations(RoundedCornersTransformation(5.3f.dpToPx()))
}
binding.tvTitle.text = item.title
binding.tvContentCount.text = "${item.contentCount}"
if (item.desc.isNotBlank()) {
binding.tvDesc.text = item.desc
binding.tvDesc.visibility = View.VISIBLE
} else {
binding.tvDesc.visibility = View.GONE
}
binding.root.setOnClickListener { onClickItem(item.id) }
}
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = ViewHolder(
ItemPlaylistListBinding.inflate(
LayoutInflater.from(parent.context),
parent,
false
)
)
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.bind(items[position])
}
override fun getItemCount() = items.count()
}

View File

@@ -0,0 +1,76 @@
package kr.co.vividnext.sodalive.audio_content.playlist
import android.annotation.SuppressLint
import android.os.Bundle
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import kr.co.vividnext.sodalive.base.BaseFragment
import kr.co.vividnext.sodalive.common.LoadingDialog
import kr.co.vividnext.sodalive.databinding.FragmentAudioContentPlaylistListBinding
import org.koin.android.ext.android.inject
class AudioContentPlaylistListFragment : BaseFragment<FragmentAudioContentPlaylistListBinding>(
FragmentAudioContentPlaylistListBinding::inflate
) {
private val viewModel: AudioContentPlaylistListViewModel by inject()
private lateinit var loadingDialog: LoadingDialog
private lateinit var adapter: AudioContentPlaylistListAdapter
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
setupView()
bindData()
viewModel.getPlaylistList()
}
private fun setupView() {
loadingDialog = LoadingDialog(requireActivity(), layoutInflater)
adapter = AudioContentPlaylistListAdapter { }
val recyclerView = binding.rvPlaylistList
recyclerView.setHasFixedSize(true)
recyclerView.layoutManager = LinearLayoutManager(
activity,
LinearLayoutManager.VERTICAL,
false
)
recyclerView.adapter = adapter
}
@SuppressLint("SetTextI18n")
private fun bindData() {
viewModel.isLoading.observe(viewLifecycleOwner) {
if (it) {
loadingDialog.show(screenWidth)
} else {
loadingDialog.dismiss()
}
}
viewModel.toastLiveData.observe(viewLifecycleOwner) {
it?.let { showToast(it) }
}
viewModel.totalCountLiveData.observe(viewLifecycleOwner) {
binding.tvCreatePlaylist.text = "${it}"
}
viewModel.playlistLiveData.observe(viewLifecycleOwner) {
if (it.isEmpty()) {
binding.tvTotalCount.visibility = View.GONE
binding.rvPlaylistList.visibility = View.GONE
binding.llNoPlaylist.visibility = View.VISIBLE
} else {
binding.llNoPlaylist.visibility = View.GONE
binding.tvTotalCount.visibility = View.VISIBLE
binding.rvPlaylistList.visibility = View.VISIBLE
adapter.items.addAll(it)
}
}
}
}

View File

@@ -0,0 +1,5 @@
package kr.co.vividnext.sodalive.audio_content.playlist
class AudioContentPlaylistListRepository(private val api: PlaylistApi) {
fun getPlaylistList(token: String) = api.getPlaylistList(authHeader = token)
}

View File

@@ -0,0 +1,57 @@
package kr.co.vividnext.sodalive.audio_content.playlist
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.orhanobut.logger.Logger
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import io.reactivex.rxjava3.schedulers.Schedulers
import kr.co.vividnext.sodalive.base.BaseViewModel
import kr.co.vividnext.sodalive.common.SharedPreferenceManager
class AudioContentPlaylistListViewModel(
private val repository: AudioContentPlaylistListRepository
) : BaseViewModel() {
private val _toastLiveData = MutableLiveData<String?>()
val toastLiveData: LiveData<String?>
get() = _toastLiveData
private var _isLoading = MutableLiveData(false)
val isLoading: LiveData<Boolean>
get() = _isLoading
private val _totalCountLiveData = MutableLiveData<Int>()
val totalCountLiveData: LiveData<Int>
get() = _totalCountLiveData
private val _playlistLiveData = MutableLiveData<List<GetPlaylistsItem>>()
val playlistLiveData: LiveData<List<GetPlaylistsItem>>
get() = _playlistLiveData
fun getPlaylistList() {
compositeDisposable.add(
repository.getPlaylistList(token = "Bearer ${SharedPreferenceManager.token}")
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
{
if (it.success && it.data != null) {
_totalCountLiveData.value = it.data.totalCount
_playlistLiveData.value = it.data.items
} else {
if (it.message != null) {
_toastLiveData.postValue(it.message)
} else {
_toastLiveData.postValue(
"알 수 없는 오류가 발생했습니다. 다시 시도해 주세요."
)
}
}
},
{
it.message?.let { message -> Logger.e(message) }
_toastLiveData.postValue("알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.")
}
)
)
}
}

View File

@@ -0,0 +1,16 @@
package kr.co.vividnext.sodalive.audio_content.playlist
import com.google.gson.annotations.SerializedName
data class GetPlaylistsResponse(
@SerializedName("totalCount") val totalCount: Int,
@SerializedName("items") val items: List<GetPlaylistsItem>
)
data class GetPlaylistsItem(
@SerializedName("id") val id: Long,
@SerializedName("title") val title: String,
@SerializedName("desc") val desc: String,
@SerializedName("contentCount") val contentCount: Int,
@SerializedName("coverImageUrl") val coverImageUrl: String
)

View File

@@ -0,0 +1,13 @@
package kr.co.vividnext.sodalive.audio_content.playlist
import io.reactivex.rxjava3.core.Single
import kr.co.vividnext.sodalive.common.ApiResponse
import retrofit2.http.GET
import retrofit2.http.Header
interface PlaylistApi {
@GET("/audio-content/playlist")
fun getPlaylistList(
@Header("Authorization") authHeader: String
): Single<ApiResponse<GetPlaylistsResponse>>
}

View File

@@ -24,6 +24,9 @@ import kr.co.vividnext.sodalive.audio_content.main.ranking.AudioContentMainRanki
import kr.co.vividnext.sodalive.audio_content.main.recommend_series.AudioContentMainRecommendSeriesViewModel
import kr.co.vividnext.sodalive.audio_content.modify.AudioContentModifyViewModel
import kr.co.vividnext.sodalive.audio_content.order.AudioContentOrderListViewModel
import kr.co.vividnext.sodalive.audio_content.playlist.AudioContentPlaylistListRepository
import kr.co.vividnext.sodalive.audio_content.playlist.AudioContentPlaylistListViewModel
import kr.co.vividnext.sodalive.audio_content.playlist.PlaylistApi
import kr.co.vividnext.sodalive.audio_content.series.SeriesApi
import kr.co.vividnext.sodalive.audio_content.series.SeriesListAllViewModel
import kr.co.vividnext.sodalive.audio_content.series.SeriesRepository
@@ -191,6 +194,7 @@ class AppDI(private val context: Context, isDebugMode: Boolean) {
single { ApiBuilder().build(get(), RouletteApi::class.java) }
single { ApiBuilder().build(get(), CreatorCommunityApi::class.java) }
single { ApiBuilder().build(get(), CategoryApi::class.java) }
single { ApiBuilder().build(get(), PlaylistApi::class.java) }
}
private val viewModelModule = module {
@@ -265,6 +269,7 @@ class AppDI(private val context: Context, isDebugMode: Boolean) {
viewModel { BlockMemberViewModel(get()) }
viewModel { UserViewModel(get(), get()) }
viewModel { MenuConfigViewModel(get()) }
viewModel { AudioContentPlaylistListViewModel(get()) }
}
private val repositoryModule = module {
@@ -293,6 +298,7 @@ class AppDI(private val context: Context, isDebugMode: Boolean) {
factory { CreatorCommunityRepository(get()) }
factory { AlarmListRepository(get()) }
factory { MenuConfigRepository(get()) }
factory { AudioContentPlaylistListRepository(get()) }
}
private val moduleList = listOf(