Revert "优化"

This reverts commit 42300dc6
This commit is contained in:
kunfei
2023-03-21 23:53:36 +08:00
parent a45f6707bb
commit 38e47e1c01
12 changed files with 62 additions and 40 deletions
@@ -8,7 +8,6 @@ import io.legado.app.data.entities.BookSource
import io.legado.app.help.config.SourceConfig
import io.legado.app.utils.GSON
import io.legado.app.utils.fromJsonArray
import io.legado.app.utils.fromJsonObject
object BookSourceController {
@@ -24,7 +23,7 @@ object BookSourceController {
fun saveSource(postData: String?): ReturnData {
val returnData = ReturnData()
postData ?: return returnData.setErrorMsg("数据不能为空")
val bookSource = GSON.fromJsonObject<BookSource>(postData).getOrNull()
val bookSource = BookSource.fromJson(postData).getOrNull()
if (bookSource != null) {
if (TextUtils.isEmpty(bookSource.bookSourceName) || TextUtils.isEmpty(bookSource.bookSourceUrl)) {
returnData.setErrorMsg("源名称和URL不能为空")
@@ -41,7 +40,7 @@ object BookSourceController {
fun saveSources(postData: String?): ReturnData {
postData ?: return ReturnData().setErrorMsg("数据为空")
val okSources = arrayListOf<BookSource>()
val bookSources = GSON.fromJsonArray<BookSource>(postData).getOrNull()
val bookSources = BookSource.fromJsonArray(postData).getOrNull()
if (bookSources.isNullOrEmpty()) {
return ReturnData().setErrorMsg("转换源失败")
}
@@ -5,9 +5,6 @@ import android.text.TextUtils
import io.legado.app.api.ReturnData
import io.legado.app.data.appDb
import io.legado.app.data.entities.RssSource
import io.legado.app.utils.GSON
import io.legado.app.utils.fromJsonArray
import io.legado.app.utils.fromJsonObject
object RssSourceController {
@@ -23,7 +20,7 @@ object RssSourceController {
fun saveSource(postData: String?): ReturnData {
val returnData = ReturnData()
postData ?: return returnData.setErrorMsg("数据不能为空")
GSON.fromJsonObject<RssSource>(postData).onFailure {
RssSource.fromJson(postData).onFailure {
returnData.setErrorMsg("转换源失败${it.localizedMessage}")
}.onSuccess { source ->
if (TextUtils.isEmpty(source.sourceName) || TextUtils.isEmpty(source.sourceUrl)) {
@@ -39,7 +36,7 @@ object RssSourceController {
fun saveSources(postData: String?): ReturnData {
postData ?: return ReturnData().setErrorMsg("数据不能为空")
val okSources = arrayListOf<RssSource>()
val source = GSON.fromJsonArray<RssSource>(postData).getOrNull()
val source = RssSource.fromJsonArray(postData).getOrNull()
if (source.isNullOrEmpty()) {
return ReturnData().setErrorMsg("转换源失败")
}
@@ -66,7 +63,7 @@ object RssSourceController {
fun deleteSources(postData: String?): ReturnData {
postData ?: return ReturnData().setErrorMsg("没有传递数据")
GSON.fromJsonArray<RssSource>(postData).onFailure {
RssSource.fromJsonArray(postData).onFailure {
return ReturnData().setErrorMsg("格式不对")
}.onSuccess {
it.forEach { source ->