优化代码

pull/352/head
gedoor 4 years ago
parent 13934582a4
commit 64bf4e0f04
  1. 2
      app/src/main/java/io/legado/app/help/BookHelp.kt
  2. 2
      app/src/main/java/io/legado/app/help/CrashHandler.kt
  3. 2
      app/src/main/java/io/legado/app/help/storage/Backup.kt
  4. 5
      app/src/main/java/io/legado/app/utils/FileUtils.kt

@ -52,7 +52,7 @@ object BookHelp {
App.db.bookDao().all.forEach {
bookFolderNames.add(it.getFolderName())
}
val file = FileUtils.getDirFile(downloadDir, cacheFolderName)
val file = FileUtils.getFile(downloadDir, cacheFolderName)
file.listFiles()?.forEach { bookFile ->
if (!bookFolderNames.contains(bookFile.name)) {
FileUtils.deleteFile(bookFile.absolutePath)

@ -142,7 +142,7 @@ class CrashHandler : Thread.UncaughtExceptionHandler {
val time = format.format(Date())
val fileName = "crash-$time-$timestamp.log"
mContext?.externalCacheDir?.let { rootFile ->
FileUtils.getDirFile(rootFile, "crash").listFiles()?.forEach {
FileUtils.getFile(rootFile, "crash").listFiles()?.forEach {
if (it.lastModified() < System.currentTimeMillis() - TimeUnit.DAYS.toMillis(7)) {
it.delete()
}

@ -18,7 +18,7 @@ import java.util.concurrent.TimeUnit
object Backup {
val backupPath: String by lazy {
FileUtils.getDirFile(App.INSTANCE.filesDir, "backup").absolutePath
FileUtils.getFile(App.INSTANCE.filesDir, "backup").absolutePath
}
val backupFileNames by lazy {

@ -54,11 +54,6 @@ object FileUtils {
return File(filePath)
}
fun getDirFile(root: File, vararg subDirs: String): File {
val filePath = getPath(root = root, *subDirs)
return File(filePath)
}
fun getPath(root: File, vararg subDirFiles: String): String {
val path = StringBuilder(root.absolutePath)
subDirFiles.forEach {

Loading…
Cancel
Save