添加导出epub

pull/931/head
gedoor 4 years ago
parent e8a6714b16
commit c37e00f2fd
  1. 1
      app/src/main/java/io/legado/app/constant/PreferKey.kt
  2. 6
      app/src/main/java/io/legado/app/help/AppConfig.kt
  3. 17
      app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt
  4. 10
      app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt
  5. 5
      app/src/main/res/menu/book_cache.xml
  6. 1
      app/src/main/res/values-zh-rHK/strings.xml
  7. 1
      app/src/main/res/values-zh-rTW/strings.xml
  8. 1
      app/src/main/res/values-zh/strings.xml
  9. 1
      app/src/main/res/values/strings.xml

@ -40,6 +40,7 @@ object PreferKey {
const val webDavPassword = "web_dav_password"
const val webDavCreateDir = "webDavCreateDir"
const val exportToWebDav = "webDavCacheBackup"
const val exportType = "exportType"
const val changeSourceLoadToc = "changeSourceLoadToc"
const val changeSourceLoadInfo = "changeSourceLoadInfo"
const val chineseConverterType = "chineseConverterType"

@ -161,6 +161,12 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
appCtx.putPrefBoolean(PreferKey.exportToWebDav, value)
}
var exportType: Int
get() = appCtx.getPrefInt(PreferKey.exportType)
set(value) {
appCtx.putPrefInt(PreferKey.exportType, value)
}
val autoChangeSource: Boolean
get() = appCtx.getPrefBoolean(PreferKey.autoChangeSource, true)

@ -23,6 +23,7 @@ import io.legado.app.databinding.DialogEditTextBinding
import io.legado.app.help.AppConfig
import io.legado.app.help.BookHelp
import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.dialogs.selector
import io.legado.app.service.help.CacheBook
import io.legado.app.ui.document.FilePicker
import io.legado.app.ui.document.FilePickerParam
@ -122,6 +123,7 @@ class CacheActivity : VMBaseActivity<ActivityCacheBookBinding, CacheViewModel>()
R.id.menu_enable_replace -> AppConfig.exportUseReplace = !item.isChecked
R.id.menu_export_web_dav -> AppConfig.exportToWebDav = !item.isChecked
R.id.menu_export_folder -> export(-1)
R.id.menu_export_type -> showExportTypeConfig()
R.id.menu_export_charset -> showCharsetConfig()
R.id.menu_log ->
TextListDialog.show(supportFragmentManager, getString(R.string.log), CacheBook.logs)
@ -239,12 +241,23 @@ class CacheActivity : VMBaseActivity<ActivityCacheBookBinding, CacheViewModel>()
adapter.getItem(exportPosition)?.let { book ->
Snackbar.make(binding.titleBar, R.string.exporting, Snackbar.LENGTH_INDEFINITE)
.show()
viewModel.exportEPUB(path, book) {
binding.titleBar.snackbar(it)
when (AppConfig.exportType) {
1 -> viewModel.exportEPUB(path, book) {
binding.titleBar.snackbar(it)
}
else -> viewModel.export(path, book) {
binding.titleBar.snackbar(it)
}
}
}
}
private fun showExportTypeConfig() {
selector(R.string.export_type, arrayListOf("txt", "epub")) { _, i ->
AppConfig.exportType = i
}
}
private fun showCharsetConfig() {
alert(R.string.set_charset) {
val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply {

@ -106,7 +106,7 @@ class CacheViewModel(application: Application) : BaseViewModel(application) {
}
}
private suspend fun getAllContents(book: Book, append: (text: String) -> Unit) {
private fun getAllContents(book: Book, append: (text: String) -> Unit) {
val useReplace = AppConfig.exportUseReplace
val contentProcessor = ContentProcessor(book.name, book.origin)
append("${book.name}\n${context.getString(R.string.author_show, book.author)}")
@ -159,13 +159,13 @@ class CacheViewModel(application: Application) : BaseViewModel(application) {
}
@Suppress("BlockingMethodInNonBlockingContext")
private suspend fun exportEpub(doc: DocumentFile, book: Book) {
private fun exportEpub(doc: DocumentFile, book: Book) {
val filename = "${book.name} by ${book.author}.epub"
DocumentUtils.delete(doc, filename)
val epubBook = EpubBook()
epubBook.version = "2.0"
//set metadata
setEpubMetadata(book,epubBook)
setEpubMetadata(book, epubBook)
//set cover
setCover(book, epubBook)
@ -187,12 +187,12 @@ class CacheViewModel(application: Application) : BaseViewModel(application) {
}
}
private suspend fun exportEpub(file: File, book: Book) {
private fun exportEpub(file: File, book: Book) {
val filename = "${book.name} by ${book.author}.epub"
val epubBook = EpubBook()
epubBook.version = "2.0"
//set metadata
setEpubMetadata(book,epubBook)
setEpubMetadata(book, epubBook)
//set cover
setCover(book, epubBook)

@ -37,6 +37,11 @@
android:title="@string/export_folder"
app:showAsAction="never" />
<item
android:id="@+id/menu_export_type"
android:title="@string/export_type"
app:showAsAction="never" />
<item
android:id="@+id/menu_export_charset"
android:title="@string/export_charset"

@ -811,5 +811,6 @@
<string name="use_zh_layout">使用自定义中文分行</string>
<string name="image_style">图片样式</string>
<string name="system_tts">系统TTS</string>
<string name="export_type">导出格式</string>
</resources>

@ -813,5 +813,6 @@
<string name="debug">调试</string>
<string name="image_style">图片样式</string>
<string name="system_tts">系统TTS</string>
<string name="export_type">导出格式</string>
</resources>

@ -815,5 +815,6 @@
<string name="use_zh_layout">使用自定义中文分行</string>
<string name="image_style">图片样式</string>
<string name="system_tts">系统TTS</string>
<string name="export_type">导出格式</string>
</resources>

@ -818,5 +818,6 @@
<string name="use_zh_layout">使用自定义中文分行</string>
<string name="image_style">Image style</string>
<string name="system_tts">System TTS</string>
<string name="export_type">导出格式</string>
</resources>

Loading…
Cancel
Save