diff --git a/data/src/main/java/com/moez/QKSMS/util/FileUtils.kt b/data/src/main/java/com/moez/QKSMS/util/FileUtils.kt index 2ac317f3ddf23c716088ce12138f75cb64f5e6dc..61841e94c5239bf366f8a5de87698ecedb744099 100644 --- a/data/src/main/java/com/moez/QKSMS/util/FileUtils.kt +++ b/data/src/main/java/com/moez/QKSMS/util/FileUtils.kt @@ -15,15 +15,28 @@ */ package com.moez.QKSMS.util +import android.os.Handler +import android.os.Looper import java.io.File object FileUtils { - fun moveDir(oldDir: File, newDir: File) { - if (oldDir.exists() && oldDir.isDirectory) { - newDir.apply { mkdirs() } - oldDir.copyRecursively(newDir) - oldDir.deleteRecursively() + fun moveDir(sourceDir: File, destinationDir: File) { + if (!sourceDir.exists() || !sourceDir.isDirectory) { + return + } + + // Perform the copy operation asynchronously using + // a Handler to prevent blocking the main thread + Handler(Looper.getMainLooper()).post { + if (destinationDir.exists()) { + val copySuccess = sourceDir.copyRecursively(destinationDir, true) + if (copySuccess) { + sourceDir.deleteRecursively() + } + } else { + sourceDir.renameTo(destinationDir) + } } }