优化
This commit is contained in:
@@ -8,6 +8,7 @@ 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 {
|
||||
|
||||
@@ -23,7 +24,7 @@ object BookSourceController {
|
||||
fun saveSource(postData: String?): ReturnData {
|
||||
val returnData = ReturnData()
|
||||
postData ?: return returnData.setErrorMsg("数据不能为空")
|
||||
val bookSource = BookSource.fromJson(postData).getOrNull()
|
||||
val bookSource = GSON.fromJsonObject<BookSource>(postData).getOrNull()
|
||||
if (bookSource != null) {
|
||||
if (TextUtils.isEmpty(bookSource.bookSourceName) || TextUtils.isEmpty(bookSource.bookSourceUrl)) {
|
||||
returnData.setErrorMsg("源名称和URL不能为空")
|
||||
@@ -40,7 +41,7 @@ object BookSourceController {
|
||||
fun saveSources(postData: String?): ReturnData {
|
||||
postData ?: return ReturnData().setErrorMsg("数据为空")
|
||||
val okSources = arrayListOf<BookSource>()
|
||||
val bookSources = BookSource.fromJsonArray(postData).getOrNull()
|
||||
val bookSources = GSON.fromJsonArray<BookSource>(postData).getOrNull()
|
||||
if (bookSources.isNullOrEmpty()) {
|
||||
return ReturnData().setErrorMsg("转换源失败")
|
||||
}
|
||||
|
||||
@@ -5,6 +5,9 @@ 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 {
|
||||
|
||||
@@ -20,7 +23,7 @@ object RssSourceController {
|
||||
fun saveSource(postData: String?): ReturnData {
|
||||
val returnData = ReturnData()
|
||||
postData ?: return returnData.setErrorMsg("数据不能为空")
|
||||
RssSource.fromJson(postData).onFailure {
|
||||
GSON.fromJsonObject<RssSource>(postData).onFailure {
|
||||
returnData.setErrorMsg("转换源失败${it.localizedMessage}")
|
||||
}.onSuccess { source ->
|
||||
if (TextUtils.isEmpty(source.sourceName) || TextUtils.isEmpty(source.sourceUrl)) {
|
||||
@@ -36,7 +39,7 @@ object RssSourceController {
|
||||
fun saveSources(postData: String?): ReturnData {
|
||||
postData ?: return ReturnData().setErrorMsg("数据不能为空")
|
||||
val okSources = arrayListOf<RssSource>()
|
||||
val source = RssSource.fromJsonArray(postData).getOrNull()
|
||||
val source = GSON.fromJsonArray<RssSource>(postData).getOrNull()
|
||||
if (source.isNullOrEmpty()) {
|
||||
return ReturnData().setErrorMsg("转换源失败")
|
||||
}
|
||||
@@ -63,7 +66,7 @@ object RssSourceController {
|
||||
|
||||
fun deleteSources(postData: String?): ReturnData {
|
||||
postData ?: return ReturnData().setErrorMsg("没有传递数据")
|
||||
RssSource.fromJsonArray(postData).onFailure {
|
||||
GSON.fromJsonArray<RssSource>(postData).onFailure {
|
||||
return ReturnData().setErrorMsg("格式不对")
|
||||
}.onSuccess {
|
||||
it.forEach { source ->
|
||||
|
||||
Reference in New Issue
Block a user