pull/1303/head
gedoor 3 years ago
parent 427b71fabd
commit a17df90a40
  1. 12
      app/src/main/java/io/legado/app/data/entities/BaseSource.kt
  2. 2
      app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt
  3. 30
      app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt
  4. 1
      app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt
  5. 18
      app/src/main/res/layout/dialog_edit_text.xml
  6. 5
      app/src/main/res/menu/book_info.xml
  7. 1
      app/src/main/res/values-es-rES/strings.xml
  8. 1
      app/src/main/res/values-ja-rJP/strings.xml
  9. 1
      app/src/main/res/values-pt-rBR/strings.xml
  10. 1
      app/src/main/res/values-zh-rHK/strings.xml
  11. 1
      app/src/main/res/values-zh-rTW/strings.xml
  12. 1
      app/src/main/res/values-zh/strings.xml
  13. 1
      app/src/main/res/values/strings.xml

@ -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
*/

@ -302,10 +302,10 @@ class CacheActivity : VMBaseActivity<ActivityCacheBookBinding, CacheViewModel>()
@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 {

@ -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 {

@ -281,6 +281,7 @@ class ImportBookActivity : VMBaseActivity<ActivityImportBookBinding, ImportBookV
private fun alertImportFileName() {
alert(R.string.import_file_name) {
setMessage("""使用js返回一个json结构,{"name":"xxx", "author":"yyy"}""")
val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply {
editView.hint = "js"
editView.setText(AppConfig.bookImportFileName)

@ -4,14 +4,8 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:overScrollMode="ifContentScrolls"
android:paddingTop="12dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="20dp"
android:paddingRight="20dp">
android:paddingLeft="16dp"
android:paddingRight="16dp">
<io.legado.app.ui.widget.text.AutoCompleteTextView
android:id="@+id/edit_view"
@ -19,12 +13,4 @@
android:layout_height="wrap_content"
tools:ignore="SpeakableTextPresentCheck,TouchTargetSizeCheck" />
<TextView
android:id="@+id/tv_summary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/secondaryText" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>

@ -29,6 +29,11 @@
android:title="@string/to_top"
app:showAsAction="never" />
<item
android:id="@+id/menu_set_source_variable"
android:title="@string/set_source_variable"
app:showAsAction="never" />
<item
android:id="@+id/menu_copy_book_url"
android:title="@string/copy_book_url"

@ -872,4 +872,5 @@
<string name="direct_link_upload_rule">直链上传规则</string>
<string name="direct_link_upload_rule_summary">用于导出书源书单时生成直链url</string>
<string name="copy_play_url">拷贝播放Url</string>
<string name="set_source_variable">设置源变量</string>
</resources>

@ -872,4 +872,5 @@
<string name="direct_link_upload_rule">直链上传规则</string>
<string name="direct_link_upload_rule_summary">用于导出书源书单时生成直链url</string>
<string name="copy_play_url">拷贝播放Url</string>
<string name="set_source_variable">设置源变量</string>
</resources>

@ -872,5 +872,6 @@
<string name="direct_link_upload_rule">直链上传规则</string>
<string name="direct_link_upload_rule_summary">用于导出书源书单时生成直链url</string>
<string name="copy_play_url">拷贝播放Url</string>
<string name="set_source_variable">设置源变量</string>
</resources>

@ -869,5 +869,6 @@
<string name="direct_link_upload_rule">直链上传规则</string>
<string name="direct_link_upload_rule_summary">用于导出书源书单时生成直链url</string>
<string name="copy_play_url">拷贝播放Url</string>
<string name="set_source_variable">设置源变量</string>
</resources>

@ -870,5 +870,6 @@
<string name="direct_link_upload_rule">直链上传规则</string>
<string name="direct_link_upload_rule_summary">用于导出书源书单时生成直链url</string>
<string name="copy_play_url">拷贝播放Url</string>
<string name="set_source_variable">设置源变量</string>
</resources>

@ -871,5 +871,6 @@
<string name="direct_link_upload_rule">直链上传规则</string>
<string name="direct_link_upload_rule_summary">用于导出书源书单时生成直链url</string>
<string name="copy_play_url">拷贝播放Url</string>
<string name="set_source_variable">设置源变量</string>
</resources>

@ -872,5 +872,6 @@
<string name="direct_link_upload_rule">直链上传规则</string>
<string name="direct_link_upload_rule_summary">用于导出书源书单时生成直链url</string>
<string name="copy_play_url">拷贝播放Url</string>
<string name="set_source_variable">设置源变量</string>
</resources>

Loading…
Cancel
Save