package com.base.browserwhite.ui.activity.bookmark

import android.content.Context
import android.view.View
import android.view.ViewGroup
import androidx.core.view.isVisible
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.base.browserwhite.R
import com.base.browserwhite.bean.BookmarkBean
import com.base.browserwhite.databinding.ItemBookmarkBinding
import com.base.browserwhite.utils.KotlinExt.toFormatTime
import com.base.browserwhite.utils.XmlEx.inflate
import com.chad.library.adapter4.BaseQuickAdapter

class BookmarkAdapter : BaseQuickAdapter<BookmarkBean, BookmarkAdapter.BookmarkHolder>() {
    inner class BookmarkHolder(view: View) : ViewHolder(view)

    override fun onBindViewHolder(holder: BookmarkHolder, position: Int, item: BookmarkBean?) {
        if (item == null) {
            return
        }

        val binding = ItemBookmarkBinding.bind(holder.itemView)
        binding.flTime.isVisible = item.showTime
        binding.tvTime.text = item.time.toFormatTime()

    }

    override fun getItemViewType(position: Int, list: List<BookmarkBean>): Int {
        return list[position].viewType

    }

    override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): BookmarkHolder {

        val layout = when (viewType) {
            0 -> R.layout.item_bookmark
            else -> R.layout.item_bookmark
        }
        return BookmarkHolder(layout.inflate(parent))
    }
}