재생목록 리스트 페이지

This commit is contained in:
klaus 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(

View File

@ -0,0 +1,97 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black"
android:padding="40dp">
<TextView
android:id="@+id/tv_create_playlist"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@drawable/bg_round_corner_5_3_3bb9f1"
android:fontFamily="@font/gmarket_sans_bold"
android:gravity="center"
android:paddingVertical="13.3dp"
android:text="+ 새 재생목록 만들기"
android:textColor="@color/white"
android:textSize="14.7sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:id="@+id/ll_total_count"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="13.3dp"
android:gravity="center_vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv_create_playlist">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/gmarket_sans_medium"
android:text="전체"
android:textColor="@color/white"
android:textSize="14.7sp" />
<TextView
android:id="@+id/tv_total_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5.3dp"
android:fontFamily="@font/gmarket_sans_medium"
android:textColor="@color/color_909090"
android:textSize="12sp"
tools:text="2개" />
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_playlist_list"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="13.3dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/ll_total_count" />
<LinearLayout
android:id="@+id/ll_no_playlist"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="13.3dp"
android:background="@drawable/bg_round_corner_4_7_13181b"
android:gravity="center"
android:orientation="vertical"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv_create_playlist">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/gmarket_sans_bold"
android:text="재생목록이 비어있습니다."
android:textColor="@color/color_eeeeee"
android:textSize="14.7sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="13.3dp"
android:fontFamily="@font/gmarket_sans_medium"
android:gravity="center"
android:text="자주 듣는 콘텐츠를\n재생목록으로 만들어 보세요."
android:textColor="@color/color_bbbbbb"
android:textSize="11sp" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,67 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/black">
<ImageView
android:id="@+id/iv_cover"
android:layout_width="66.7dp"
android:layout_height="66.7dp"
android:layout_centerVertical="true"
android:contentDescription="@null" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginStart="11dp"
android:layout_toEndOf="@+id/iv_cover"
android:gravity="center_vertical"
android:orientation="vertical">
<TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:fontFamily="@font/gmarket_sans_bold"
android:maxLines="1"
android:textColor="@color/color_d2d2d2"
android:textSize="14.7sp"
tools:text="재생목록 제목" />
<TextView
android:id="@+id/tv_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="7dp"
android:ellipsize="end"
android:fontFamily="@font/gmarket_sans_medium"
android:maxLines="1"
android:textColor="@color/color_909090"
android:textSize="12sp"
tools:text="재생목록 설명(없으면 미노출)" />
<TextView
android:id="@+id/tv_content_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="7dp"
android:ellipsize="end"
android:fontFamily="@font/gmarket_sans_medium"
android:maxLines="1"
android:textColor="@color/color_909090"
android:textSize="12sp"
tools:text="총 5개" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="@+id/iv_cover"
android:layout_marginTop="8dp"
android:background="@color/color_555555" />
</RelativeLayout>