package com.example.leudaemialikeme.Activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.Toast;

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

import com.example.leudaemialikeme.Adapter.InfoAdapter;
import com.example.leudaemialikeme.Model.Recnews;
import com.example.leudaemialikeme.R;

import java.util.ArrayList;
import java.util.List;

public class InfoActivity extends BaseActivity {

    private List<Recnews> recNews=new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_info);

        Intent intent=getIntent();
        int infoType=intent.getIntExtra("info_type",4);


        List<String> typeList = new ArrayList<String>();
        typeList.add("公司");
        typeList.add("红十字");
        typeList.add("政府");
        typeList.add("慈善");
        typeList.add("全部");
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, typeList);
        adapter.setDropDownViewResource(android.R.layout.simple_list_item_single_choice);
        Spinner sp = (Spinner) findViewById(R.id.info_type);
        sp.setAdapter(adapter);
        sp.setSelection(infoType,true);
        sp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            // parent： 为控件Spinner view：显示文字的TextView position：下拉选项的位置从0开始
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

         //获取Spinner控件的适配器
                ArrayAdapter<String> adapter = (ArrayAdapter<String>) parent.getAdapter();
                //tvResult.setText(adapter.getItem(position));
                Toast.makeText(getBaseContext(),adapter.getItem(position),Toast.LENGTH_SHORT).show();
            }
            //没有选中时的处理
            public void onNothingSelected(AdapterView<?> parent) {
            }
        });

        ImageView infoToIndex=(ImageView) findViewById(R.id.info_to_index);
        infoToIndex.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent(InfoActivity.this, MainActivity.class);
                i.putExtra("flag",1);
                startActivity(i);
            }
        });

        initRecNews();
        RecyclerView recyclerView=(RecyclerView) findViewById(R.id.info_recyclerView);
        LinearLayoutManager layoutManager=new LinearLayoutManager(this);
        recyclerView.setLayoutManager(layoutManager);
        InfoAdapter infoAdapter=new InfoAdapter(recNews);
        recyclerView.setAdapter(infoAdapter);



    }

    private void initRecNews(){
        for(int i=0;i<2;i++){
            Recnews news1=new Recnews(R.drawable.rec_news1,
                    "儿童急性B淋巴细胞白血病,除了传统疗法还有哪些前沿治疗方法呢？",
                    "急性淋巴细胞白血病（ALL）是儿童最常见的恶性肿瘤，其中约85%为……"
                    ,102,"2021-11-6 09:19:54"
            );
            recNews.add(news1);
            Recnews news2=new Recnews(R.drawable.rec_news2,
                    "儿童急性B淋巴细胞白血病,除了传统疗法还有哪些前沿治疗方法呢？",
                    "急性淋巴细胞白血病（ALL）是儿童最常见的恶性肿瘤，其中约85%为……"
                    ,100,"2021-12-6 03:19:54"
            );
            recNews.add(news2);
            Recnews news3=new Recnews(R.drawable.rec_news3,
                    "儿童急性B淋巴细胞白血病,除了传统疗法还有哪些前沿治疗方法呢？",
                    "急性淋巴细胞白血病（ALL）是儿童最常见的恶性肿瘤，其中约85%为……"
                    ,100,"2021-12-6 03:19:54"
            );
            recNews.add(news3);
            Recnews news4=new Recnews(R.drawable.rec_news4,
                    "儿童急性B淋巴细胞白血病,除了传统疗法还有哪些前沿治疗方法呢？",
                    "急性淋巴细胞白血病（ALL）是儿童最常见的恶性肿瘤，其中约85%为……"
                    ,100,"2021-12-6 03:19:54"
            );
            recNews.add(news4);
        }
    }
}
