package com.gh.gamecenter.feature.selector

import android.content.Context
import android.database.Cursor
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.CursorAdapter
import android.widget.TextView

import com.gh.gamecenter.common.R

import com.facebook.drawee.view.SimpleDraweeView
import com.gh.gamecenter.common.utils.goneIf
import com.zhihu.matisse.internal.entity.Album

class VideoAlbumsAdapter(context: Context) : CursorAdapter(context, null) {

    private var selectedPosition = 0

    override fun newView(context: Context?, cursor: Cursor?, parent: ViewGroup?): View {
        val inflate = LayoutInflater.from(context)
        return inflate.inflate(R.layout.video_albums_item, parent, false)
    }

    override fun bindView(view: View, context: Context, cursor: Cursor?) {
        val album = Album.valueOf(cursor)

        view.findViewById<View>(R.id.checkIv).goneIf(cursor?.position != selectedPosition)
        view.findViewById<TextView>(R.id.album_name).text = album.getDisplayName(context)
        view.findViewById<TextView>(R.id.album_media_count).text = album.count.toString()
        view.findViewById<SimpleDraweeView>(R.id.album_cover).setImageURI(album.coverUri)
    }

    fun updateSelectedPosition(position: Int) {
        selectedPosition = position
    }
}
