package com.ccwangluo.accelerator.ui.news

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.RecyclerView
import com.ccwangluo.accelerator.R
import com.ccwangluo.accelerator.ui.home.NewsViewModel
import com.ccwangluo.accelerator.ui.news.DemoCollectionAdapter.Companion.ARG_OBJECT


class DemoObjectFragment : Fragment() {
    var recycle_view: RecyclerView? = null
    private lateinit var newsViewModel: NewsViewModel

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        newsViewModel = ViewModelProvider(requireActivity()).get(NewsViewModel::class.java)
        return inflater.inflate(R.layout.fragment_collection_object, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        arguments?.takeIf { it.containsKey(ARG_OBJECT) }?.apply {
            val position = getInt(ARG_OBJECT).toString()
            recycle_view = view.findViewById(R.id.recycle_view)

        }

//        val  adapter = KotlinDataAdapter.Builder<DeviceModel>()
//            .setData(deviceList)
//            .setLayoutId(R.layout.item_device)
//            .addBindView { itemView, itemData ->
//                itemView.tv_device_name.text = if (itemData.platform.isEmpty()) "未命名" else
//            }
//            .create()
    }

    fun refresh() {
        recycle_view?.postDelayed({
            newsViewModel.refreshState.postValue(false )
        }, 1000)

    }
}