diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 344463246..50cf85aef 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -3,6 +3,12 @@ * 关注合作公众号 **[小说拾遗]** 获取好看的小说。 * 旧版数据导入教程:先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 +**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 e9801a743..72d260d8a 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,8 @@ object PreferKey { const val webDavPassword = "web_dav_password" 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/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/help/AppConfig.kt b/app/src/main/java/io/legado/app/help/AppConfig.kt index 7468fbef5..c72078564 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,18 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener { appCtx.putPrefBoolean(PreferKey.exportToWebDav, value) } + var exportType: Int + get() = appCtx.getPrefInt(PreferKey.exportType) + set(value) { + 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) @@ -176,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/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, 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/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/java/io/legado/app/ui/book/changesource/ChangeSourceAdapter.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceAdapter.kt index 70196a543..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 @@ -16,7 +16,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 +50,7 @@ class ChangeSourceAdapter(context: Context, val callBack: CallBack) : binding.apply { if (bundle == null) { tvOrigin.text = item.originName + tvAuthor.text = 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 e6be2e4be..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,13 +77,15 @@ class ChangeSourceDialog : BaseDialogFragment(), private fun showTitle() { binding.toolBar.title = viewModel.name - binding.toolBar.subtitle = getString(R.string.author_show, viewModel.author) + binding.toolBar.subtitle = viewModel.author } private fun initMenu() { 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) @@ -91,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 @@ -160,6 +162,11 @@ 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 + viewModel.loadDbSearchBook() + } 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..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() } } } @@ -130,15 +133,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.contains(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/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..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 @@ -90,15 +90,21 @@ class BookSourceDebugActivity : VMBaseActivity { - qrCodeResult.launch(null) - } + R.id.menu_scan -> qrCodeResult.launch(null) + 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) 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() { diff --git a/app/src/main/res/layout/item_change_source.xml b/app/src/main/res/layout/item_change_source.xml index db773e7fc..fa04abeda 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"> + + + + + + + + + + + + + + + + + + + \ No newline at end of file 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" /> + + - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 59a6ea723..1df7c6415 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -811,5 +811,7 @@ 使用自定义中文分行 图片样式 系统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..2920fcc23 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -813,5 +813,7 @@ 调试 图片样式 系统TTS + 导出格式 + 校验作者 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 910a08008..f64b848d7 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -815,5 +815,7 @@ 使用自定义中文分行 图片样式 系统TTS + 导出格式 + 校验作者 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 57077eafb..4cb2fa208 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -818,5 +818,7 @@ 使用自定义中文分行 Image style System TTS + 导出格式 + 校验作者