Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0b2de845 authored by moezbhatti's avatar moezbhatti
Browse files

Organize saved files in /Media folder

parent 629e7a2d
Loading
Loading
Loading
Loading
+6 −8
Original line number Diff line number Diff line
@@ -60,17 +60,15 @@ class ImageRepostoryImpl @Inject constructor(private val context: Context) : Ima

    override fun saveImage(uri: Uri) {
        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()}")

        try {
            val outputStream = FileOutputStream(file)
            val inputStream = context.contentResolver.openInputStream(uri)

            FileOutputStream(file).use { outputStream ->
                context.contentResolver.openInputStream(uri)?.use { inputStream ->
                    inputStream.copyTo(outputStream, 1024)

            inputStream.close()
            outputStream.close()
                }
            }
        } catch (e: FileNotFoundException) {
            e.printStackTrace()
        } catch (e: IOException) {