From 69b91657b806f406ab12fd920c47a2357586e290 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 14 May 2022 21:34:48 +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 --- .../association/BaseAssociationViewModel.kt | 52 ------------------- 1 file changed, 52 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/association/BaseAssociationViewModel.kt b/app/src/main/java/io/legado/app/ui/association/BaseAssociationViewModel.kt index 50548f15a..e2a4cfdf9 100644 --- a/app/src/main/java/io/legado/app/ui/association/BaseAssociationViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/association/BaseAssociationViewModel.kt @@ -2,16 +2,7 @@ package io.legado.app.ui.association import android.app.Application import androidx.lifecycle.MutableLiveData -import io.legado.app.R import io.legado.app.base.BaseViewModel -import io.legado.app.data.appDb -import io.legado.app.data.entities.TxtTocRule -import io.legado.app.exception.NoStackTraceException -import io.legado.app.help.config.ThemeConfig -import io.legado.app.utils.GSON -import io.legado.app.utils.fromJsonArray -import io.legado.app.utils.fromJsonObject -import io.legado.app.utils.isJsonArray abstract class BaseAssociationViewModel(application: Application) : BaseViewModel(application) { @@ -37,47 +28,4 @@ abstract class BaseAssociationViewModel(application: Application) : BaseViewMode } } - fun importTextTocRule(json: String, finally: (title: String, msg: String) -> Unit) { - execute { - if (json.isJsonArray()) { - GSON.fromJsonArray(json).getOrThrow()?.let { - appDb.txtTocRuleDao.insert(*it.toTypedArray()) - } ?: throw NoStackTraceException("格式不对") - } else { - GSON.fromJsonObject(json).getOrThrow()?.let { - appDb.txtTocRuleDao.insert(it) - } ?: throw NoStackTraceException("格式不对") - } - }.onSuccess { - finally.invoke(context.getString(R.string.success), "导入Txt规则成功") - }.onError { - finally.invoke( - context.getString(R.string.error), - it.localizedMessage ?: context.getString(R.string.unknown_error) - ) - } - } - - fun importTheme(json: String, finally: (title: String, msg: String) -> Unit) { - execute { - if (json.isJsonArray()) { - GSON.fromJsonArray(json).getOrThrow()?.forEach { - ThemeConfig.addConfig(it) - } - } else { - GSON.fromJsonObject(json).getOrThrow()?.let { - ThemeConfig.addConfig(it) - } - } - }.onSuccess { - finally.invoke(context.getString(R.string.success), "导入主题成功") - }.onError { - finally.invoke( - context.getString(R.string.error), - it.localizedMessage ?: context.getString(R.string.unknown_error) - ) - } - } - - } \ No newline at end of file