package com.example.leudaemialikeme.Activity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.example.leudaemialikeme.R;

public class BlogSearchActivity extends AppCompatActivity {
    ImageView back;
    EditText blogSearchEdit;
    TextView blogSearchCommit;
    TextView recView;
    TextView foView;
    TextView poView;
    TextView meView;
    TextView stView;
    TextView exView;



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

        initView();
        initClick();




    }

    private void initView(){
        back = (ImageView)findViewById(R.id.search_back);
        blogSearchEdit = (EditText)findViewById(R.id.blog_search_edit);
        blogSearchCommit = (TextView) findViewById(R.id.blog_search_commit);
        recView=(TextView)findViewById(R.id.recView);
        foView=(TextView)findViewById(R.id.foView);
        poView=(TextView)findViewById(R.id.poView);
        meView=(TextView)findViewById(R.id.meView);
        stView=(TextView)findViewById(R.id.stView);
        exView=(TextView)findViewById(R.id.exView);
    }

    private void initClick(){

        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        blogSearchCommit.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v) {
                String text = blogSearchEdit.getText().toString();
                if(text.length() != 0){
                Intent intent=new Intent(BlogSearchActivity.this,BlogSearchResultActivity.class);
                Log.e("onClick-text",text);
                intent.putExtra("text",text);
                startActivity(intent);}
                else{
                    Toast.makeText(BlogSearchActivity.this, "请输入搜索的内容", Toast.LENGTH_SHORT).show();
                }
            }
        });

        recView.setOnClickListener(new View.OnClickListener(){

            @Override
            public void onClick(View v) {
                skip(recView);
            }
        });

        foView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                skip(foView);
            }
        });

        poView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                skip(poView);
            }
        });

        meView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                skip(meView);
            }
        });

        stView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                skip(stView);
            }
        });

        exView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                skip(exView);
            }
        });


    }
    private void skip(TextView view){
        String text = view.getText().toString();
        Intent intent=new Intent(BlogSearchActivity.this,BlogSearchResultActivity.class);
//                Log.e("onClick-text",text);
        intent.putExtra("text",text);
        startActivity(intent);
    }

}