package com.gh.common.provider

import android.content.Context
import android.content.Intent
import android.os.Build
import android.os.Bundle
import androidx.fragment.app.FragmentActivity
import com.therouter.router.Route
import com.gh.common.util.EntranceUtils
import com.gh.gamecenter.common.avoidcallback.Callback
import com.gh.gamecenter.common.constant.RouteConsts
import com.gh.gamecenter.core.provider.IEntranceUtilsProvider
import com.lightgame.utils.AppManager

@com.therouter.inject.ServiceProvider
class EntranceUtilsProviderImpl : IEntranceUtilsProvider {

    override fun jumpActivity(context: Context, bundle: Bundle) {
        EntranceUtils.jumpActivity(context, bundle)
    }

    override fun saveShortcut(activityName: String, bundle: Bundle?) {
        EntranceUtils.saveShortcut(activityName, bundle)
    }

    override fun jumpActivityWithCallback(context: Context, bundle: Bundle, callback: () -> Unit) {
        if (context is FragmentActivity && !context.supportFragmentManager.isDestroyed) {
            EntranceUtils.jumpActivityCompat(context, bundle, null, object : Callback {
                override fun onActivityResult(resultCode: Int, data: Intent?) {
                    callback()
                }
            })
        } else {
            EntranceUtils.jumpActivityCompat(AppManager.getInstance().currentActivity(), bundle)
        }
    }

}