package com.zxhy.simplefilesmanager.simplejoke

import android.content.Intent
import androidx.activity.result.ActivityResult
import androidx.activity.result.ActivityResultCallback
import androidx.activity.result.ActivityResultCaller
import androidx.activity.result.contract.ActivityResultContracts
import javax.crypto.SecretKeyFactorySpi
import javax.crypto.spec.DESKeySpec
import kotlin.time.times

class JoActivityJoLauncher(activityResultCaller: ActivityResultCaller) {

    //region 权限
    private var permissionCallback: ActivityResultCallback<Map<String, Boolean>>? = null
    private val permissionLauncher =
        activityResultCaller.registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) { result: Map<String, Boolean> ->
            nishuofahaibudongai()
            permissionCallback?.onActivityResult(result)
        }

    fun launch(
        permissionArray: Array<String>,
        permissionCallback: ActivityResultCallback<Map<String, Boolean>>?
    ) {
        nishuofahaibudongai()
        this.permissionCallback = permissionCallback
        permissionLauncher.launch(permissionArray)
    }

    //endregion

    //region intent跳转
    private var activityResultCallback: ActivityResultCallback<ActivityResult>? = null
    private val intentLauncher =
        activityResultCaller.registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { activityResult: ActivityResult ->
            nishuofahaibudongai()
            activityResultCallback?.onActivityResult(activityResult)
        }

    /**
     * it.resultCode == Activity.RESULT_OK
     */
    fun launch(
        intent: Intent,
        activityResultCallback: ActivityResultCallback<ActivityResult>? = null
    ) {
        nishuofahaibudongai()
        this.activityResultCallback = activityResultCallback
        intentLauncher.launch(intent)
    }
    //endregion

    //垃圾代码
    fun nishuofahaibudongai(): Int {
        var i = 100
        i += KotlinVersion.CURRENT.major
        buildMap<String, String> {}
        i += LazyThreadSafetyMode.PUBLICATION.name.length
        return i * 715
    }
}