Convert MediaFileUtils to a non-object

This commit is contained in:
ericdecanini 2022-04-14 11:28:14 +02:00
parent 8b66034af5
commit da843443ef
2 changed files with 18 additions and 21 deletions

View File

@ -23,8 +23,8 @@ import android.provider.MediaStore
import androidx.activity.result.ActivityResultLauncher
import androidx.core.content.FileProvider
import im.vector.lib.multipicker.entity.MultiPickerImageType
import im.vector.lib.multipicker.utils.MediaFileUtils.MediaType.IMAGE
import im.vector.lib.multipicker.utils.MediaFileUtils.createTemporaryMediaFile
import im.vector.lib.multipicker.utils.MediaType
import im.vector.lib.multipicker.utils.createTemporaryMediaFile
import im.vector.lib.multipicker.utils.toMultiPickerImageType
/**
@ -61,7 +61,7 @@ class CameraPicker {
companion object {
fun createPhotoUri(context: Context): Uri {
val file = createTemporaryMediaFile(context, IMAGE)
val file = createTemporaryMediaFile(context, MediaType.IMAGE)
val authority = context.packageName + ".multipicker.fileprovider"
return FileProvider.getUriForFile(context, authority, file)
}

View File

@ -22,24 +22,21 @@ import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale
object MediaFileUtils {
fun createTemporaryMediaFile(context: Context, mediaType: MediaType): File {
val timeStamp: String = SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(Date())
val storageDir: File = context.filesDir.also { it.mkdirs() }
val fileSuffix = when (mediaType) {
MediaType.IMAGE -> ".jpg"
MediaType.VIDEO -> ".mp4"
}
return File.createTempFile(
"${timeStamp}_",
fileSuffix,
storageDir
)
fun createTemporaryMediaFile(context: Context, mediaType: MediaType): File {
val timeStamp: String = SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(Date())
val storageDir: File = context.filesDir.also { it.mkdirs() }
val fileSuffix = when (mediaType) {
MediaType.IMAGE -> ".jpg"
MediaType.VIDEO -> ".mp4"
}
enum class MediaType {
IMAGE, VIDEO
}
return File.createTempFile(
"${timeStamp}_",
fileSuffix,
storageDir
)
}
enum class MediaType {
IMAGE, VIDEO
}