diff --git a/app/src/main/java/io/legado/app/data/entities/BaseSource.kt b/app/src/main/java/io/legado/app/data/entities/BaseSource.kt index fed5ef9c2..d704cc957 100644 --- a/app/src/main/java/io/legado/app/data/entities/BaseSource.kt +++ b/app/src/main/java/io/legado/app/data/entities/BaseSource.kt @@ -120,6 +120,18 @@ interface BaseSource : JsExtensions { CacheManager.delete("userInfo_${getStoreUrl()}") } + fun setVariable(variable: String?) { + if (variable != null) { + CacheManager.put("sourceVariable_${getStoreUrl()}", variable) + } else { + CacheManager.delete("sourceVariable_${getStoreUrl()}") + } + } + + fun getVariable(): String? { + return CacheManager.get("sourceVariable_${getStoreUrl()}") + } + /** * 执行JS */ 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 9c0a2e4c3..b23f4e0b5 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 @@ -302,10 +302,10 @@ class CacheActivity : VMBaseActivity() @SuppressLint("SetTextI18n") private fun alertExportFileName() { alert(R.string.export_file_name) { + setMessage("js内有name和author变量,返回书名") val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply { editView.hint = "file name js" editView.setText(AppConfig.bookExportFileName) - tvSummary.text = """使用js返回一个json结构,{"name":"xxx", "author":"yyy"}""" } customView { alertBinding.root } okButton { diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt index a9a95113d..d6f4a8cc4 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt @@ -21,6 +21,7 @@ import io.legado.app.data.appDb import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookChapter import io.legado.app.databinding.ActivityBookInfoBinding +import io.legado.app.databinding.DialogEditTextBinding import io.legado.app.help.BlurTransformation import io.legado.app.help.glide.ImageLoader import io.legado.app.lib.dialogs.alert @@ -119,6 +120,8 @@ class BookInfoActivity : viewModel.bookData.value?.canUpdate ?: true menu.findItem(R.id.menu_login)?.isVisible = !viewModel.bookSource?.loginUrl.isNullOrBlank() + menu.findItem(R.id.menu_set_source_variable)?.isVisible = + viewModel.bookSource != null return super.onMenuOpened(featureId, menu) } @@ -157,6 +160,7 @@ class BookInfoActivity : } } R.id.menu_top -> viewModel.topBook() + R.id.menu_set_source_variable -> setSourceVariable() R.id.menu_copy_book_url -> viewModel.bookData.value?.bookUrl?.let { sendToClip(it) } ?: toastOnUi(R.string.no_book) @@ -309,6 +313,32 @@ class BookInfoActivity : } } + private fun setSourceVariable() { + launch { + val variable = withContext(IO) { viewModel.bookSource?.getVariable() } + alert(R.string.set_source_variable) { + setMessage("源变量可在js中通过source.getVariable()获取") + val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply { + editView.hint = "source variable" + editView.setText(variable) + } + customView { alertBinding.root } + okButton { + launch(IO) { + viewModel.bookSource?.setVariable(alertBinding.editView.text?.toString()) + } + } + cancelButton() + neutralButton(R.string.delete) { + launch(IO) { + viewModel.bookSource?.setVariable(null) + } + } + }.show() + } + + } + @SuppressLint("InflateParams") private fun deleteBook() { viewModel.bookData.value?.let { diff --git a/app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt index b47405be7..506de03fc 100644 --- a/app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt @@ -281,6 +281,7 @@ class ImportBookActivity : VMBaseActivity + android:paddingLeft="16dp" + android:paddingRight="16dp"> - - - - - - - + tools:ignore="SpeakableTextPresentCheck,TouchTargetSizeCheck" /> \ No newline at end of file diff --git a/app/src/main/res/menu/book_info.xml b/app/src/main/res/menu/book_info.xml index 370597f5c..37acb0fa3 100644 --- a/app/src/main/res/menu/book_info.xml +++ b/app/src/main/res/menu/book_info.xml @@ -29,6 +29,11 @@ android:title="@string/to_top" app:showAsAction="never" /> + + 直链上传规则 用于导出书源书单时生成直链url 拷贝播放Url + 设置源变量 diff --git a/app/src/main/res/values-ja-rJP/strings.xml b/app/src/main/res/values-ja-rJP/strings.xml index 8426607e0..572840413 100644 --- a/app/src/main/res/values-ja-rJP/strings.xml +++ b/app/src/main/res/values-ja-rJP/strings.xml @@ -872,4 +872,5 @@ 直链上传规则 用于导出书源书单时生成直链url 拷贝播放Url + 设置源变量 diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index c3cf77417..93ad6d6b0 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -872,5 +872,6 @@ 直链上传规则 用于导出书源书单时生成直链url 拷贝播放Url + 设置源变量 diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 03165419b..f6f79fe01 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -869,5 +869,6 @@ 直链上传规则 用于导出书源书单时生成直链url 拷贝播放Url + 设置源变量 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 91d8d023b..49f5841bc 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -870,5 +870,6 @@ 直链上传规则 用于导出书源书单时生成直链url 拷贝播放Url + 设置源变量 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 634c13677..f32c7c762 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -871,5 +871,6 @@ 直链上传规则 用于导出书源书单时生成直链url 拷贝播放Url + 设置源变量 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a2dac3821..e437d54b9 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -872,5 +872,6 @@ 直链上传规则 用于导出书源书单时生成直链url 拷贝播放Url + 设置源变量