package com.webtoonviewer.utils

import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Environment
import android.provider.Settings
import androidx.activity.result.ActivityResultLauncher

class ExternalStoragePermission (private val context: Context){

    fun hasManageExternalStoragePermission(): Boolean {
        return Environment.isExternalStorageManager()
    }

    fun requestManageExternalStoragePermission(
        manageExternalStoragePermissionLauncher: ActivityResultLauncher<Intent>
    ) {
        try {
            val intent = Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION)
            intent.data = Uri.parse("package:" + context.packageName)
            manageExternalStoragePermissionLauncher.launch(intent)
        } catch (ex: Exception) {
            val intent = Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION)
            manageExternalStoragePermissionLauncher.launch(intent)
        }
    }
}