package com.cheng.blzb.ui.fragment.push.subscribe

import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.cheng.blzb.R
import com.cheng.blzb.bean.SubscriptionEntity
import com.cheng.blzb.manager.UserConfigManager

class SubscribeAdapter: BaseQuickAdapter<SubscriptionEntity, BaseViewHolder>(R.layout.listitem_subscribe) {

    init {
        addChildClickViewIds(R.id.tv_delete, R.id.tv_edit)
    }

    override fun convert(holder: BaseViewHolder, item: SubscriptionEntity) {
        holder.setText(R.id.tv_name, item.name)

        val rvKeyword = holder.getView<RecyclerView>(R.id.rv_keywords)
        val keywordAdapter = KeywordAdapter()
        rvKeyword.adapter = keywordAdapter
        keywordAdapter.setList(item.keyword)

        val rvCity = holder.getView<RecyclerView>(R.id.rv_area)
        val cityAdapter = CityAdapter()
        rvCity.adapter = cityAdapter
        if (item.type == 1) {
            if (item.city_name.size == UserConfigManager.getCityList().size) {
                cityAdapter.setList(listOf("全国"))
            } else {
                cityAdapter.setList(item.city_name)
            }
        } else {
            cityAdapter.setList(item.source_name)
        }
    }

    inner class KeywordAdapter: BaseQuickAdapter<String, BaseViewHolder>(R.layout.listitem_subscribe_keyword) {
        override fun convert(holder: BaseViewHolder, item: String) {
            holder.setText(R.id.tv_name, item)
        }

    }

    inner class CityAdapter: BaseQuickAdapter<String, BaseViewHolder>(R.layout.listitem_subscribe_area) {
        override fun convert(holder: BaseViewHolder, item: String) {
            holder.setText(R.id.tv_name, item)
        }

    }
}