pull/1303/head
gedoor 3 years ago
parent a17df90a40
commit 65cf646520
  1. 8
      app/src/main/java/io/legado/app/data/entities/Book.kt
  2. 8
      app/src/main/java/io/legado/app/data/entities/BookChapter.kt
  3. 8
      app/src/main/java/io/legado/app/data/entities/RssArticle.kt
  4. 8
      app/src/main/java/io/legado/app/data/entities/RssStar.kt
  5. 8
      app/src/main/java/io/legado/app/data/entities/SearchBook.kt
  6. 8
      app/src/main/java/io/legado/app/model/analyzeRule/RuleData.kt
  7. 6
      app/src/main/java/io/legado/app/model/analyzeRule/RuleDataInterface.kt
  8. 27
      app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt
  9. 5
      app/src/main/res/menu/book_info.xml
  10. 1
      app/src/main/res/values-es-rES/strings.xml
  11. 1
      app/src/main/res/values-ja-rJP/strings.xml
  12. 1
      app/src/main/res/values-pt-rBR/strings.xml
  13. 1
      app/src/main/res/values-zh-rHK/strings.xml
  14. 1
      app/src/main/res/values-zh-rTW/strings.xml
  15. 1
      app/src/main/res/values-zh/strings.xml
  16. 1
      app/src/main/res/values/strings.xml

@ -94,8 +94,12 @@ data class Book(
GSON.fromJsonObject<HashMap<String, String>>(variable) ?: HashMap()
}
override fun putVariable(key: String, value: String) {
variableMap[key] = value
override fun putVariable(key: String, value: String?) {
if (value != null) {
variableMap[key] = value
} else {
variableMap.remove(key)
}
variable = GSON.toJson(variableMap)
}

@ -49,8 +49,12 @@ data class BookChapter(
GSON.fromJsonObject<HashMap<String, String>>(variable) ?: HashMap()
}
override fun putVariable(key: String, value: String) {
variableMap[key] = value
override fun putVariable(key: String, value: String?) {
if (value != null) {
variableMap[key] = value
} else {
variableMap.remove(key)
}
variable = GSON.toJson(variableMap)
}

@ -40,8 +40,12 @@ data class RssArticle(
GSON.fromJsonObject<HashMap<String, String>>(variable) ?: HashMap()
}
override fun putVariable(key: String, value: String) {
variableMap[key] = value
override fun putVariable(key: String, value: String?) {
if (value != null) {
variableMap[key] = value
} else {
variableMap.remove(key)
}
variable = GSON.toJson(variableMap)
}

@ -32,8 +32,12 @@ data class RssStar(
GSON.fromJsonObject<HashMap<String, String>>(variable) ?: HashMap()
}
override fun putVariable(key: String, value: String) {
variableMap[key] = value
override fun putVariable(key: String, value: String?) {
if (value != null) {
variableMap[key] = value
} else {
variableMap.remove(key)
}
variable = GSON.toJson(variableMap)
}

@ -63,8 +63,12 @@ data class SearchBook(
GSON.fromJsonObject<HashMap<String, String>>(variable) ?: HashMap()
}
override fun putVariable(key: String, value: String) {
variableMap[key] = value
override fun putVariable(key: String, value: String?) {
if (value != null) {
variableMap[key] = value
} else {
variableMap.remove(key)
}
variable = GSON.toJson(variableMap)
}

@ -6,8 +6,12 @@ class RuleData : RuleDataInterface {
hashMapOf<String, String>()
}
override fun putVariable(key: String, value: String) {
variableMap[key] = value
override fun putVariable(key: String, value: String?) {
if (value != null) {
variableMap[key] = value
} else {
variableMap.remove(key)
}
}
}

@ -4,6 +4,10 @@ interface RuleDataInterface {
val variableMap: HashMap<String, String>
fun putVariable(key: String, value: String)
fun putVariable(key: String, value: String?)
fun getVariable(key: String): String? {
return variableMap[key]
}
}

@ -122,6 +122,8 @@ class BookInfoActivity :
!viewModel.bookSource?.loginUrl.isNullOrBlank()
menu.findItem(R.id.menu_set_source_variable)?.isVisible =
viewModel.bookSource != null
menu.findItem(R.id.menu_set_book_variable)?.isVisible =
viewModel.bookSource != null
return super.onMenuOpened(featureId, menu)
}
@ -161,6 +163,7 @@ class BookInfoActivity :
}
R.id.menu_top -> viewModel.topBook()
R.id.menu_set_source_variable -> setSourceVariable()
R.id.menu_set_book_variable -> setBookVariable()
R.id.menu_copy_book_url -> viewModel.bookData.value?.bookUrl?.let {
sendToClip(it)
} ?: toastOnUi(R.string.no_book)
@ -336,7 +339,31 @@ class BookInfoActivity :
}
}.show()
}
}
private fun setBookVariable() {
launch {
val variable = withContext(IO) { viewModel.bookData.value?.getVariable("custom") }
alert(R.string.set_source_variable) {
setMessage("""书籍变量可在js中通过book.getVariable("custom")获取""")
val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply {
editView.hint = "book variable"
editView.setText(variable)
}
customView { alertBinding.root }
okButton {
viewModel.bookData.value
?.putVariable("custom", alertBinding.editView.text?.toString())
viewModel.saveBook()
}
cancelButton()
neutralButton(R.string.delete) {
viewModel.bookData.value
?.putVariable("custom", null)
viewModel.saveBook()
}
}.show()
}
}
@SuppressLint("InflateParams")

@ -34,6 +34,11 @@
android:title="@string/set_source_variable"
app:showAsAction="never" />
<item
android:id="@+id/menu_set_book_variable"
android:title="@string/set_book_variable"
app:showAsAction="never" />
<item
android:id="@+id/menu_copy_book_url"
android:title="@string/copy_book_url"

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

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

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

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

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

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

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

Loading…
Cancel
Save