package melody.offline.music.view

import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.widget.LinearLayout
import android.widget.TextView
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import melody.offline.music.R
import melody.offline.music.activity.MoSingerMoreSongActivity
import melody.offline.music.adapter.SingerDetailsSongListAdapter
import melody.offline.music.innertube.Innertube

@SuppressLint("ViewConstructor")
class SingerDetailsSongView(context: Context, bean: Innertube.SingerDetailsListPage) :
    ModuleView(context) {
    init {
        contentView = inflate(getContext(), R.layout.singer_music_list_layout, this)
        val title = contentView?.findViewById<TextView>(R.id.title)
        title?.text = bean.title

        val moreBtn = contentView?.findViewById<LinearLayout>(R.id.moreBtn)
        moreBtn?.setOnClickListener {
            val intent = Intent(context, MoSingerMoreSongActivity::class.java)
            intent.putExtra(MoSingerMoreSongActivity.SINGER_MORE_SONG_BROWSE_ID, bean.browseId)
            intent.putExtra(MoSingerMoreSongActivity.SINGER_MORE_SONG_PARAMS, bean.params)
            context.startActivity(intent)
        }

        val rv = contentView?.findViewById<RecyclerView>(R.id.rv)

        val adapter = SingerDetailsSongListAdapter(context, bean.contents?.musicShelfContentList!!)
        rv?.layoutManager = LinearLayoutManager(context, GridLayoutManager.VERTICAL, false)
        rv?.adapter = adapter
    }

}