package com.example.cmknowledgegraph;

import android.os.Bundle;


import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.hankcs.hanlp.HanLP;


import androidx.appcompat.app.AppCompatActivity;

import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;


import android.view.MenuItem;

import android.widget.TextView;


import yalantis.com.sidemenu.util.ViewAnimator;

public class MainActivity extends AppCompatActivity  {
    private TextView mTextMessage;
    private FragmentTransaction transaction;
    private FragmentManager fragmentManager;


    public final AppCompatActivity getAppCompatActivity(){
        return this;
    }

    private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
            = new BottomNavigationView.OnNavigationItemSelectedListener() {

        @Override


        public boolean onNavigationItemSelected(MenuItem item) {

            fragmentManager = getSupportFragmentManager();  //使用fragmentmanager和transaction来实现切换效果
            transaction = fragmentManager.beginTransaction();//开启事务
/*
* replace代替相应view
* commit提交事务
* */
            switch (item.getItemId()) {
                case R.id.home:
                    transaction.replace(R.id.content,new MainContent());  //对应的java class
                    transaction.commit();  //提交事务
                    return true;
                case R.id.search:
                    SearchContent searchContent = new SearchContent();
                    searchContent.setAppCompatActivity(getAppCompatActivity());
                    transaction.replace(R.id.content, searchContent);  //对应的java class

                    transaction.commit();  //提交事务
                    return true;
                case R.id.chat:
                    ChatContent chatContent = new ChatContent();
                    chatContent.setAppCompatActivity(getAppCompatActivity());
                    transaction.replace(R.id.content,chatContent);

                    transaction.commit();//提交事务
                    return true;
                case R.id.person:
                    PersonContent personContent = new PersonContent();
                    personContent.setAppCompatActivity(getAppCompatActivity());
                    transaction.replace(R.id.content, personContent);  //对应的java class

                    transaction.commit();  //提交事务
                    return true;
            }
            return false;
        }

    };
// 设置默认进来是tab 显示的页面
private void setDefaultFragment(){
        fragmentManager = getSupportFragmentManager();
        transaction = fragmentManager.beginTransaction();//开始事务
        transaction.replace(R.id.content,new MainContent());
        transaction.commit();//提交事务
        }

@Override
protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        setDefaultFragment();  //上面写的那个函数
        BottomNavigationView navView = findViewById(R.id.nav_view);
        mTextMessage = findViewById(R.id.message);
        navView.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);


        }

}