package com.bbitcn.silk.ui.activity;

import android.view.View;

import androidx.recyclerview.widget.LinearLayoutManager;

import com.bbitcn.silk.adapter.AboutAdapter;
import com.bbitcn.silk.base.BaseActivity;
import com.bbitcn.silk.databinding.ActivityAboutBinding;
import com.bbitcn.silk.databinding.ItemAboutBinding;
import com.bbitcn.silk.model.net.About;

import java.util.List;

/**
 * @Description 关于界面
 * @Author DuanKaiji
 * @CreateTime 2024年03月27日 15:12
 */
public class AboutActivity extends BaseActivity<ActivityAboutBinding, AboutActivityPresenter> {
    AboutAdapter adapter;

    @Override
    public void initView() {
        presenter.getAboutInfo();
        adapter = new AboutAdapter(null, ItemAboutBinding.class);
        binding.recycleView.setAdapter(adapter);
        binding.recycleView.setLayoutManager(new LinearLayoutManager(mContext));
        binding.clSystem.setVisibility(View.GONE);
        presenter.getAboutLiveData().observe(this, about -> {
            //刷新数据
            binding.tvAbout.setText(about.getAbout());
            List<About.DataDTO.ItemsDTO> items = about.getItems();
            if (items == null || items.size() == 0) {
                return;
            }
            About.DataDTO.ItemsDTO itemsDTO = items.get(0);
            binding.tvTitle.setText(itemsDTO.getName());
            adapter.setDataList(itemsDTO.getItems());
            if (items.size() < 2) {
                return;
            }
            itemsDTO = items.get(1);
            binding.clSystem.setVisibility(View.VISIBLE);
            //显示甲方数据
            if (itemsDTO.getItems().size() > 0 && itemsDTO.getItems().get(0) != null) {
                binding.tvKey1.setText(itemsDTO.getItems().get(0).getName());
                binding.tvValue1.setText(itemsDTO.getItems().get(0).getValue());
            }
            if (itemsDTO.getItems().size() > 1 && itemsDTO.getItems().get(1) != null) {
                binding.tvKey2.setText(itemsDTO.getItems().get(1).getName());
                binding.tvValue2.setText(itemsDTO.getItems().get(1).getValue());
            }
        });

    }

    @Override
    public void initListener() {
        super.initListener();
        binding.ivBack.setOnClickListener(v -> finish());
    }

}
