|
|
@ -5,7 +5,6 @@ import android.text.TextUtils |
|
|
|
import io.legado.app.api.ReturnData |
|
|
|
import io.legado.app.api.ReturnData |
|
|
|
import io.legado.app.data.appDb |
|
|
|
import io.legado.app.data.appDb |
|
|
|
import io.legado.app.data.entities.RssSource |
|
|
|
import io.legado.app.data.entities.RssSource |
|
|
|
import io.legado.app.utils.msg |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
object RssSourceController { |
|
|
|
object RssSourceController { |
|
|
|
|
|
|
|
|
|
|
@ -21,20 +20,15 @@ object RssSourceController { |
|
|
|
fun saveSource(postData: String?): ReturnData { |
|
|
|
fun saveSource(postData: String?): ReturnData { |
|
|
|
val returnData = ReturnData() |
|
|
|
val returnData = ReturnData() |
|
|
|
postData ?: return returnData.setErrorMsg("数据不能为空") |
|
|
|
postData ?: return returnData.setErrorMsg("数据不能为空") |
|
|
|
kotlin.runCatching { |
|
|
|
RssSource.fromJson(postData).onFailure { |
|
|
|
val source = RssSource.fromJson(postData) |
|
|
|
returnData.setErrorMsg("转换源失败${it.localizedMessage}") |
|
|
|
if (source != null) { |
|
|
|
}.onSuccess { source -> |
|
|
|
if (TextUtils.isEmpty(source.sourceName) || TextUtils.isEmpty(source.sourceUrl)) { |
|
|
|
if (TextUtils.isEmpty(source.sourceName) || TextUtils.isEmpty(source.sourceUrl)) { |
|
|
|
returnData.setErrorMsg("源名称和URL不能为空") |
|
|
|
returnData.setErrorMsg("源名称和URL不能为空") |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
appDb.rssSourceDao.insert(source) |
|
|
|
appDb.rssSourceDao.insert(source) |
|
|
|
returnData.setData("") |
|
|
|
returnData.setData("") |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
|
|
|
|
returnData.setErrorMsg("转换源失败") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}.onFailure { |
|
|
|
|
|
|
|
returnData.setErrorMsg(it.msg) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return returnData |
|
|
|
return returnData |
|
|
|
} |
|
|
|
} |
|
|
@ -42,8 +36,10 @@ object RssSourceController { |
|
|
|
fun saveSources(postData: String?): ReturnData { |
|
|
|
fun saveSources(postData: String?): ReturnData { |
|
|
|
postData ?: return ReturnData().setErrorMsg("数据不能为空") |
|
|
|
postData ?: return ReturnData().setErrorMsg("数据不能为空") |
|
|
|
val okSources = arrayListOf<RssSource>() |
|
|
|
val okSources = arrayListOf<RssSource>() |
|
|
|
val source = RssSource.fromJsonArray(postData) |
|
|
|
val source = RssSource.fromJsonArray(postData).getOrNull() |
|
|
|
if (source.isNotEmpty()) { |
|
|
|
if (source.isNullOrEmpty()) { |
|
|
|
|
|
|
|
return ReturnData().setErrorMsg("转换源失败") |
|
|
|
|
|
|
|
} |
|
|
|
for (rssSource in source) { |
|
|
|
for (rssSource in source) { |
|
|
|
if (rssSource.sourceName.isBlank() || rssSource.sourceUrl.isBlank()) { |
|
|
|
if (rssSource.sourceName.isBlank() || rssSource.sourceUrl.isBlank()) { |
|
|
|
continue |
|
|
|
continue |
|
|
@ -51,9 +47,6 @@ object RssSourceController { |
|
|
|
appDb.rssSourceDao.insert(rssSource) |
|
|
|
appDb.rssSourceDao.insert(rssSource) |
|
|
|
okSources.add(rssSource) |
|
|
|
okSources.add(rssSource) |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
|
|
|
|
return ReturnData().setErrorMsg("转换源失败") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return ReturnData().setData(okSources) |
|
|
|
return ReturnData().setData(okSources) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -70,13 +63,13 @@ object RssSourceController { |
|
|
|
|
|
|
|
|
|
|
|
fun deleteSources(postData: String?): ReturnData { |
|
|
|
fun deleteSources(postData: String?): ReturnData { |
|
|
|
postData ?: return ReturnData().setErrorMsg("没有传递数据") |
|
|
|
postData ?: return ReturnData().setErrorMsg("没有传递数据") |
|
|
|
kotlin.runCatching { |
|
|
|
RssSource.fromJsonArray(postData).onFailure { |
|
|
|
RssSource.fromJsonArray(postData).let { |
|
|
|
return ReturnData().setErrorMsg("格式不对") |
|
|
|
|
|
|
|
}.onSuccess { |
|
|
|
it.forEach { source -> |
|
|
|
it.forEach { source -> |
|
|
|
appDb.rssSourceDao.delete(source) |
|
|
|
appDb.rssSourceDao.delete(source) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return ReturnData().setData("已执行"/*okSources*/) |
|
|
|
return ReturnData().setData("已执行"/*okSources*/) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|