mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-22 13:48:52 +01:00
Organize saved files in /Media folder
This commit is contained in:
@@ -60,17 +60,15 @@ class ImageRepostoryImpl @Inject constructor(private val context: Context) : Ima
|
|||||||
|
|
||||||
override fun saveImage(uri: Uri) {
|
override fun saveImage(uri: Uri) {
|
||||||
val type = context.contentResolver.getType(uri)?.split("/") ?: return
|
val type = context.contentResolver.getType(uri)?.split("/") ?: return
|
||||||
val dir = File(Environment.getExternalStorageDirectory(), "QKSMS").apply { mkdirs() }
|
val dir = File(Environment.getExternalStorageDirectory(), "QKSMS/Media").apply { mkdirs() }
|
||||||
val file = File(dir, "${type.first()}${System.currentTimeMillis()}.${type.last()}")
|
val file = File(dir, "${type.first()}${System.currentTimeMillis()}.${type.last()}")
|
||||||
|
|
||||||
try {
|
try {
|
||||||
val outputStream = FileOutputStream(file)
|
FileOutputStream(file).use { outputStream ->
|
||||||
val inputStream = context.contentResolver.openInputStream(uri)
|
context.contentResolver.openInputStream(uri)?.use { inputStream ->
|
||||||
|
inputStream.copyTo(outputStream, 1024)
|
||||||
inputStream.copyTo(outputStream, 1024)
|
}
|
||||||
|
}
|
||||||
inputStream.close()
|
|
||||||
outputStream.close()
|
|
||||||
} catch (e: FileNotFoundException) {
|
} catch (e: FileNotFoundException) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
|
|||||||
Reference in New Issue
Block a user