mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-10-09 23:52:33 +02:00
Use Pair instead of Array to split up file name
This commit is contained in:
@@ -167,8 +167,8 @@ class MediaCompressor {
|
|||||||
|
|
||||||
val inputStream = context.contentResolver.openInputStream(uri!!)
|
val inputStream = context.contentResolver.openInputStream(uri!!)
|
||||||
val fileName: String = UUID.randomUUID().toString() + ".$extension"
|
val fileName: String = UUID.randomUUID().toString() + ".$extension"
|
||||||
val splitName: Array<String> = splitFileName(fileName)
|
val (name, ext) = splitFileName(fileName)
|
||||||
val tempFile = File.createTempFile(splitName[0], splitName[1])
|
val tempFile = File.createTempFile(name, ext)
|
||||||
inputStream?.use { input ->
|
inputStream?.use { input ->
|
||||||
FileOutputStream(tempFile).use { output ->
|
FileOutputStream(tempFile).use { output ->
|
||||||
val buffer = ByteArray(1024 * 50)
|
val buffer = ByteArray(1024 * 50)
|
||||||
@@ -183,15 +183,13 @@ class MediaCompressor {
|
|||||||
return tempFile
|
return tempFile
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun splitFileName(fileName: String): Array<String> {
|
private fun splitFileName(fileName: String): Pair<String, String> {
|
||||||
var name = fileName
|
|
||||||
var extension = ""
|
|
||||||
val i = fileName.lastIndexOf(".")
|
val i = fileName.lastIndexOf(".")
|
||||||
if (i != -1) {
|
return if (i != -1) {
|
||||||
name = fileName.substring(0, i)
|
fileName.substring(0, i) to fileName.substring(i)
|
||||||
extension = fileName.substring(i)
|
} else {
|
||||||
|
fileName to ""
|
||||||
}
|
}
|
||||||
return arrayOf(name, extension)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun intToCompressorQuality(mediaQualityFloat: Int): CompressorQuality =
|
fun intToCompressorQuality(mediaQualityFloat: Int): CompressorQuality =
|
||||||
|
Reference in New Issue
Block a user