From 645333a12bf6b6ad191d7e92b0b9ee3cf71b5af4 Mon Sep 17 00:00:00 2001 From: gedoor Date: Fri, 2 Apr 2021 22:46:58 +0800 Subject: [PATCH 01/12] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../source/debug/BookSourceDebugActivity.kt | 2 +- app/src/main/res/menu/book_source_debug.xml | 38 +++++++++++++++++++ app/src/main/res/menu/source_debug.xml | 19 ---------- 3 files changed, 39 insertions(+), 20 deletions(-) create mode 100644 app/src/main/res/menu/book_source_debug.xml delete mode 100644 app/src/main/res/menu/source_debug.xml diff --git a/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugActivity.kt index 76e0b81f6..977502eba 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugActivity.kt @@ -90,7 +90,7 @@ class BookSourceDebugActivity : VMBaseActivity + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/source_debug.xml b/app/src/main/res/menu/source_debug.xml deleted file mode 100644 index 706cb362a..000000000 --- a/app/src/main/res/menu/source_debug.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - \ No newline at end of file From 9d3d4824e78d19bd4bb414a931f7f4a52e1f9cb7 Mon Sep 17 00:00:00 2001 From: gedoor Date: Fri, 2 Apr 2021 23:07:08 +0800 Subject: [PATCH 02/12] =?UTF-8?q?debug=E6=B7=BB=E5=8A=A0=E6=9F=A5=E7=9C=8B?= =?UTF-8?q?=E6=BA=90=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/model/webBook/BookChapterList.kt | 2 +- .../io/legado/app/model/webBook/BookContent.kt | 1 + .../java/io/legado/app/model/webBook/BookInfo.kt | 1 + .../java/io/legado/app/model/webBook/BookList.kt | 1 + .../book/source/debug/BookSourceDebugActivity.kt | 14 ++++++++++++-- .../ui/book/source/debug/BookSourceDebugModel.kt | 15 ++++++++++++--- 6 files changed, 28 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt b/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt index 2e7ebfb38..0867fd95e 100644 --- a/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt +++ b/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt @@ -32,7 +32,7 @@ object BookChapterList { appCtx.getString(R.string.error_get_web_content, baseUrl) ) Debug.log(bookSource.bookSourceUrl, "≡获取成功:${baseUrl}") - + Debug.log(bookSource.bookSourceUrl, body, state = 30) val tocRule = bookSource.getTocRule() val nextUrlList = arrayListOf(baseUrl) var reverse = false diff --git a/app/src/main/java/io/legado/app/model/webBook/BookContent.kt b/app/src/main/java/io/legado/app/model/webBook/BookContent.kt index 574a9acdf..8eef8d50b 100644 --- a/app/src/main/java/io/legado/app/model/webBook/BookContent.kt +++ b/app/src/main/java/io/legado/app/model/webBook/BookContent.kt @@ -33,6 +33,7 @@ object BookContent { appCtx.getString(R.string.error_get_web_content, baseUrl) ) Debug.log(bookSource.bookSourceUrl, "≡获取成功:${baseUrl}") + Debug.log(bookSource.bookSourceUrl, body, state = 40) val mNextChapterUrl = if (!nextChapterUrl.isNullOrEmpty()) { nextChapterUrl } else { diff --git a/app/src/main/java/io/legado/app/model/webBook/BookInfo.kt b/app/src/main/java/io/legado/app/model/webBook/BookInfo.kt index 5bd30e2b3..bb3e99a39 100644 --- a/app/src/main/java/io/legado/app/model/webBook/BookInfo.kt +++ b/app/src/main/java/io/legado/app/model/webBook/BookInfo.kt @@ -29,6 +29,7 @@ object BookInfo { appCtx.getString(R.string.error_get_web_content, baseUrl) ) Debug.log(bookSource.bookSourceUrl, "≡获取成功:${baseUrl}") + Debug.log(bookSource.bookSourceUrl, body, state = 20) val analyzeRule = AnalyzeRule(book) analyzeRule.setContent(body).setBaseUrl(baseUrl) analyzeRule.setRedirectUrl(redirectUrl) diff --git a/app/src/main/java/io/legado/app/model/webBook/BookList.kt b/app/src/main/java/io/legado/app/model/webBook/BookList.kt index c24192ab2..64c0618d9 100644 --- a/app/src/main/java/io/legado/app/model/webBook/BookList.kt +++ b/app/src/main/java/io/legado/app/model/webBook/BookList.kt @@ -36,6 +36,7 @@ object BookList { ) ) Debug.log(bookSource.bookSourceUrl, "≡获取成功:${analyzeUrl.ruleUrl}") + Debug.log(bookSource.bookSourceUrl, body, state = 10) val analyzeRule = AnalyzeRule(variableBook) analyzeRule.setContent(body).setBaseUrl(baseUrl) analyzeRule.setRedirectUrl(baseUrl) diff --git a/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugActivity.kt index 977502eba..ffb21b7bf 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugActivity.kt @@ -96,8 +96,18 @@ class BookSourceDebugActivity : VMBaseActivity { - qrCodeResult.launch(null) + R.id.menu_scan -> qrCodeResult.launch(null) + R.id.menu_search_src -> { + + } + R.id.menu_book_src -> { + + } + R.id.menu_toc_src -> { + + } + R.id.menu_content_src -> { + } R.id.menu_help -> showHelp() } diff --git a/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugModel.kt b/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugModel.kt index 3ce462f24..43e969e97 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugModel.kt @@ -10,8 +10,11 @@ class BookSourceDebugModel(application: Application) : BaseViewModel(application Debug.Callback { private var webBook: WebBook? = null - - private var callback: ((Int, String)-> Unit)? = null + private var callback: ((Int, String) -> Unit)? = null + var searchSrc: String? = null + var bookSrc: String? = null + var tocSrc: String? = null + var contentSrc: String? = null fun init(sourceUrl: String?) { sourceUrl?.let { @@ -39,7 +42,13 @@ class BookSourceDebugModel(application: Application) : BaseViewModel(application } override fun printLog(state: Int, msg: String) { - callback?.invoke(state, msg) + when (state) { + 10 -> searchSrc = msg + 20 -> bookSrc = msg + 30 -> tocSrc = msg + 40 -> contentSrc = msg + else -> callback?.invoke(state, msg) + } } override fun onCleared() { From 9361c488b4010c3d5c0c9331258fdc0130a56742 Mon Sep 17 00:00:00 2001 From: gedoor Date: Fri, 2 Apr 2021 23:09:24 +0800 Subject: [PATCH 03/12] =?UTF-8?q?debug=E6=B7=BB=E5=8A=A0=E6=9F=A5=E7=9C=8B?= =?UTF-8?q?=E6=BA=90=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/assets/updateLog.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 344463246..6cb716e85 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -3,6 +3,10 @@ * 关注合作公众号 **[小说拾遗]** 获取好看的小说。 * 旧版数据导入教程:先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 +**2021/04/02** +* 修复bug +* 书源调试添加源码查看 + **2021/03/31** * 优化epubLib by ag2s20150909 * 升级库,修改弃用方法 From e8a6714b1604d020c2ff55cfa983e26a4093855e Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 3 Apr 2021 21:48:12 +0800 Subject: [PATCH 04/12] =?UTF-8?q?debug=E6=B7=BB=E5=8A=A0=E6=9F=A5=E7=9C=8B?= =?UTF-8?q?=E6=BA=90=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../source/debug/BookSourceDebugActivity.kt | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugActivity.kt index ffb21b7bf..42f85da7c 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugActivity.kt @@ -97,18 +97,14 @@ class BookSourceDebugActivity : VMBaseActivity qrCodeResult.launch(null) - R.id.menu_search_src -> { - - } - R.id.menu_book_src -> { - - } - R.id.menu_toc_src -> { - - } - R.id.menu_content_src -> { - - } + R.id.menu_search_src -> + TextDialog.show(supportFragmentManager, viewModel.searchSrc) + R.id.menu_book_src -> + TextDialog.show(supportFragmentManager, viewModel.bookSrc) + R.id.menu_toc_src -> + TextDialog.show(supportFragmentManager, viewModel.tocSrc) + R.id.menu_content_src -> + TextDialog.show(supportFragmentManager, viewModel.contentSrc) R.id.menu_help -> showHelp() } return super.onCompatOptionsItemSelected(item) From c37e00f2fd7fb9100fd21bde0c9b75ce6de9ea57 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 3 Apr 2021 22:21:03 +0800 Subject: [PATCH 05/12] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=AF=BC=E5=87=BAepub?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/constant/PreferKey.kt | 1 + .../main/java/io/legado/app/help/AppConfig.kt | 6 ++++++ .../legado/app/ui/book/cache/CacheActivity.kt | 17 +++++++++++++++-- .../legado/app/ui/book/cache/CacheViewModel.kt | 10 +++++----- app/src/main/res/menu/book_cache.xml | 5 +++++ app/src/main/res/values-zh-rHK/strings.xml | 1 + app/src/main/res/values-zh-rTW/strings.xml | 1 + app/src/main/res/values-zh/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 9 files changed, 36 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/io/legado/app/constant/PreferKey.kt b/app/src/main/java/io/legado/app/constant/PreferKey.kt index e9801a743..7e8f68da5 100644 --- a/app/src/main/java/io/legado/app/constant/PreferKey.kt +++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt @@ -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" diff --git a/app/src/main/java/io/legado/app/help/AppConfig.kt b/app/src/main/java/io/legado/app/help/AppConfig.kt index 7468fbef5..4e4ce33c9 100644 --- a/app/src/main/java/io/legado/app/help/AppConfig.kt +++ b/app/src/main/java/io/legado/app/help/AppConfig.kt @@ -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) diff --git a/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt b/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt index 52feb9489..23b4289f3 100644 --- a/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt @@ -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() 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() 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 { diff --git a/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt b/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt index e60a7d3d0..ef0cc2aea 100644 --- a/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt @@ -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) diff --git a/app/src/main/res/menu/book_cache.xml b/app/src/main/res/menu/book_cache.xml index a0dca539f..42c873c82 100644 --- a/app/src/main/res/menu/book_cache.xml +++ b/app/src/main/res/menu/book_cache.xml @@ -37,6 +37,11 @@ android:title="@string/export_folder" app:showAsAction="never" /> + + 使用自定义中文分行 图片样式 系统TTS + 导出格式 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 6ea300b43..ab85be403 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -813,5 +813,6 @@ 调试 图片样式 系统TTS + 导出格式 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 910a08008..196d02455 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -815,5 +815,6 @@ 使用自定义中文分行 图片样式 系统TTS + 导出格式 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 57077eafb..983a21e48 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -818,5 +818,6 @@ 使用自定义中文分行 Image style System TTS + 导出格式 From c13dd1d3719d97fce4cc834930cfbe2810c08cfd Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 3 Apr 2021 23:07:14 +0800 Subject: [PATCH 06/12] =?UTF-8?q?=E6=8D=A2=E6=BA=90=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E6=A0=A1=E9=AA=8C=E4=BD=9C=E8=80=85=E9=80=89?= =?UTF-8?q?=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/assets/updateLog.md | 2 ++ .../java/io/legado/app/constant/PreferKey.kt | 1 + .../main/java/io/legado/app/help/AppConfig.kt | 8 +++++++- .../ui/book/changesource/ChangeSourceDialog.kt | 6 ++++++ .../book/changesource/ChangeSourceViewModel.kt | 16 ++++++++++------ app/src/main/res/menu/change_source.xml | 6 ++++++ app/src/main/res/values-zh-rHK/strings.xml | 1 + app/src/main/res/values-zh-rTW/strings.xml | 1 + app/src/main/res/values-zh/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 10 files changed, 36 insertions(+), 7 deletions(-) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 6cb716e85..50cf85aef 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -6,6 +6,8 @@ **2021/04/02** * 修复bug * 书源调试添加源码查看 +* 添加导出epub by ag2s20150909 +* 换源添加是否校验作者选项 **2021/03/31** * 优化epubLib by ag2s20150909 diff --git a/app/src/main/java/io/legado/app/constant/PreferKey.kt b/app/src/main/java/io/legado/app/constant/PreferKey.kt index 7e8f68da5..72d260d8a 100644 --- a/app/src/main/java/io/legado/app/constant/PreferKey.kt +++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt @@ -41,6 +41,7 @@ object PreferKey { const val webDavCreateDir = "webDavCreateDir" const val exportToWebDav = "webDavCacheBackup" const val exportType = "exportType" + const val changeSourceCheckAuthor = "changeSourceCheckAuthor" const val changeSourceLoadToc = "changeSourceLoadToc" const val changeSourceLoadInfo = "changeSourceLoadInfo" const val chineseConverterType = "chineseConverterType" diff --git a/app/src/main/java/io/legado/app/help/AppConfig.kt b/app/src/main/java/io/legado/app/help/AppConfig.kt index 4e4ce33c9..c72078564 100644 --- a/app/src/main/java/io/legado/app/help/AppConfig.kt +++ b/app/src/main/java/io/legado/app/help/AppConfig.kt @@ -167,6 +167,12 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener { appCtx.putPrefInt(PreferKey.exportType, value) } + var changeSourceCheckAuthor: Boolean + get() = appCtx.getPrefBoolean(PreferKey.changeSourceCheckAuthor) + set(value) { + appCtx.putPrefBoolean(PreferKey.changeSourceCheckAuthor, value) + } + val autoChangeSource: Boolean get() = appCtx.getPrefBoolean(PreferKey.autoChangeSource, true) @@ -182,7 +188,7 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener { val mediaButtonOnExit get() = appCtx.getPrefBoolean("mediaButtonOnExit", true) - val replaceEnableDefault get() = appCtx.getPrefBoolean(PreferKey.replaceEnableDefault, true) + val replaceEnableDefault get() = appCtx.getPrefBoolean(PreferKey.replaceEnableDefault, true) private fun getPrefUserAgent(): String { val ua = appCtx.getPrefString(PreferKey.userAgent) diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt index e6be2e4be..7b858949a 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt @@ -84,6 +84,8 @@ class ChangeSourceDialog : BaseDialogFragment(), binding.toolBar.inflateMenu(R.menu.change_source) binding.toolBar.menu.applyTint(requireContext()) binding.toolBar.setOnMenuItemClickListener(this) + binding.toolBar.menu.findItem(R.id.menu_check_author) + ?.isChecked = AppConfig.changeSourceCheckAuthor binding.toolBar.menu.findItem(R.id.menu_load_info) ?.isChecked = AppConfig.changeSourceLoadInfo binding.toolBar.menu.findItem(R.id.menu_load_toc) @@ -160,6 +162,10 @@ class ChangeSourceDialog : BaseDialogFragment(), override fun onMenuItemClick(item: MenuItem?): Boolean { when (item?.itemId) { + R.id.menu_check_author -> { + AppConfig.changeSourceCheckAuthor = !item.isChecked + item.isChecked = !item.isChecked + } R.id.menu_load_toc -> { putPrefBoolean(PreferKey.changeSourceLoadToc, !item.isChecked) item.isChecked = !item.isChecked diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt index ae3114e04..03f49c28e 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt @@ -130,15 +130,19 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio .timeout(60000L) .onSuccess(IO) { it.forEach { searchBook -> - if (searchBook.name == name && searchBook.author == author) { - if (searchBook.latestChapterTitle.isNullOrEmpty()) { - if (AppConfig.changeSourceLoadInfo || AppConfig.changeSourceLoadToc) { - loadBookInfo(webBook, searchBook.toBook()) + if (searchBook.name == name) { + if ((AppConfig.changeSourceCheckAuthor && searchBook.author == author) + || !AppConfig.changeSourceCheckAuthor + ) { + if (searchBook.latestChapterTitle.isNullOrEmpty()) { + if (AppConfig.changeSourceLoadInfo || AppConfig.changeSourceLoadToc) { + loadBookInfo(webBook, searchBook.toBook()) + } else { + searchFinish(searchBook) + } } else { searchFinish(searchBook) } - } else { - searchFinish(searchBook) } } } diff --git a/app/src/main/res/menu/change_source.xml b/app/src/main/res/menu/change_source.xml index ecee5ca02..347877bde 100644 --- a/app/src/main/res/menu/change_source.xml +++ b/app/src/main/res/menu/change_source.xml @@ -23,6 +23,12 @@ android:title="@string/book_source_manage" app:showAsAction="never" /> + + 图片样式 系统TTS 导出格式 + 校验作者 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index ab85be403..2920fcc23 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -814,5 +814,6 @@ 图片样式 系统TTS 导出格式 + 校验作者 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 196d02455..f64b848d7 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -816,5 +816,6 @@ 图片样式 系统TTS 导出格式 + 校验作者 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 983a21e48..4cb2fa208 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -819,5 +819,6 @@ Image style System TTS 导出格式 + 校验作者 From 5898ecc2a213fc2aa60ad230eff0ac1b8ee03778 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 4 Apr 2021 09:44:10 +0800 Subject: [PATCH 07/12] =?UTF-8?q?=E6=8D=A2=E6=BA=90=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E6=A0=A1=E9=AA=8C=E4=BD=9C=E8=80=85=E9=80=89?= =?UTF-8?q?=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/data/dao/SearchBookDao.kt | 2 +- .../ui/book/changesource/ChangeSourceAdapter.kt | 9 ++++++++- .../ui/book/changesource/ChangeSourceDialog.kt | 3 ++- .../book/changesource/ChangeSourceViewModel.kt | 17 ++++++++++------- app/src/main/res/layout/item_change_source.xml | 11 +++++++++++ 5 files changed, 32 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/dao/SearchBookDao.kt b/app/src/main/java/io/legado/app/data/dao/SearchBookDao.kt index 234e24e0d..9618ad317 100644 --- a/app/src/main/java/io/legado/app/data/dao/SearchBookDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/SearchBookDao.kt @@ -27,7 +27,7 @@ interface SearchBookDao { select t1.name, t1.author, t1.origin, t1.originName, t1.coverUrl, t1.bookUrl, t1.type, t1.time, t1.intro, t1.kind, t1.latestChapterTitle, t1.tocUrl, t1.variable, t1.wordCount, t2.customOrder as originOrder from searchBooks as t1 inner join book_sources as t2 on t1.origin = t2.bookSourceUrl - where t1.name = :name and t1.author = :author and t2.enabled = 1 and t2.bookSourceGroup like '%'||:sourceGroup||'%' + where t1.name = :name and t1.author like '%'||:author||'%' and t2.enabled = 1 and t2.bookSourceGroup like '%'||:sourceGroup||'%' order by t2.customOrder """ ) diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceAdapter.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceAdapter.kt index 70196a543..e35f00e89 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceAdapter.kt @@ -5,6 +5,7 @@ import android.os.Bundle import android.view.View import android.view.ViewGroup import androidx.appcompat.widget.PopupMenu +import androidx.core.view.isGone import androidx.recyclerview.widget.DiffUtil import io.legado.app.R import io.legado.app.base.adapter.DiffRecyclerAdapter @@ -16,7 +17,11 @@ import io.legado.app.utils.visible import splitties.views.onLongClick -class ChangeSourceAdapter(context: Context, val callBack: CallBack) : +class ChangeSourceAdapter( + context: Context, + val viewModel: ChangeSourceViewModel, + val callBack: CallBack +) : DiffRecyclerAdapter(context) { override val diffItemCallback: DiffUtil.ItemCallback @@ -46,6 +51,8 @@ class ChangeSourceAdapter(context: Context, val callBack: CallBack) : binding.apply { if (bundle == null) { tvOrigin.text = item.originName + tvAuthor.text = context.getString(R.string.author_show, item.author) + tvAuthor.isGone = viewModel.author == item.author tvLast.text = item.getDisplayLastChapterTitle() if (callBack.bookUrl == item.bookUrl) { ivChecked.visible() diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt index 7b858949a..9040f7d13 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt @@ -93,7 +93,7 @@ class ChangeSourceDialog : BaseDialogFragment(), } private fun initRecyclerView() { - adapter = ChangeSourceAdapter(requireContext(), this) + adapter = ChangeSourceAdapter(requireContext(), viewModel, this) binding.recyclerView.layoutManager = LinearLayoutManager(context) binding.recyclerView.addItemDecoration(VerticalDivider(requireContext())) binding.recyclerView.adapter = adapter @@ -165,6 +165,7 @@ class ChangeSourceDialog : BaseDialogFragment(), R.id.menu_check_author -> { AppConfig.changeSourceCheckAuthor = !item.isChecked item.isChecked = !item.isChecked + viewModel.loadDbSearchBook() } R.id.menu_load_toc -> { putPrefBoolean(PreferKey.changeSourceLoadToc, !item.isChecked) diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt index 03f49c28e..6197725bd 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt @@ -63,12 +63,15 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio execute { searchBooks.clear() upAdapter() - appDb.searchBookDao.getChangeSourceSearch(name, author, searchGroup).let { - searchBooks.addAll(it) - searchBooksLiveData.postValue(searchBooks.toList()) - if (it.size <= 1) { - startSearch() - } + val sbs = if (AppConfig.changeSourceCheckAuthor) { + appDb.searchBookDao.getChangeSourceSearch(name, author, searchGroup) + } else { + appDb.searchBookDao.getChangeSourceSearch(name, "", searchGroup) + } + searchBooks.addAll(sbs) + searchBooksLiveData.postValue(searchBooks.toList()) + if (sbs.size <= 1) { + startSearch() } } } @@ -131,7 +134,7 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio .onSuccess(IO) { it.forEach { searchBook -> if (searchBook.name == name) { - if ((AppConfig.changeSourceCheckAuthor && searchBook.author == author) + if ((AppConfig.changeSourceCheckAuthor && searchBook.author.contains(author)) || !AppConfig.changeSourceCheckAuthor ) { if (searchBook.latestChapterTitle.isNullOrEmpty()) { diff --git a/app/src/main/res/layout/item_change_source.xml b/app/src/main/res/layout/item_change_source.xml index db773e7fc..0bebee9fe 100644 --- a/app/src/main/res/layout/item_change_source.xml +++ b/app/src/main/res/layout/item_change_source.xml @@ -14,6 +14,17 @@ android:textColor="@color/primaryText" app:layout_constraintTop_toTopOf="parent" app:layout_constraintLeft_toLeftOf="parent" + app:layout_constraintRight_toLeftOf="@+id/tv_author" /> + + Date: Sun, 4 Apr 2021 10:04:15 +0800 Subject: [PATCH 08/12] =?UTF-8?q?=E6=8D=A2=E6=BA=90=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E6=A0=A1=E9=AA=8C=E4=BD=9C=E8=80=85=E9=80=89?= =?UTF-8?q?=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/ui/book/changesource/ChangeSourceAdapter.kt | 7 ++++++- .../legado/app/ui/book/changesource/ChangeSourceDialog.kt | 7 ++++++- app/src/main/res/layout/item_change_source.xml | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceAdapter.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceAdapter.kt index e35f00e89..1222391cc 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceAdapter.kt @@ -51,7 +51,12 @@ class ChangeSourceAdapter( binding.apply { if (bundle == null) { tvOrigin.text = item.originName - tvAuthor.text = context.getString(R.string.author_show, item.author) + val author = if (item.author.isEmpty()) { + context.getString(R.string.empty) + } else { + item.author + } + tvAuthor.text = context.getString(R.string.author_show, author) tvAuthor.isGone = viewModel.author == item.author tvLast.text = item.getDisplayLastChapterTitle() if (callBack.bookUrl == item.bookUrl) { diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt index 9040f7d13..dafd9a40f 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt @@ -77,7 +77,12 @@ class ChangeSourceDialog : BaseDialogFragment(), private fun showTitle() { binding.toolBar.title = viewModel.name - binding.toolBar.subtitle = getString(R.string.author_show, viewModel.author) + val author = if (viewModel.author.isBlank()) { + getString(R.string.empty) + } else { + viewModel.author + } + binding.toolBar.subtitle = getString(R.string.author_show, author) } private fun initMenu() { diff --git a/app/src/main/res/layout/item_change_source.xml b/app/src/main/res/layout/item_change_source.xml index 0bebee9fe..809b2b93d 100644 --- a/app/src/main/res/layout/item_change_source.xml +++ b/app/src/main/res/layout/item_change_source.xml @@ -22,7 +22,7 @@ android:layout_height="wrap_content" android:singleLine="true" android:textColor="@color/primaryText" - android:maxWidth="30dp" + android:maxWidth="160dp" android:visibility="gone" app:layout_constraintTop_toTopOf="parent" app:layout_constraintRight_toLeftOf="@+id/iv_checked" /> From 84b6fcc6db6c921ba1e89d356b2834ea8e25037a Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 4 Apr 2021 10:27:17 +0800 Subject: [PATCH 09/12] =?UTF-8?q?=E6=8D=A2=E6=BA=90=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E6=A0=A1=E9=AA=8C=E4=BD=9C=E8=80=85=E9=80=89?= =?UTF-8?q?=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/changesource/ChangeSourceAdapter.kt | 9 +-------- app/src/main/res/layout/item_change_source.xml | 7 +++---- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceAdapter.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceAdapter.kt index 1222391cc..b5298d4b7 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceAdapter.kt @@ -5,7 +5,6 @@ import android.os.Bundle import android.view.View import android.view.ViewGroup import androidx.appcompat.widget.PopupMenu -import androidx.core.view.isGone import androidx.recyclerview.widget.DiffUtil import io.legado.app.R import io.legado.app.base.adapter.DiffRecyclerAdapter @@ -51,13 +50,7 @@ class ChangeSourceAdapter( binding.apply { if (bundle == null) { tvOrigin.text = item.originName - val author = if (item.author.isEmpty()) { - context.getString(R.string.empty) - } else { - item.author - } - tvAuthor.text = context.getString(R.string.author_show, author) - tvAuthor.isGone = viewModel.author == item.author + tvAuthor.text = item.author tvLast.text = item.getDisplayLastChapterTitle() if (callBack.bookUrl == item.bookUrl) { ivChecked.visible() diff --git a/app/src/main/res/layout/item_change_source.xml b/app/src/main/res/layout/item_change_source.xml index 809b2b93d..28d02caca 100644 --- a/app/src/main/res/layout/item_change_source.xml +++ b/app/src/main/res/layout/item_change_source.xml @@ -23,7 +23,6 @@ android:singleLine="true" android:textColor="@color/primaryText" android:maxWidth="160dp" - android:visibility="gone" app:layout_constraintTop_toTopOf="parent" app:layout_constraintRight_toLeftOf="@+id/iv_checked" /> @@ -40,9 +39,9 @@ Date: Sun, 4 Apr 2021 10:38:38 +0800 Subject: [PATCH 10/12] =?UTF-8?q?=E6=8D=A2=E6=BA=90=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E6=A0=A1=E9=AA=8C=E4=BD=9C=E8=80=85=E9=80=89?= =?UTF-8?q?=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/ui/book/changesource/ChangeSourceDialog.kt | 7 +------ app/src/main/res/layout/item_change_source.xml | 6 +++++- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt index dafd9a40f..e83118039 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt @@ -77,12 +77,7 @@ class ChangeSourceDialog : BaseDialogFragment(), private fun showTitle() { binding.toolBar.title = viewModel.name - val author = if (viewModel.author.isBlank()) { - getString(R.string.empty) - } else { - viewModel.author - } - binding.toolBar.subtitle = getString(R.string.author_show, author) + binding.toolBar.subtitle = viewModel.author } private fun initMenu() { diff --git a/app/src/main/res/layout/item_change_source.xml b/app/src/main/res/layout/item_change_source.xml index 28d02caca..b47da7d06 100644 --- a/app/src/main/res/layout/item_change_source.xml +++ b/app/src/main/res/layout/item_change_source.xml @@ -1,10 +1,14 @@ + android:paddingLeft="10dp" + android:paddingTop="10dp" + android:paddingBottom="10dp" + tools:ignore="RtlHardcoded,RtlSymmetry"> Date: Sun, 4 Apr 2021 11:17:55 +0800 Subject: [PATCH 11/12] =?UTF-8?q?=E6=8D=A2=E6=BA=90=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E6=A0=A1=E9=AA=8C=E4=BD=9C=E8=80=85=E9=80=89?= =?UTF-8?q?=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/res/layout/item_change_source.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/res/layout/item_change_source.xml b/app/src/main/res/layout/item_change_source.xml index b47da7d06..fa04abeda 100644 --- a/app/src/main/res/layout/item_change_source.xml +++ b/app/src/main/res/layout/item_change_source.xml @@ -25,7 +25,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:singleLine="true" - android:textColor="@color/primaryText" + android:textColor="@color/secondaryText" android:maxWidth="160dp" app:layout_constraintTop_toTopOf="parent" app:layout_constraintRight_toLeftOf="@+id/iv_checked" /> From 980c3e0b0961bb364c49dacf7b35ef57d76e4f6e Mon Sep 17 00:00:00 2001 From: no bk Date: Sun, 4 Apr 2021 13:59:56 +0800 Subject: [PATCH 12/12] =?UTF-8?q?=E4=BB=8E=E6=96=87=E4=BB=B6=E5=90=8D'?= =?UTF-8?q?=E4=B9=A6=E5=90=8D=20by=20=E4=BD=9C=E8=80=85.txt'=E6=88=96.epub?= =?UTF-8?q?=E6=8F=90=E5=8F=96=E4=B9=A6=E5=90=8D=E3=80=81=E4=BD=9C=E8=80=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/model/localBook/LocalBook.kt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt b/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt index 19e293b2b..142571054 100644 --- a/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt +++ b/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt @@ -72,6 +72,16 @@ object LocalBook { if (smhStart != -1 && smhEnd != -1) { name = (name.substring(smhStart + 1, smhEnd)) } + if (author == "" && fileName.contains(" by ")) { + val rstr = fileName.reversed() + // find last ' by ' near '.txt' or '.epub' using reversed string + val pattern = """^(txt|bupe)\.(.*) yb (.*)$""".toRegex() + val matches = pattern.findAll(input = rstr) + matches.forEach { matchResult -> + name = matchResult.groupValues[3].reversed() + author = matchResult.groupValues[2].reversed() + } + } val book = Book( bookUrl = path, name = name,