From 36617b413f03d1d19fd6d04415d89e3046c33aa4 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 22 Apr 2022 15:11:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/help/config/ReadBookConfig.kt | 4 +- .../io/legado/app/help/config/ThemeConfig.kt | 2 +- .../book/source/manage/BookSourceViewModel.kt | 4 ++ .../app/ui/replace/ReplaceRuleViewModel.kt | 4 ++ .../rss/source/manage/RssSourceViewModel.kt | 4 ++ .../io/legado/app/utils/DataExtensions.kt | 41 ------------------- 6 files changed, 15 insertions(+), 44 deletions(-) delete mode 100644 app/src/main/java/io/legado/app/utils/DataExtensions.kt diff --git a/app/src/main/java/io/legado/app/help/config/ReadBookConfig.kt b/app/src/main/java/io/legado/app/help/config/ReadBookConfig.kt index f6756deed..1a53a2956 100644 --- a/app/src/main/java/io/legado/app/help/config/ReadBookConfig.kt +++ b/app/src/main/java/io/legado/app/help/config/ReadBookConfig.kt @@ -328,7 +328,7 @@ object ReadBookConfig { } fun getExportConfig(): Config { - val exportConfig = durConfig.deepCopy() + val exportConfig = durConfig.copy() if (shareLayout) { exportConfig.textFont = shareConfig.textFont exportConfig.textBold = shareConfig.textBold @@ -430,7 +430,7 @@ object ReadBookConfig { } @Keep - class Config( + data class Config( var name: String = "", var bgStr: String = "#EEEEEE",//白天背景 var bgStrNight: String = "#000000",//夜间背景 diff --git a/app/src/main/java/io/legado/app/help/config/ThemeConfig.kt b/app/src/main/java/io/legado/app/help/config/ThemeConfig.kt index 84be2aaa4..f29bcfc5d 100644 --- a/app/src/main/java/io/legado/app/help/config/ThemeConfig.kt +++ b/app/src/main/java/io/legado/app/help/config/ThemeConfig.kt @@ -249,7 +249,7 @@ object ThemeConfig { } @Keep - class Config( + data class Config( var themeName: String, var isNightTheme: Boolean, var primaryColor: String, diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt index 4a24f70ac..390dd5ec2 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt @@ -9,6 +9,10 @@ import io.legado.app.utils.* import java.io.File import java.io.FileOutputStream +/** + * 书源管理数据修改 + * 修改数据要copy,直接修改会导致界面不刷新 + */ class BookSourceViewModel(application: Application) : BaseViewModel(application) { fun topSource(vararg sources: BookSource) { diff --git a/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleViewModel.kt b/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleViewModel.kt index 737a74f5a..3160b8fb7 100644 --- a/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleViewModel.kt @@ -7,6 +7,10 @@ import io.legado.app.data.appDb import io.legado.app.data.entities.ReplaceRule import io.legado.app.utils.splitNotBlank +/** + * 替换规则数据修改 + * 修改数据要copy,直接修改会导致界面不刷新 + */ class ReplaceRuleViewModel(application: Application) : BaseViewModel(application) { fun update(vararg rule: ReplaceRule) { diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt index 224e4db3d..8c48c12da 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt @@ -9,6 +9,10 @@ import io.legado.app.help.DefaultData import io.legado.app.utils.* import java.io.File +/** + * 订阅源管理数据修改 + * 修改数据要copy,直接修改会导致界面不刷新 + */ class RssSourceViewModel(application: Application) : BaseViewModel(application) { fun topSource(vararg sources: RssSource) { diff --git a/app/src/main/java/io/legado/app/utils/DataExtensions.kt b/app/src/main/java/io/legado/app/utils/DataExtensions.kt deleted file mode 100644 index 8e9f15404..000000000 --- a/app/src/main/java/io/legado/app/utils/DataExtensions.kt +++ /dev/null @@ -1,41 +0,0 @@ -package io.legado.app.utils - -import kotlin.reflect.KClass -import kotlin.reflect.full.memberProperties -import kotlin.reflect.full.primaryConstructor - -@Suppress("UNCHECKED_CAST") -fun T.deepCopy(): T { - //如果不是数据类,直接返回 - if (!this::class.isData) { - return this - } - - //拿到构造函数 - return this::class.primaryConstructor!!.let { primaryConstructor -> - //转换类型 - //memberProperties 返回非扩展属性中的第一个并将构造函数赋值给其 - //最终value=第一个参数类型的对象 - - //如果当前类(这里的当前类指的是参数对应的类型,比如说这里如果非基本类型时)是数据类 - - //最终返回一个新的映射map,即返回一个属性值重新组合的map,并调用callBy返回指定的对象 - primaryConstructor.parameters.associate { parameter -> - //转换类型 - //memberProperties 返回非扩展属性中的第一个并将构造函数赋值给其 - //最终value=第一个参数类型的对象 - val value = (this::class as KClass).memberProperties.first { - it.name == parameter.name - }.get(this) - - //如果当前类(这里的当前类指的是参数对应的类型,比如说这里如果非基本类型时)是数据类 - if ((parameter.type.classifier as? KClass<*>)?.isData == true) { - parameter to value?.deepCopy() - } else { - parameter to value - } - - //最终返回一个新的映射map,即返回一个属性值重新组合的map,并调用callBy返回指定的对象 - }.let(primaryConstructor::callBy) - } -} \ No newline at end of file