package com.grkj.iscs_mc.extentions

import android.os.Bundle
import androidx.fragment.app.Fragment
import androidx.navigation.NavDirections
import androidx.navigation.NavOptions
import androidx.navigation.fragment.findNavController
import com.grkj.iscs_mc.util.Executor
import com.grkj.iscs_mc.util.log.LogUtil

/**
 * 回到上一页面
 */
fun Fragment.navigateUp() {
    Executor.runOnMain {
        if (isAdded) {
            findNavController().navigateUp()
        }
    }
}

/**
 * 回到上一页面
 */
fun Fragment.navigateTo(direction: NavDirections) {
    Executor.runOnMain {
        try {
            findNavController().navigate(direction)
        } catch (e: Exception) {
            LogUtil.e(e)
        }
    }
}

fun Fragment.navigateTo(directionId: Int, bundle: Bundle, navOptions: NavOptions? = null) {
    Executor.runOnMain {
        try {
            findNavController().navigate(directionId, bundle, navOptions)
        } catch (e: Exception) {
            LogUtil.e(e)
        }
    }
}
