package com.wisewoods.eduandroid.ui;

import android.os.Bundle;

import androidx.recyclerview.widget.LinearLayoutManager;

import com.wisewoods.base.base.BaseActivity;
import com.wisewoods.base.bean.RoomInfo;
import com.wisewoods.base.net.JCallback;
import com.wisewoods.eduandroid.app.App;
import com.wisewoods.eduandroid.databinding.ActivityRoomBinding;
import com.wisewoods.eduandroid.ui.adapter.RoomAdapter;

import retrofit2.Response;

public class RoomActivity extends BaseActivity<ActivityRoomBinding> {


    private RoomAdapter mAdapter;

    @Override
    protected void initData(Bundle savedInstanceState) {
        showBarBack(binding.bar.tvTitle, "教室统计", binding.bar.ivBack);

        binding.ts.setTimeListener((timeStrStart, timeStrEnd) -> {
            mAdapter.setNewInstance(null);
            getData();
        });

        binding.rvRoom.setLayoutManager(new LinearLayoutManager(this));
        mAdapter = new RoomAdapter();
        binding.rvRoom.setAdapter(mAdapter);

        getData();
    }

    private void getData() {
        App.api.getRoomList(binding.ts.getTimeStrStart())
                .enqueue(new JCallback<RoomInfo>() {
                    @Override
                    public void onS(Response<RoomInfo> response, RoomInfo roomInfo) {
                        mAdapter.setNewInstance(roomInfo.data);

                    }
                });
    }
}
