package com.example.cmknowledgegraph;

import android.os.Bundle;

import com.example.cmknowledgegraph.MainContent;
import com.example.cmknowledgegraph.R;
import com.example.cmknowledgegraph.SearchContent;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.hankcs.hanlp.HanLP;

import androidx.appcompat.app.AppCompatActivity;
import androidx.annotation.NonNull;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import android.view.MenuItem;
import android.widget.TextView;

import java.util.List;

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

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

        @Override


        public boolean onNavigationItemSelected(MenuItem item) {
            fragmentManager = getSupportFragmentManager();  //使用fragmentmanager和transaction来实现切换效果
            transaction = fragmentManager.beginTransaction();
            switch (item.getItemId()) {
                case R.id.home:
                    transaction.replace(R.id.content,new MainContent());  //对应的java class
                    transaction.commit();  //一定不要忘记commit，否则不会显示
                    return true;
                case R.id.search:
                    transaction.replace(R.id.content,new SearchContent());  //对应的java class
                    transaction.commit();  //一定不要忘记commit，否则不会显示
                    return true;
                case R.id.chat:
                    return true;
                case R.id.person:
                    transaction.replace(R.id.content,new PersonContent());  //对应的java class
                    transaction.commit();  //一定不要忘记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);

        //HanLP测试
        String content = "发烧感冒";
        List<String> keywordList = HanLP.extractKeyword(content, 5);
        System.out.println(keywordList);
        }

        }