|
|
@ -7,7 +7,7 @@ import android.net.Uri |
|
|
|
import androidx.activity.result.ActivityResult |
|
|
|
import androidx.activity.result.ActivityResult |
|
|
|
import androidx.activity.result.contract.ActivityResultContract |
|
|
|
import androidx.activity.result.contract.ActivityResultContract |
|
|
|
|
|
|
|
|
|
|
|
class SelectImageContract : ActivityResultContract<Int, Pair<Int?, Uri?>?>() { |
|
|
|
class SelectImageContract : ActivityResultContract<Int, SelectImageContract.Result>() { |
|
|
|
|
|
|
|
|
|
|
|
var requestCode: Int? = null |
|
|
|
var requestCode: Int? = null |
|
|
|
|
|
|
|
|
|
|
@ -18,13 +18,18 @@ class SelectImageContract : ActivityResultContract<Int, Pair<Int?, Uri?>?>() { |
|
|
|
.setType("image/*") |
|
|
|
.setType("image/*") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun parseResult(resultCode: Int, intent: Intent?): Pair<Int?, Uri?>? { |
|
|
|
override fun parseResult(resultCode: Int, intent: Intent?): Result { |
|
|
|
if (resultCode == RESULT_OK) { |
|
|
|
if (resultCode == RESULT_OK) { |
|
|
|
return Pair(requestCode, intent?.data) |
|
|
|
return Result(requestCode, intent?.data) |
|
|
|
} |
|
|
|
} |
|
|
|
return null |
|
|
|
return Result(requestCode, null) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data class Result( |
|
|
|
|
|
|
|
val requestCode: Int?, |
|
|
|
|
|
|
|
val uri: Uri? = null |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
class StartActivityForResult(private val cls: Class<*>) : |
|
|
|
class StartActivityForResult(private val cls: Class<*>) : |
|
|
|