package com.addd.xingdongli.ui;

import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.MenuItem;
import android.widget.LinearLayout;
import android.view.View;

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

import com.addd.xingdongli.R;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.bottomsheet.BottomSheetBehavior;
import com.google.android.material.floatingactionbutton.FloatingActionButton;

public class MainActivity extends AppCompatActivity {


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

        // 初始化 BottomNavigationView
        BottomNavigationView bottomNavigation = findViewById(R.id.bottom_navigation);



        // 设置菜单项点击监听
        bottomNavigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                int itemId = item.getItemId();
                if (itemId == R.id.navigation_home) {
                    loadFragment(new HomeFragment());
                    return true;
                } else if (itemId == R.id.navigation_plan) {
                    loadFragment(new PlanFragment());
                    return true;
                } else if (itemId == R.id.navigation_settings) {
                    loadFragment(new SettingsFragment());
                    return true;
                }
                return false;
            }

        });

        // 默认加载主页
        if (savedInstanceState == null) {
            loadFragment(new HomeFragment());
        }

    }

    /**
     * 用于替换 Fragment 的方法
     * @param fragment 要加载的 Fragment 实例
     */
    private void loadFragment(Fragment fragment) {
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.replace(R.id.fragment_container, fragment);
        transaction.commit();
    }


}
