diff --git a/app/src/main/assets/defaultData/coverRuleConfig.json b/app/src/main/assets/defaultData/coverRule.json similarity index 100% rename from app/src/main/assets/defaultData/coverRuleConfig.json rename to app/src/main/assets/defaultData/coverRule.json diff --git a/app/src/main/java/io/legado/app/constant/AppConst.kt b/app/src/main/java/io/legado/app/constant/AppConst.kt index be8cd07e5..f6aa88f5f 100644 --- a/app/src/main/java/io/legado/app/constant/AppConst.kt +++ b/app/src/main/java/io/legado/app/constant/AppConst.kt @@ -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 = "" diff --git a/app/src/main/java/io/legado/app/data/entities/BaseSource.kt b/app/src/main/java/io/legado/app/data/entities/BaseSource.kt index f73d2977e..0e35087c3 100644 --- a/app/src/main/java/io/legado/app/data/entities/BaseSource.kt +++ b/app/src/main/java/io/legado/app/data/entities/BaseSource.kt @@ -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 diff --git a/app/src/main/java/io/legado/app/help/DefaultData.kt b/app/src/main/java/io/legado/app/help/DefaultData.kt index 7aae0536e..749123f06 100644 --- a/app/src/main/java/io/legado/app/help/DefaultData.kt +++ b/app/src/main/java/io/legado/app/help/DefaultData.kt @@ -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(json).getOrThrow()!! + GSON.fromJsonObject(json).getOrThrow()!! } val keyboardAssists: List by lazy { diff --git a/app/src/main/java/io/legado/app/model/BookCover.kt b/app/src/main/java/io/legado/app/model/BookCover.kt index bf042e569..ce2e7b91d 100644 --- a/app/src/main/java/io/legado/app/model/BookCover.kt +++ b/app/src/main/java/io/legado/app/model/BookCover.kt @@ -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(CacheManager.get(coverRuleConfigKey)) - .getOrNull() - ?: DefaultData.coverRuleConfig - } init { @@ -117,8 +113,14 @@ object BookCover { .thumbnail(loadBlur) } + fun getCoverRule(): CoverRule { + return GSON.fromJsonObject(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, diff --git a/app/src/main/java/io/legado/app/ui/book/audio/AudioPlayActivity.kt b/app/src/main/java/io/legado/app/ui/book/audio/AudioPlayActivity.kt index 154af3f3c..063a63cc5 100644 --- a/app/src/main/java/io/legado/app/ui/book/audio/AudioPlayActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/audio/AudioPlayActivity.kt @@ -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 } diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt index a9598f9fb..258cc9675 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt @@ -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) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextChapter.kt b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextChapter.kt index 50d254e58..77759eb26 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextChapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextChapter.kt @@ -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, diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt index 11a3cf970..004de6ab7 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt @@ -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 = "", diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt index 346e651cd..318cad235 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt @@ -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, diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPos.kt b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPos.kt index eac680cda..841be4cd0 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPos.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPos.kt @@ -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, diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/entities/column/ButtonColumn.kt b/app/src/main/java/io/legado/app/ui/book/read/page/entities/column/ButtonColumn.kt index 33f4f0f88..f4ef14a74 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/entities/column/ButtonColumn.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/entities/column/ButtonColumn.kt @@ -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 diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/entities/column/ImageColumn.kt b/app/src/main/java/io/legado/app/ui/book/read/page/entities/column/ImageColumn.kt index 80b38a538..b4c91921e 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/entities/column/ImageColumn.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/entities/column/ImageColumn.kt @@ -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, diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/entities/column/ReviewColumn.kt b/app/src/main/java/io/legado/app/ui/book/read/page/entities/column/ReviewColumn.kt index 7bb8e51c9..5b035d20a 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/entities/column/ReviewColumn.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/entities/column/ReviewColumn.kt @@ -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, diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/entities/column/TextColumn.kt b/app/src/main/java/io/legado/app/ui/book/read/page/entities/column/TextColumn.kt index 0733c3b95..b30f8e970 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/entities/column/TextColumn.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/entities/column/TextColumn.kt @@ -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, diff --git a/app/src/main/java/io/legado/app/ui/config/CoverRuleConfigDialog.kt b/app/src/main/java/io/legado/app/ui/config/CoverRuleConfigDialog.kt index 34bd34c68..21aaa071c 100644 --- a/app/src/main/java/io/legado/app/ui/config/CoverRuleConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/config/CoverRuleConfigDialog.kt @@ -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) + } + } + } \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_cover_rule_config.xml b/app/src/main/res/layout/dialog_cover_rule_config.xml index 9d8082502..e09153226 100644 --- a/app/src/main/res/layout/dialog_cover_rule_config.xml +++ b/app/src/main/res/layout/dialog_cover_rule_config.xml @@ -85,12 +85,13 @@ android:layout_height="wrap_content" android:orientation="horizontal"> -