diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 2ba3ec7a5..e0f13a0c8 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -3,6 +3,9 @@ * 关注合作公众号 **[小说拾遗]()** 获取好看的小说。 - 旧版数据导入教程:先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 +**2020/08/19** +* 选择文本替换时带入书名和书源 + **2020/08/16** * 添加亮度调节控件显示开关 * 添加应用内语言切换 diff --git a/app/src/main/java/io/legado/app/service/help/ReadBook.kt b/app/src/main/java/io/legado/app/service/help/ReadBook.kt index 7878cb1c2..afb7702a8 100644 --- a/app/src/main/java/io/legado/app/service/help/ReadBook.kt +++ b/app/src/main/java/io/legado/app/service/help/ReadBook.kt @@ -7,6 +7,7 @@ import io.legado.app.R import io.legado.app.constant.BookType import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookChapter +import io.legado.app.data.entities.BookSource import io.legado.app.help.AppConfig import io.legado.app.help.BookHelp import io.legado.app.help.IntentDataHelp @@ -35,6 +36,7 @@ object ReadBook { var prevTextChapter: TextChapter? = null var curTextChapter: TextChapter? = null var nextTextChapter: TextChapter? = null + var bookSource: BookSource? = null var webBook: WebBook? = null var msg: String? = null private val loadingChapters = arrayListOf() @@ -54,14 +56,16 @@ object ReadBook { } fun upWebBook(book: Book) { - webBook = if (book.origin == BookType.local) { - null + if (book.origin == BookType.local) { + bookSource = null + webBook = null } else { - val bookSource = App.db.bookSourceDao().getBookSource(book.origin) - if (bookSource != null) { - WebBook(bookSource) - } else { - null + App.db.bookSourceDao().getBookSource(book.origin)?.let { + bookSource = it + webBook = WebBook(it) + } ?: let { + bookSource = null + webBook = null } } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index 512d22a6f..7ad4008ac 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -470,7 +470,18 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo override fun onMenuItemSelected(itemId: Int): Boolean { when (itemId) { R.id.menu_replace -> { - ReplaceEditDialog.show(supportFragmentManager, pattern = selectedText) + val scopes = arrayListOf() + ReadBook.book?.name?.let { + scopes.add(it) + } + ReadBook.bookSource?.bookSourceUrl?.let { + scopes.add(it) + } + ReplaceEditDialog.show( + supportFragmentManager, + pattern = selectedText, + scope = scopes.joinToString(";") + ) return true } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt index 0c5c63aa8..bc7e8c5b6 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt @@ -163,7 +163,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at ReadBook.book!!, textPage.chapterIndex, textChar.charData, - textChar.charData, + null, true )?.let { canvas.drawBitmap(it, null, rectF, null) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt index 0084bfc5f..b6109e9d3 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt @@ -31,7 +31,7 @@ object ImageProvider { indexCache[src] = bitmap } - fun getImage(book: Book, chapterIndex: Int, src: String, baseUrl: String, onUi: Boolean = false): Bitmap? { + fun getImage(book: Book, chapterIndex: Int, src: String, referrer: String?, onUi: Boolean = false): Bitmap? { getCache(chapterIndex, src)?.let { return it } @@ -48,8 +48,8 @@ object ImageProvider { out.flush() out.close() } - } else if (!onUi) { - HttpHelper.getBytes(src, baseUrl)?.let { + } else if (!onUi && referrer != null) { + HttpHelper.getBytes(src, referrer)?.let { FileUtils.createFileIfNotExist(vFile.absolutePath).writeBytes(it) } } diff --git a/app/src/main/java/io/legado/app/ui/replacerule/edit/ReplaceEditDialog.kt b/app/src/main/java/io/legado/app/ui/replacerule/edit/ReplaceEditDialog.kt index 60235a279..6b207cd0b 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/edit/ReplaceEditDialog.kt +++ b/app/src/main/java/io/legado/app/ui/replacerule/edit/ReplaceEditDialog.kt @@ -35,15 +35,17 @@ class ReplaceEditDialog : BaseDialogFragment(), fragmentManager: FragmentManager, id: Long = -1, pattern: String? = null, - isRegex: Boolean = false + isRegex: Boolean = false, + scope: String? = null ) { val dialog = ReplaceEditDialog() val bundle = Bundle() bundle.putLong("id", id) bundle.putString("pattern", pattern) bundle.putBoolean("isRegex", isRegex) + bundle.putString("scope", scope) dialog.arguments = bundle - dialog.show(fragmentManager, "editReplace") + dialog.show(fragmentManager, this::class.simpleName) } } diff --git a/app/src/main/java/io/legado/app/ui/replacerule/edit/ReplaceEditViewModel.kt b/app/src/main/java/io/legado/app/ui/replacerule/edit/ReplaceEditViewModel.kt index e4a0d443c..1308b64ec 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/edit/ReplaceEditViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/replacerule/edit/ReplaceEditViewModel.kt @@ -20,12 +20,16 @@ class ReplaceEditViewModel(application: Application) : BaseViewModel(application replaceRuleData.postValue(it) } } else { - bundle.getString("pattern")?.let { pattern -> - val isRegex = bundle.getBoolean("isRegex") - replaceRuleData.postValue( - ReplaceRule(name = pattern, pattern = pattern, isRegex = isRegex) - ) - } + val pattern = bundle.getString("pattern") ?: "" + val isRegex = bundle.getBoolean("isRegex") + val scope = bundle.getString("scope") + val rule = ReplaceRule( + name = pattern, + pattern = pattern, + isRegex = isRegex, + scope = scope + ) + replaceRuleData.postValue(rule) } } } diff --git a/app/src/main/java/io/legado/app/ui/widget/dialog/PhotoDialog.kt b/app/src/main/java/io/legado/app/ui/widget/dialog/PhotoDialog.kt index c00064222..69c062295 100644 --- a/app/src/main/java/io/legado/app/ui/widget/dialog/PhotoDialog.kt +++ b/app/src/main/java/io/legado/app/ui/widget/dialog/PhotoDialog.kt @@ -56,7 +56,7 @@ class PhotoDialog : BaseDialogFragment() { val src = it.getString("src") ReadBook.book?.let { book -> src?.let { - ImageProvider.getImage(book, chapterIndex, src, src)?.let { bitmap -> + ImageProvider.getImage(book, chapterIndex, src, null)?.let { bitmap -> photo_view.setImageBitmap(bitmap) } } diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index aacb27576..f9d881de9 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -319,7 +319,7 @@ 書籍信息編輯 默認打開書架 自動跳轉最近閲讀 - 替換範圍,選填書名或者源名 + 替換範圍,選填書名或者書源url 分組 內容緩存路徑 清理緩存 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 208ea687f..6aaf6b82f 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -320,7 +320,7 @@ 書籍訊息編輯 預設打開書架 自動跳轉最近閱讀 - 取代範圍,選填書名或者源名 + 取代範圍,選填書名或者書源url 分組 內容快取路徑 清理快取 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index a0a3eb278..27aa2a8f8 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -321,7 +321,7 @@ 书籍信息编辑 默认打开书架 自动跳转最近阅读 - 替换范围,选填书名或者源名 + 替换范围,选填书名或者书源url 分组 内容缓存路径 清理缓存 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5bf2741dd..2b1b21058 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -321,7 +321,7 @@ Edit book infomation Use Bookshelf as start page Auto jump to Recent list - Replacement object. Book name or source name is available + Replacement object. Book name or source url is available Groups Cache path Clear cache diff --git a/build.gradle b/build.gradle index 13629c5e0..f2d22610f 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.3.72' + ext.kotlin_version = '1.4.0' repositories { google() jcenter()