From 2ad3c622513f9d81bc30297e7eb18a6f78b1afaf Mon Sep 17 00:00:00 2001 From: gedoor Date: Thu, 3 Sep 2020 16:33:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/download/DownloadViewModel.kt | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/download/DownloadViewModel.kt b/app/src/main/java/io/legado/app/ui/book/download/DownloadViewModel.kt index 7402dd18b..c4a3ea97f 100644 --- a/app/src/main/java/io/legado/app/ui/book/download/DownloadViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/download/DownloadViewModel.kt @@ -5,8 +5,8 @@ import android.net.Uri import androidx.documentfile.provider.DocumentFile import io.legado.app.App import io.legado.app.R -import io.legado.app.constant.AppPattern import io.legado.app.base.BaseViewModel +import io.legado.app.constant.AppPattern import io.legado.app.data.entities.Book import io.legado.app.help.BookHelp import io.legado.app.utils.* @@ -44,10 +44,14 @@ class DownloadViewModel(application: Application) : BaseViewModel(application) { var src = matcher.group(1) src = NetworkUtils.getAbsoluteURL(chapter.url, src) src?.let { - val vfile = BookHelp.getImage(book, src) - if(vfile.exists()) { - DocumentUtils.createFileIfNotExist(doc, "${index}-${MD5Utils.md5Encode16(src)}.jpg", subDirs = arrayOf("${book.name}_${book.author}", "images", chapter.title)) - ?.writeBytes(context, vfile.readBytes()) + val vFile = BookHelp.getImage(book, src) + if (vFile.exists()) { + DocumentUtils.createFileIfNotExist(doc, + "${index}-${MD5Utils.md5Encode16(src)}.jpg", + subDirs = arrayOf("${book.name}_${book.author}", + "images", + chapter.title)) + ?.writeBytes(context, vFile.readBytes()) } } } @@ -67,10 +71,14 @@ class DownloadViewModel(application: Application) : BaseViewModel(application) { var src = matcher.group(1) src = NetworkUtils.getAbsoluteURL(chapter.url, src) src?.let { - val vfile = BookHelp.getImage(book, src) - if(vfile.exists()) { - FileUtils.createFileIfNotExist(file, "${book.name}_${book.author}", "images", chapter.title, "${index}-${MD5Utils.md5Encode16(src)}.jpg") - .writeBytes(vfile.readBytes()) + val vFile = BookHelp.getImage(book, src) + if (vFile.exists()) { + FileUtils.createFileIfNotExist(file, + "${book.name}_${book.author}", + "images", + chapter.title, + "${index}-${MD5Utils.md5Encode16(src)}.jpg") + .writeBytes(vFile.readBytes()) } } }