|  |  |  | @ -7,8 +7,10 @@ import io.legado.app.App | 
			
		
	
		
			
				
					|  |  |  |  | import io.legado.app.R | 
			
		
	
		
			
				
					|  |  |  |  | import io.legado.app.base.BaseViewModel | 
			
		
	
		
			
				
					|  |  |  |  | import io.legado.app.constant.AppPattern | 
			
		
	
		
			
				
					|  |  |  |  | import io.legado.app.constant.PreferKey | 
			
		
	
		
			
				
					|  |  |  |  | import io.legado.app.data.entities.Book | 
			
		
	
		
			
				
					|  |  |  |  | import io.legado.app.help.BookHelp | 
			
		
	
		
			
				
					|  |  |  |  | import io.legado.app.help.storage.WebDavHelp | 
			
		
	
		
			
				
					|  |  |  |  | import io.legado.app.utils.* | 
			
		
	
		
			
				
					|  |  |  |  | import java.io.File | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
	
		
			
				
					|  |  |  | @ -34,8 +36,21 @@ class CacheViewModel(application: Application) : BaseViewModel(application) { | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     private fun export(doc: DocumentFile, book: Book) { | 
			
		
	
		
			
				
					|  |  |  |  |         DocumentUtils.createFileIfNotExist(doc, "${book.name} 作者:${book.author}.txt") | 
			
		
	
		
			
				
					|  |  |  |  |             ?.writeText(context, getAllContents(book)) | 
			
		
	
		
			
				
					|  |  |  |  |         val filename = "${book.name} by ${book.author}.txt" | 
			
		
	
		
			
				
					|  |  |  |  |         val content = getAllContents(book) | 
			
		
	
		
			
				
					|  |  |  |  |         DocumentUtils.createFileIfNotExist(doc, filename) | 
			
		
	
		
			
				
					|  |  |  |  |             ?.writeText(context, content) | 
			
		
	
		
			
				
					|  |  |  |  |         if(App.INSTANCE.getPrefBoolean(PreferKey.webDavExport,false)) { | 
			
		
	
		
			
				
					|  |  |  |  |             //写出文件到cache目录 | 
			
		
	
		
			
				
					|  |  |  |  |             FileUtils.createFileIfNotExist( | 
			
		
	
		
			
				
					|  |  |  |  |                 File(FileUtils.getCachePath()), | 
			
		
	
		
			
				
					|  |  |  |  |                 filename | 
			
		
	
		
			
				
					|  |  |  |  |             ).writeText(content) | 
			
		
	
		
			
				
					|  |  |  |  |             //导出到webdav | 
			
		
	
		
			
				
					|  |  |  |  |             WebDavHelp.exportWebDav(FileUtils.getCachePath(), filename) | 
			
		
	
		
			
				
					|  |  |  |  |             //上传完删除cache文件 | 
			
		
	
		
			
				
					|  |  |  |  |             FileUtils.deleteFile("${FileUtils.getCachePath()}${File.separator}${filename}") | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |         App.db.bookChapterDao().getChapterList(book.bookUrl).forEach { chapter -> | 
			
		
	
		
			
				
					|  |  |  |  |             BookHelp.getContent(book, chapter).let { content -> | 
			
		
	
		
			
				
					|  |  |  |  |                 content?.split("\n")?.forEachIndexed { index, text -> | 
			
		
	
	
		
			
				
					|  |  |  | @ -61,8 +76,12 @@ class CacheViewModel(application: Application) : BaseViewModel(application) { | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     private fun export(file: File, book: Book) { | 
			
		
	
		
			
				
					|  |  |  |  |         FileUtils.createFileIfNotExist(file, "${book.name} 作者:${book.author}.txt") | 
			
		
	
		
			
				
					|  |  |  |  |         val filename = "${book.name} by ${book.author}.txt" | 
			
		
	
		
			
				
					|  |  |  |  |         FileUtils.createFileIfNotExist(file, filename) | 
			
		
	
		
			
				
					|  |  |  |  |             .writeText(getAllContents(book)) | 
			
		
	
		
			
				
					|  |  |  |  |         if(App.INSTANCE.getPrefBoolean(PreferKey.webDavExport,false)) { | 
			
		
	
		
			
				
					|  |  |  |  |             WebDavHelp.exportWebDav(file.absolutePath, filename)//导出到webdav | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |         App.db.bookChapterDao().getChapterList(book.bookUrl).forEach { chapter -> | 
			
		
	
		
			
				
					|  |  |  |  |             BookHelp.getContent(book, chapter).let { content -> | 
			
		
	
		
			
				
					|  |  |  |  |                 content?.split("\n")?.forEachIndexed { index, text -> | 
			
		
	
	
		
			
				
					|  |  |  | 
 |