mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -152,5 +152,4 @@ let options = {
|
||||
```
|
||||
|
||||
* 购买操作
|
||||
> 返回购买链接,可直接填写链接或者JavaScript
|
||||
> 可用变量 book chapter java(不支持AnalyzeRule函数) source
|
||||
> 可直接填写链接或者JavaScript,如果执行结果是字符串链接将会自动打开浏览器
|
||||
@@ -1,7 +1,6 @@
|
||||
package io.legado.app.ui.book.changesource
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
@@ -14,7 +13,10 @@ import io.legado.app.base.adapter.DiffRecyclerAdapter
|
||||
import io.legado.app.base.adapter.ItemViewHolder
|
||||
import io.legado.app.data.entities.SearchBook
|
||||
import io.legado.app.databinding.ItemChangeSourceBinding
|
||||
import io.legado.app.utils.*
|
||||
import io.legado.app.utils.getCompatColor
|
||||
import io.legado.app.utils.gone
|
||||
import io.legado.app.utils.invisible
|
||||
import io.legado.app.utils.visible
|
||||
import splitties.init.appCtx
|
||||
import splitties.views.onLongClick
|
||||
|
||||
|
||||
@@ -83,27 +83,23 @@ open class ChangeBookSourceViewModel(application: Application) : BaseViewModel(a
|
||||
searchCallback = null
|
||||
}
|
||||
}.map {
|
||||
searchBooks.sortedWith(object : Comparator<SearchBook> {
|
||||
override fun compare(o1: SearchBook, o2: SearchBook): Int {
|
||||
val o1bs = SourceConfig.getBookScore(o1.origin, o1.name, o1.author)
|
||||
val o2bs = SourceConfig.getBookScore(o2.origin, o2.name, o2.author)
|
||||
if (o1bs - o2bs > 0) {
|
||||
return -1
|
||||
} else if (o1bs - o2bs < 0) {
|
||||
return 1
|
||||
} else {
|
||||
searchBooks.sortedWith { o1, o2 ->
|
||||
val o1bs = SourceConfig.getBookScore(o1.origin, o1.name, o1.author)
|
||||
val o2bs = SourceConfig.getBookScore(o2.origin, o2.name, o2.author)
|
||||
when {
|
||||
o1bs - o2bs > 0 -> -1
|
||||
o1bs - o2bs < 0 -> 1
|
||||
else -> {
|
||||
val o1ss = SourceConfig.getSourceScore(o1.origin)
|
||||
val o2ss = SourceConfig.getSourceScore(o2.origin)
|
||||
if (o1ss - o2ss > 0) {
|
||||
return -1
|
||||
} else if (o1ss - o2ss < 0) {
|
||||
return 1
|
||||
} else {
|
||||
return o1.originOrder - o2.originOrder
|
||||
when {
|
||||
o1ss - o2ss > 0 -> -1
|
||||
o1ss - o2ss < 0 -> 1
|
||||
else -> o1.originOrder - o2.originOrder
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}.flowOn(IO)
|
||||
|
||||
@Volatile
|
||||
|
||||
@@ -36,6 +36,7 @@ import io.legado.app.lib.dialogs.selector
|
||||
import io.legado.app.lib.theme.accentColor
|
||||
import io.legado.app.model.ReadAloud
|
||||
import io.legado.app.model.ReadBook
|
||||
import io.legado.app.model.analyzeRule.AnalyzeRule
|
||||
import io.legado.app.receiver.TimeBatteryReceiver
|
||||
import io.legado.app.service.BaseReadAloudService
|
||||
import io.legado.app.ui.about.AppLogDialog
|
||||
@@ -962,31 +963,41 @@ class ReadBookActivity : BaseReadBookActivity(),
|
||||
}
|
||||
|
||||
override fun payAction() {
|
||||
Coroutine.async(this) {
|
||||
val book = ReadBook.book ?: throw NoStackTraceException("no book")
|
||||
ReadBook.book?.let { book ->
|
||||
if (book.isLocalBook()) return
|
||||
val chapter = appDb.bookChapterDao.getChapter(book.bookUrl, ReadBook.durChapterIndex)
|
||||
?: throw NoStackTraceException("no chapter")
|
||||
val source = ReadBook.bookSource ?: throw NoStackTraceException("no book source")
|
||||
val payAction = source.getContentRule().payAction
|
||||
if (payAction.isNullOrEmpty()) {
|
||||
throw NoStackTraceException("no pay action")
|
||||
if (chapter == null) {
|
||||
toastOnUi("no chapter")
|
||||
return
|
||||
}
|
||||
JsUtils.evalJs(payAction) {
|
||||
it["java"] = source
|
||||
it["source"] = source
|
||||
it["book"] = book
|
||||
it["chapter"] = chapter
|
||||
}
|
||||
}.onSuccess {
|
||||
if (it.isNotBlank()) {
|
||||
startActivity<WebViewActivity> {
|
||||
putExtra("title", getString(R.string.chapter_pay))
|
||||
putExtra("url", it)
|
||||
IntentData.put(it, ReadBook.bookSource?.getHeaderMap(true))
|
||||
alert(R.string.chapter_pay) {
|
||||
setMessage(chapter.title)
|
||||
yesButton {
|
||||
Coroutine.async {
|
||||
val source = ReadBook.bookSource ?: throw NoStackTraceException("no book source")
|
||||
val payAction = source.getContentRule().payAction
|
||||
if (payAction.isNullOrEmpty()) {
|
||||
throw NoStackTraceException("no pay action")
|
||||
}
|
||||
val analyzeRule = AnalyzeRule(book, source)
|
||||
analyzeRule.setBaseUrl(chapter.url)
|
||||
analyzeRule.chapter = chapter
|
||||
analyzeRule.evalJS(payAction).toString()
|
||||
}.onSuccess {
|
||||
if (it.isNotBlank()) {
|
||||
startActivity<WebViewActivity> {
|
||||
putExtra("title", R.string.chapter_pay)
|
||||
putExtra("url", it)
|
||||
IntentData.put(it, ReadBook.bookSource?.getHeaderMap(true))
|
||||
}
|
||||
}
|
||||
}.onError {
|
||||
AppLog.putDebug(it.localizedMessage)
|
||||
toastOnUi(it.localizedMessage)
|
||||
}
|
||||
}
|
||||
noButton()
|
||||
}
|
||||
}.onError {
|
||||
toastOnUi(it.localizedMessage)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user