|
|
@ -7,16 +7,19 @@ import android.net.Uri |
|
|
|
import androidx.activity.result.contract.ActivityResultContract |
|
|
|
import androidx.activity.result.contract.ActivityResultContract |
|
|
|
|
|
|
|
|
|
|
|
@Suppress("unused") |
|
|
|
@Suppress("unused") |
|
|
|
class HandleFileContract : ActivityResultContract<FilePickerParam, Uri?>() { |
|
|
|
class HandleFileContract : |
|
|
|
|
|
|
|
ActivityResultContract<HandleFileContract.HandleFileParam.() -> Unit, Uri?>() { |
|
|
|
|
|
|
|
|
|
|
|
companion object { |
|
|
|
companion object { |
|
|
|
const val DIRECTORY = 0 |
|
|
|
const val DIRECTORY = 0 |
|
|
|
const val FILE = 1 |
|
|
|
const val FILE = 1 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun createIntent(context: Context, input: FilePickerParam?): Intent { |
|
|
|
override fun createIntent(context: Context, input: HandleFileParam.() -> Unit): Intent { |
|
|
|
val intent = Intent(context, FilePickerActivity::class.java) |
|
|
|
val intent = Intent(context, HandleFileActivity::class.java) |
|
|
|
input?.let { |
|
|
|
val handleFileParam = HandleFileParam() |
|
|
|
|
|
|
|
handleFileParam.apply(input) |
|
|
|
|
|
|
|
handleFileParam.let { |
|
|
|
intent.putExtra("mode", it.mode) |
|
|
|
intent.putExtra("mode", it.mode) |
|
|
|
intent.putExtra("title", it.title) |
|
|
|
intent.putExtra("title", it.title) |
|
|
|
intent.putExtra("allowExtensions", it.allowExtensions) |
|
|
|
intent.putExtra("allowExtensions", it.allowExtensions) |
|
|
@ -32,12 +35,12 @@ class HandleFileContract : ActivityResultContract<FilePickerParam, Uri?>() { |
|
|
|
return null |
|
|
|
return null |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
@Suppress("ArrayInDataClass") |
|
|
|
|
|
|
|
data class HandleFileParam( |
|
|
|
|
|
|
|
var mode: Int = DIRECTORY, |
|
|
|
|
|
|
|
var title: String? = null, |
|
|
|
|
|
|
|
var allowExtensions: Array<String> = arrayOf(), |
|
|
|
|
|
|
|
var otherActions: Array<String>? = null, |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
@Suppress("ArrayInDataClass") |
|
|
|
} |
|
|
|
data class FilePickerParam( |
|
|
|
|
|
|
|
var mode: Int = 0, |
|
|
|
|
|
|
|
var title: String? = null, |
|
|
|
|
|
|
|
var allowExtensions: Array<String> = arrayOf(), |
|
|
|
|
|
|
|
var otherActions: Array<String>? = null, |
|
|
|
|
|
|
|
) |
|
|
|
|