优化payAction

pull/2213/head
Odomu 3 years ago
parent 0aa493f57c
commit 28b85e45c2
  1. 3
      app/src/main/assets/help/ruleHelp.md
  2. 50
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  3. 1
      app/src/main/res/values-es-rES/strings.xml
  4. 1
      app/src/main/res/values-ja-rJP/strings.xml
  5. 1
      app/src/main/res/values-pt-rBR/strings.xml
  6. 1
      app/src/main/res/values-zh-rHK/strings.xml
  7. 1
      app/src/main/res/values-zh/strings.xml
  8. 1
      app/src/main/res/values/strings.xml

@ -152,5 +152,4 @@ let options = {
``` ```
* 购买操作 * 购买操作
> 返回购买链接,可直接填写链接或者JavaScript > 返回购买链接(自动打开浏览器),可直接填写链接或者JavaScript
> 可用变量 book chapter java(不支持AnalyzeRule函数) source

@ -36,6 +36,7 @@ import io.legado.app.lib.dialogs.selector
import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.accentColor
import io.legado.app.model.ReadAloud import io.legado.app.model.ReadAloud
import io.legado.app.model.ReadBook import io.legado.app.model.ReadBook
import io.legado.app.model.analyzeRule.AnalyzeRule
import io.legado.app.receiver.TimeBatteryReceiver import io.legado.app.receiver.TimeBatteryReceiver
import io.legado.app.service.BaseReadAloudService import io.legado.app.service.BaseReadAloudService
import io.legado.app.ui.about.AppLogDialog import io.legado.app.ui.about.AppLogDialog
@ -962,31 +963,34 @@ class ReadBookActivity : BaseReadBookActivity(),
} }
override fun payAction() { override fun payAction() {
Coroutine.async(this) { val book = ReadBook.book ?: throw NoStackTraceException("no book")
val book = ReadBook.book ?: throw NoStackTraceException("no book") val chapter = appDb.bookChapterDao.getChapter(book.bookUrl, ReadBook.durChapterIndex)
val chapter = appDb.bookChapterDao.getChapter(book.bookUrl, ReadBook.durChapterIndex) ?: throw NoStackTraceException("no chapter")
?: throw NoStackTraceException("no chapter") val source = ReadBook.bookSource ?: throw NoStackTraceException("no book source")
val source = ReadBook.bookSource ?: throw NoStackTraceException("no book source") val payAction = source.getContentRule().payAction
val payAction = source.getContentRule().payAction if (payAction.isNullOrEmpty()) {
if (payAction.isNullOrEmpty()) { throw NoStackTraceException("no pay action")
throw NoStackTraceException("no pay action") }
} alert(R.string.pay_chapter) {
JsUtils.evalJs(payAction) { setMessage(chapter.title)
it["java"] = source yesButton {
it["source"] = source Coroutine.async {
it["book"] = book val analyzeRule = AnalyzeRule(book, source).setBaseUrl(chapter.url)
it["chapter"] = chapter analyzeRule.chapter = chapter
} analyzeRule.evalJS(payAction).toString()
}.onSuccess { }.onSuccess {
if (it.isNotBlank()) { if (it.isNotBlank()) {
startActivity<WebViewActivity> { startActivity<WebViewActivity> {
putExtra("title", getString(R.string.chapter_pay)) putExtra("title", getString(R.string.chapter_pay))
putExtra("url", it) putExtra("url", it)
IntentData.put(it, ReadBook.bookSource?.getHeaderMap(true)) IntentData.put(it, ReadBook.bookSource?.getHeaderMap(true))
}
}
}.onError {
toastOnUi(it.localizedMessage)
} }
} }
}.onError { noButton()
toastOnUi(it.localizedMessage)
} }
} }

@ -1010,4 +1010,5 @@
<string name="check_selected_interval">选中所选区间</string> <string name="check_selected_interval">选中所选区间</string>
<string name="show_add_to_shelf_alert_title">返回时提示放入书架</string> <string name="show_add_to_shelf_alert_title">返回时提示放入书架</string>
<string name="show_add_to_shelf_alert_summary">阅读未放入书架的书籍在返回时提示放入书架</string> <string name="show_add_to_shelf_alert_summary">阅读未放入书架的书籍在返回时提示放入书架</string>
<string name="pay_chapter">购买章节</string>
</resources> </resources>

@ -1013,4 +1013,5 @@
<string name="check_selected_interval">选中所选区间</string> <string name="check_selected_interval">选中所选区间</string>
<string name="show_add_to_shelf_alert_title">返回时提示放入书架</string> <string name="show_add_to_shelf_alert_title">返回时提示放入书架</string>
<string name="show_add_to_shelf_alert_summary">阅读未放入书架的书籍在返回时提示放入书架</string> <string name="show_add_to_shelf_alert_summary">阅读未放入书架的书籍在返回时提示放入书架</string>
<string name="pay_chapter">购买章节</string>
</resources> </resources>

@ -1013,4 +1013,5 @@
<string name="check_selected_interval">选中所选区间</string> <string name="check_selected_interval">选中所选区间</string>
<string name="show_add_to_shelf_alert_title">返回时提示放入书架</string> <string name="show_add_to_shelf_alert_title">返回时提示放入书架</string>
<string name="show_add_to_shelf_alert_summary">阅读未放入书架的书籍在返回时提示放入书架</string> <string name="show_add_to_shelf_alert_summary">阅读未放入书架的书籍在返回时提示放入书架</string>
<string name="pay_chapter">购买章节</string>
</resources> </resources>

@ -1010,4 +1010,5 @@
<string name="check_selected_interval">选中所选区间</string> <string name="check_selected_interval">选中所选区间</string>
<string name="show_add_to_shelf_alert_title">返回时提示放入书架</string> <string name="show_add_to_shelf_alert_title">返回时提示放入书架</string>
<string name="show_add_to_shelf_alert_summary">阅读未放入书架的书籍在返回时提示放入书架</string> <string name="show_add_to_shelf_alert_summary">阅读未放入书架的书籍在返回时提示放入书架</string>
<string name="pay_chapter">购买章节</string>
</resources> </resources>

@ -1012,4 +1012,5 @@
<string name="check_selected_interval">选中所选区间</string> <string name="check_selected_interval">选中所选区间</string>
<string name="show_add_to_shelf_alert_title">返回时提示放入书架</string> <string name="show_add_to_shelf_alert_title">返回时提示放入书架</string>
<string name="show_add_to_shelf_alert_summary">阅读未放入书架的书籍在返回时提示放入书架</string> <string name="show_add_to_shelf_alert_summary">阅读未放入书架的书籍在返回时提示放入书架</string>
<string name="pay_chapter">购买章节</string>
</resources> </resources>

@ -1013,4 +1013,5 @@
<string name="check_selected_interval">选中所选区间</string> <string name="check_selected_interval">选中所选区间</string>
<string name="show_add_to_shelf_alert_title">返回时提示放入书架</string> <string name="show_add_to_shelf_alert_title">返回时提示放入书架</string>
<string name="show_add_to_shelf_alert_summary">阅读未放入书架的书籍在返回时提示放入书架</string> <string name="show_add_to_shelf_alert_summary">阅读未放入书架的书籍在返回时提示放入书架</string>
<string name="pay_chapter">购买章节</string>
</resources> </resources>

Loading…
Cancel
Save