package com.emato.ich.utils;

import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.navigation.NavBackStackEntry;
import androidx.navigation.NavController;
import androidx.navigation.fragment.NavHostFragment;

import com.emato.ich.MainActivity;
import com.emato.ich.fragment.SendInfoConfirmFragment;
import com.emato.ich.local.LocalStorage;


/**
 * 导航工具类
 */
public class NavUtils {

    private static final String TAG = NavUtils.class.getName();

    /**
     * 跳转
     * @param fragment  Fragment
     * @param navId     action_id
     * @param bundle    参数
     */
    public static void navigate(Fragment fragment, int navId, Bundle bundle) {
        try {
            NavController navController = NavHostFragment.findNavController(fragment);
            NavBackStackEntry currentBackStackEntry = navController.getCurrentBackStackEntry();
            if (currentBackStackEntry != null) {
                if (currentBackStackEntry.getDestination().getAction(navId) != null) {
                    navController.navigate(navId, bundle);
                }
            }
        } catch (Exception e) {
            Log.e(TAG, "跳转出现异常！ ", e);
        }
    }

    public static void navigate(Fragment fragment, int navId) {
        navigate(fragment, navId, null);
    }

}
