pull/2473/head
kunfei 2 years ago
parent 3ec4bef12a
commit d8e96ce143
  1. 0
      app/src/main/assets/defaultData/coverRule.json
  2. 2
      app/src/main/java/io/legado/app/constant/AppConst.kt
  3. 3
      app/src/main/java/io/legado/app/data/entities/BaseSource.kt
  4. 6
      app/src/main/java/io/legado/app/help/DefaultData.kt
  5. 23
      app/src/main/java/io/legado/app/model/BookCover.kt
  6. 3
      app/src/main/java/io/legado/app/ui/book/audio/AudioPlayActivity.kt
  7. 3
      app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt
  8. 2
      app/src/main/java/io/legado/app/ui/book/read/page/entities/TextChapter.kt
  9. 2
      app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt
  10. 2
      app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt
  11. 4
      app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPos.kt
  12. 3
      app/src/main/java/io/legado/app/ui/book/read/page/entities/column/ButtonColumn.kt
  13. 3
      app/src/main/java/io/legado/app/ui/book/read/page/entities/column/ImageColumn.kt
  14. 2
      app/src/main/java/io/legado/app/ui/book/read/page/entities/column/ReviewColumn.kt
  15. 3
      app/src/main/java/io/legado/app/ui/book/read/page/entities/column/TextColumn.kt
  16. 29
      app/src/main/java/io/legado/app/ui/config/CoverRuleConfigDialog.kt
  17. 3
      app/src/main/res/layout/dialog_cover_rule_config.xml

@ -3,6 +3,7 @@ package io.legado.app.constant
import android.annotation.SuppressLint
import android.content.pm.PackageManager
import android.provider.Settings
import com.android.tools.r8.Keep
import com.script.javascript.RhinoScriptEngine
import io.legado.app.BuildConfig
import splitties.init.appCtx
@ -87,6 +88,7 @@ object AppConst {
val charsets =
arrayListOf("UTF-8", "GB2312", "GB18030", "GBK", "Unicode", "UTF-16", "UTF-16LE", "ASCII")
@Keep
data class AppInfo(
var versionCode: Long = 0L,
var versionName: String = ""

@ -1,8 +1,7 @@
package io.legado.app.data.entities
import android.util.Base64
import com.script.SimpleBindings
import cn.hutool.crypto.symmetric.AES
import com.script.SimpleBindings
import io.legado.app.constant.AppConst
import io.legado.app.constant.AppLog
import io.legado.app.data.entities.rule.RowUi

@ -60,12 +60,12 @@ object DefaultData {
RssSource.fromJsonArray(json).getOrDefault(emptyList())
}
val coverRuleConfig: BookCover.CoverRuleConfig by lazy {
val coverRule: BookCover.CoverRule by lazy {
val json = String(
appCtx.assets.open("defaultData${File.separator}coverRuleConfig.json")
appCtx.assets.open("defaultData${File.separator}coverRule.json")
.readBytes()
)
GSON.fromJsonObject<BookCover.CoverRuleConfig>(json).getOrThrow()!!
GSON.fromJsonObject<BookCover.CoverRule>(json).getOrThrow()!!
}
val keyboardAssists: List<KeyboardAssist> by lazy {

@ -4,6 +4,7 @@ import android.annotation.SuppressLint
import android.content.Context
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable
import com.android.tools.r8.Keep
import com.bumptech.glide.RequestBuilder
import com.bumptech.glide.load.resource.bitmap.CenterCrop
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
@ -23,6 +24,7 @@ import io.legado.app.model.analyzeRule.AnalyzeUrl
import io.legado.app.utils.*
import splitties.init.appCtx
@Keep
object BookCover {
private const val coverRuleConfigKey = "legadoCoverRuleConfig"
@ -32,12 +34,6 @@ object BookCover {
private set
lateinit var defaultDrawable: Drawable
private set
val coverRuleConfig: CoverRuleConfig
get() {
return GSON.fromJsonObject<CoverRuleConfig>(CacheManager.get(coverRuleConfigKey))
.getOrNull()
?: DefaultData.coverRuleConfig
}
init {
@ -117,8 +113,14 @@ object BookCover {
.thumbnail(loadBlur)
}
fun getCoverRule(): CoverRule {
return GSON.fromJsonObject<CoverRule>(CacheManager.get(coverRuleConfigKey))
.getOrNull()
?: DefaultData.coverRule
}
suspend fun searchCover(book: Book): String? {
val config = coverRuleConfig
val config = getCoverRule()
if (!config.enable || config.searchUrl.isBlank() || config.coverRule.isBlank()) {
return null
}
@ -135,16 +137,17 @@ object BookCover {
return analyzeRule.getString(config.coverRule, isUrl = true)
}
fun saveCoverRuleConfig(config: CoverRuleConfig) {
fun saveCoverRule(config: CoverRule) {
val json = GSON.toJson(config)
CacheManager.put(coverRuleConfigKey, json)
}
fun delCoverRuleConfig() {
fun delCoverRule() {
CacheManager.delete(coverRuleConfigKey)
}
data class CoverRuleConfig(
@Keep
data class CoverRule(
var enable: Boolean = true,
var searchUrl: String,
var coverRule: String,

@ -2,7 +2,6 @@ package io.legado.app.ui.book.audio
import android.annotation.SuppressLint
import android.app.Activity
import android.graphics.Color
import android.icu.text.SimpleDateFormat
import android.os.Build
import android.os.Bundle
@ -79,7 +78,7 @@ class AudioPlayActivity :
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
binding.titleBar.setBackgroundColor(Color.argb(60, 0, 0, 0))
binding.titleBar.setBackgroundResource(R.color.transparent)
AudioPlay.titleData.observe(this) {
binding.titleBar.title = it
}

@ -2,7 +2,6 @@ package io.legado.app.ui.book.info
import android.annotation.SuppressLint
import android.content.Intent
import android.graphics.Color
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
@ -102,7 +101,7 @@ class BookInfoActivity :
@SuppressLint("PrivateResource")
override fun onActivityCreated(savedInstanceState: Bundle?) {
binding.titleBar.setBackgroundColor(Color.argb(60, 0, 0, 0))
binding.titleBar.setBackgroundResource(R.color.transparent)
binding.arcView.setBgColor(backgroundColor)
binding.llInfo.setBackgroundColor(backgroundColor)
binding.scrollView.setBackgroundColor(backgroundColor)

@ -1,10 +1,12 @@
package io.legado.app.ui.book.read.page.entities
import com.android.tools.r8.Keep
import kotlin.math.min
/**
* 章节信息
*/
@Keep
@Suppress("unused")
data class TextChapter(
val position: Int,

@ -1,6 +1,7 @@
package io.legado.app.ui.book.read.page.entities
import android.text.TextPaint
import com.android.tools.r8.Keep
import io.legado.app.ui.book.read.page.entities.column.BaseColumn
import io.legado.app.ui.book.read.page.provider.ChapterProvider
import io.legado.app.utils.textHeight
@ -8,6 +9,7 @@ import io.legado.app.utils.textHeight
/**
* 行信息
*/
@Keep
@Suppress("unused", "MemberVisibilityCanBePrivate")
data class TextLine(
var text: String = "",

@ -2,6 +2,7 @@ package io.legado.app.ui.book.read.page.entities
import android.text.Layout
import android.text.StaticLayout
import com.android.tools.r8.Keep
import io.legado.app.R
import io.legado.app.help.config.ReadBookConfig
import io.legado.app.model.ReadBook
@ -15,6 +16,7 @@ import kotlin.math.min
/**
* 页面信息
*/
@Keep
@Suppress("unused", "MemberVisibilityCanBePrivate")
data class TextPage(
var index: Int = 0,

@ -1,8 +1,12 @@
package io.legado.app.ui.book.read.page.entities
import com.android.tools.r8.Keep
/**
* 位置信息
*/
@Keep
@Suppress("unused")
data class TextPos(
var relativePagePos: Int,
var lineIndex: Int,

@ -1,9 +1,12 @@
package io.legado.app.ui.book.read.page.entities.column
import com.android.tools.r8.Keep
/**
* 按钮列
*/
@Keep
data class ButtonColumn(
override var start: Float,
override var end: Float

@ -1,8 +1,11 @@
package io.legado.app.ui.book.read.page.entities.column
import com.android.tools.r8.Keep
/**
* 图片列
*/
@Keep
data class ImageColumn(
override var start: Float,
override var end: Float,

@ -3,11 +3,13 @@ package io.legado.app.ui.book.read.page.entities.column
import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.Path
import com.android.tools.r8.Keep
import io.legado.app.ui.book.read.page.provider.ChapterProvider
/**
* 评论按钮列
*/
@Keep
data class ReviewColumn(
override var start: Float,
override var end: Float,

@ -1,8 +1,11 @@
package io.legado.app.ui.book.read.page.entities.column
import com.android.tools.r8.Keep
/**
* 文字列
*/
@Keep
data class TextColumn(
override var start: Float,
override var end: Float,

@ -1,15 +1,21 @@
package io.legado.app.ui.config
import android.os.Bundle
import android.util.Log
import android.view.View
import android.view.ViewGroup
import io.legado.app.R
import io.legado.app.base.BaseDialogFragment
import io.legado.app.databinding.DialogCoverRuleConfigBinding
import io.legado.app.lib.theme.primaryColor
import io.legado.app.model.BookCover
import io.legado.app.utils.GSON
import io.legado.app.utils.setLayout
import io.legado.app.utils.toastOnUi
import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import splitties.views.onClick
class CoverRuleConfigDialog : BaseDialogFragment(R.layout.dialog_cover_rule_config) {
@ -22,9 +28,8 @@ class CoverRuleConfigDialog : BaseDialogFragment(R.layout.dialog_cover_rule_conf
}
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
binding.cbEnable.isChecked = BookCover.coverRuleConfig.enable
binding.editSearchUrl.setText(BookCover.coverRuleConfig.searchUrl)
binding.editCoverUrlRule.setText(BookCover.coverRuleConfig.coverRule)
binding.toolBar.setBackgroundColor(primaryColor)
initData()
binding.tvCancel.onClick {
dismissAllowingStateLoss()
}
@ -35,16 +40,28 @@ class CoverRuleConfigDialog : BaseDialogFragment(R.layout.dialog_cover_rule_conf
if (searchUrl.isNullOrBlank() || coverRule.isNullOrBlank()) {
toastOnUi("搜索url和cover规则不能为空")
} else {
BookCover.CoverRuleConfig(enable, searchUrl, coverRule).let { config ->
BookCover.saveCoverRuleConfig(config)
BookCover.CoverRule(enable, searchUrl, coverRule).let { config ->
BookCover.saveCoverRule(config)
}
dismissAllowingStateLoss()
}
}
binding.tvFooterLeft.onClick {
BookCover.delCoverRuleConfig()
BookCover.delCoverRule()
dismissAllowingStateLoss()
}
}
private fun initData() {
launch {
val rule = withContext(IO) {
BookCover.getCoverRule()
}
Log.e("coverRule", GSON.toJson(rule))
binding.cbEnable.isChecked = rule.enable
binding.editSearchUrl.setText(rule.searchUrl)
binding.editCoverUrlRule.setText(rule.coverRule)
}
}
}

@ -85,12 +85,13 @@
android:layout_height="wrap_content"
android:orientation="horizontal">
<io.legado.app.ui.widget.text.AccentTextView
<TextView
android:id="@+id/tv_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="12dp"
android:text="@string/cancel"
android:textColor="@color/secondaryText"
tools:ignore="RtlHardcoded" />
<io.legado.app.ui.widget.text.AccentTextView

Loading…
Cancel
Save