147 lines
5.0 KiB
Kotlin
147 lines
5.0 KiB
Kotlin
package relax.offline.music.activity
|
|
|
|
import android.view.View
|
|
import com.bumptech.glide.Glide
|
|
import com.gyf.immersionbar.ktx.immersionBar
|
|
import relax.offline.music.databinding.ActivitySingerDetailsBinding
|
|
import relax.offline.music.innertube.Innertube
|
|
import relax.offline.music.innertube.requests.moSingerListPage
|
|
import relax.offline.music.util.LogTag.LogD
|
|
import relax.offline.music.view.SingerDetailsOtherView
|
|
import relax.offline.music.view.SingerDetailsSongView
|
|
import kotlinx.coroutines.channels.Channel
|
|
import kotlinx.coroutines.isActive
|
|
import kotlinx.coroutines.selects.select
|
|
|
|
class MoSingerDetailsActivity : MoBaseActivity() {
|
|
private val requests: Channel<Request> = Channel(Channel.UNLIMITED)
|
|
|
|
enum class Request {
|
|
TryAgain,
|
|
}
|
|
|
|
companion object {
|
|
const val SINGER_DETAILS_PAGE_BROWSE_ID = "singer_details_page_browse_id"
|
|
}
|
|
|
|
private lateinit var binding: ActivitySingerDetailsBinding
|
|
private var browseId: String? = null
|
|
|
|
override suspend fun main() {
|
|
binding = ActivitySingerDetailsBinding.inflate(layoutInflater)
|
|
setContentView(binding.root)
|
|
initImmersionBar()
|
|
browseId = intent.getStringExtra(SINGER_DETAILS_PAGE_BROWSE_ID)
|
|
if (browseId.isNullOrEmpty() || browseId == "null") {
|
|
finish()
|
|
return
|
|
}
|
|
initView()
|
|
LogD(TAG, "browseId->${browseId}")
|
|
initData(browseId!!)
|
|
onReceive()
|
|
}
|
|
|
|
private fun initImmersionBar() {
|
|
immersionBar {
|
|
statusBarDarkFont(false)
|
|
statusBarView(binding.view)
|
|
}
|
|
}
|
|
|
|
private suspend fun onReceive() {
|
|
while (isActive) {
|
|
select<Unit> {
|
|
requests.onReceive {
|
|
when (it) {
|
|
Request.TryAgain -> {
|
|
initData(browseId!!)
|
|
}
|
|
}
|
|
}
|
|
events.onReceive {
|
|
when (it) {
|
|
Event.ActivityOnResume -> {
|
|
activityOnResume()
|
|
}
|
|
|
|
else -> {}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private fun activityOnResume() {
|
|
addMusicPlayerViewToLayout(binding.playMusicLayout)
|
|
}
|
|
|
|
private fun initView() {
|
|
binding.backBtn.setOnClickListener {
|
|
finish()
|
|
}
|
|
binding.tryAgainBtn.setOnClickListener {
|
|
requests.trySend(Request.TryAgain)
|
|
}
|
|
binding.singerDescExpand.setOnClickListener {
|
|
showSongDescriptionDialog(binding.singerDesc.text.toString())
|
|
}
|
|
}
|
|
|
|
private suspend fun initData(browseId: String) {
|
|
showLoadingUi()
|
|
Innertube.moSingerListPage(browseId)
|
|
?.onSuccess {
|
|
showDataUi()
|
|
Glide.with(this)
|
|
.load(it.thumbnail)
|
|
.into(binding.singerImg)
|
|
binding.singerName.text = it.title
|
|
if (it.description.isNullOrEmpty()) {
|
|
binding.singerDesc.visibility = View.GONE
|
|
binding.singerDescExpand.visibility = View.GONE
|
|
} else {
|
|
binding.singerDesc.visibility = View.VISIBLE
|
|
binding.singerDescExpand.visibility = View.VISIBLE
|
|
binding.singerDesc.text = extractTextBeforeNewline(it.description)
|
|
}
|
|
if (it.list != null) {
|
|
for (bean: Innertube.SingerDetailsListPage in it.list) {
|
|
if (bean.contents?.musicShelfContentList != null && bean.contents.musicShelfContentList.isNotEmpty()) {
|
|
binding.contentLayout.addView(
|
|
SingerDetailsSongView(
|
|
this@MoSingerDetailsActivity,
|
|
bean
|
|
)
|
|
)
|
|
} else if (bean.contents?.musicCarouselShelfContentList != null && bean.contents.musicCarouselShelfContentList.isNotEmpty()) {
|
|
binding.contentLayout.addView(
|
|
SingerDetailsOtherView(
|
|
this@MoSingerDetailsActivity,
|
|
bean
|
|
)
|
|
)
|
|
}
|
|
}
|
|
}
|
|
}?.onFailure {
|
|
showNoContentUi()
|
|
LogD(TAG, "moSingerListPage onFailure->${it}")
|
|
}
|
|
}
|
|
|
|
private fun showDataUi() {
|
|
binding.loadingLayout.visibility = View.GONE
|
|
binding.noContentLayout.visibility = View.GONE
|
|
}
|
|
|
|
private fun showLoadingUi() {
|
|
binding.loadingLayout.visibility = View.VISIBLE
|
|
binding.noContentLayout.visibility = View.GONE
|
|
}
|
|
|
|
private fun showNoContentUi() {
|
|
binding.loadingLayout.visibility = View.GONE
|
|
binding.noContentLayout.visibility = View.VISIBLE
|
|
}
|
|
} |