package com.sjkj.appthreefloor_tsgz.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.sjkj.appthreefloor_tsgz.R;
import com.sjkj.appthreefloor_tsgz.activity.viewModel.ResourceVisualizationViewModel;
import com.sjkj.appthreefloor_tsgz.adapter.CommonDataListAdapter;
import com.sjkj.appthreefloor_tsgz.bean.DataBean;
import com.sjkj.appthreefloor_tsgz.bean.ResourceVisualizationBean;
import com.sjkj.appthreefloor_tsgz.databinding.FragmentDataListBinding;
import com.sjkj.base_lib.adapter.BaseRecAdapter;
import com.sjkj.base_lib.divider.DividerItem;
import com.sjkj.base_lib.view.BaseFragment;

import java.util.List;

public class CommonDataListFragment extends BaseFragment {

    private FragmentDataListBinding binding;
    private ResourceVisualizationViewModel viewModel;
    private List<DataBean> list;
    private int currentPage = 1;
    private CommonDataListAdapter adapter;
    private Double Latitude = 0.0, Longitude = 0.0;
    private String type = "";

    public CommonDataListFragment(String type) {
        this.type = type;
    }

    @Override
    protected int initLayout() {
        return R.layout.fragment_data_list;
    }

    @Override
    public View initBinding(LayoutInflater inflater, ViewGroup container, Bundle bundle) {
        binding = (FragmentDataListBinding) getViewDataBing(inflater, container);
        viewModel = new ViewModelProvider(getActivity(), new ViewModelProvider.NewInstanceFactory()).get(ResourceVisualizationViewModel.class);
        binding.setViewModel(viewModel);
        binding.setLifecycleOwner(this);
        return binding.getRoot();
    }

    @Override
    public void initView() {


        LinearLayoutManager manager = new LinearLayoutManager(getActivity());
        manager.setOrientation(RecyclerView.VERTICAL);
        binding.recyclerView.setLayoutManager(manager);
        adapter = new CommonDataListAdapter(getActivity());
        adapter.setItemClick(new BaseRecAdapter.OnItemClick<ResourceVisualizationBean>() {
            @Override
            public void onItemClick(ResourceVisualizationBean bean, int position) {
//                Intent intent = new Intent(getActivity(), ResourcePointDetailsActivity.class);
//                intent.putExtra("type", type);
//                intent.putExtra("id", bean.getId());
//                intent.putExtra("lat",bean.getLatitude());
//                intent.putExtra("lng",bean.getLongitude());
//                startActivity(intent);
            }
        });
        binding.recyclerView.setAdapter(adapter);
       /* binding.smartRefreshLayout.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(RefreshLayout refreshLayout) {
                currentPage = 1;
                requestListRefresh();
            }
        });*/
//        binding.smartRefreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {
//            @Override
//            public void onLoadMore(RefreshLayout refreshLayout) {
//                //requestListLoadMore();
//            }
//        });
        binding.recyclerView.addItemDecoration(new DividerItem(getActivity()));
//        viewModel.singleLiveData.observe(this, new Observer<DataBean>() {
//            @Override
//            public void onChanged(DataBean bean) {
//                ToastUtils.show(bean == null ? "null" : "not null");
//            }
//        });
    }

    @Override
    public void initListener() {

    }


    public void updataUI(List<ResourceVisualizationBean> list, String Type_Name) {
        adapter.setTypeName(Type_Name);
        adapter.refreshList(list);
    }

    @Override
    public void loadData() {


    }


}
