package com.example.iot_controlhost.adapter;

import com.blankj.utilcode.util.TimeUtils;
import com.example.iot_controlhost.R;
import com.example.iot_controlhost.base.BaseRecyclerAdapter;
import com.example.iot_controlhost.databinding.ItemLogBinding;
import com.example.iot_controlhost.model.Log;
import com.example.iot_controlhost.utils.global.RoomSetting;

import java.util.List;

/**
 * 日志适配器
 * 用于查找日志弹窗
 *
 * @Author：DuanKaiji
 */
public class LogAdapter extends BaseRecyclerAdapter<Log, ItemLogBinding> {

    public LogAdapter(List<Log> dataList, Class<ItemLogBinding> bindingClass) {
        super(dataList, bindingClass);
    }

    @Override
    protected void bindData(ItemLogBinding binding, Log data) {
        int targetColorId = binding.tvMessage.getContext().getColor(
                data.getLevel() == android.util.Log.ERROR ? R.color.red : RoomSetting.isDarkTheme() ? R.color.white : R.color.black);
        binding.tvMessage.setTextColor(targetColorId);
        binding.tvDate.setTextColor(targetColorId);
        binding.tvMessage.setText("[" + data.getTag() + "] " + data.getMessage());
        binding.tvDate.setText(TimeUtils.date2String(data.getDatetime()));
    }
}
