|
|
@ -4,13 +4,11 @@ import android.app.Application |
|
|
|
import io.legado.app.App |
|
|
|
import io.legado.app.App |
|
|
|
import io.legado.app.base.BaseViewModel |
|
|
|
import io.legado.app.base.BaseViewModel |
|
|
|
import io.legado.app.constant.Bus |
|
|
|
import io.legado.app.constant.Bus |
|
|
|
import io.legado.app.data.api.IHttpGetApi |
|
|
|
|
|
|
|
import io.legado.app.data.entities.RssSource |
|
|
|
import io.legado.app.data.entities.RssSource |
|
|
|
import io.legado.app.help.http.HttpHelper |
|
|
|
import io.legado.app.help.http.HttpHelper |
|
|
|
import io.legado.app.help.storage.Restore |
|
|
|
import io.legado.app.help.storage.Restore |
|
|
|
import io.legado.app.model.WebBook |
|
|
|
import io.legado.app.model.WebBook |
|
|
|
import io.legado.app.utils.GSON |
|
|
|
import io.legado.app.utils.GSON |
|
|
|
import io.legado.app.utils.NetworkUtils |
|
|
|
|
|
|
|
import io.legado.app.utils.fromJsonObject |
|
|
|
import io.legado.app.utils.fromJsonObject |
|
|
|
import io.legado.app.utils.postEvent |
|
|
|
import io.legado.app.utils.postEvent |
|
|
|
import kotlinx.coroutines.Dispatchers.IO |
|
|
|
import kotlinx.coroutines.Dispatchers.IO |
|
|
@ -58,20 +56,16 @@ class MainViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
fun initRss() { |
|
|
|
fun initRss() { |
|
|
|
execute { |
|
|
|
execute { |
|
|
|
val url = "https://gitee.com/alanskycn/yuedu/raw/master/JS/RSS/rssSource" |
|
|
|
val url = "https://gitee.com/alanskycn/yuedu/raw/master/JS/RSS/rssSource" |
|
|
|
NetworkUtils.getBaseUrl(url)?.let { |
|
|
|
HttpHelper.simpleGet(url)?.let { body -> |
|
|
|
val response = |
|
|
|
val sources = mutableListOf<RssSource>() |
|
|
|
HttpHelper.getApiService<IHttpGetApi>(it).getAsync(url, mapOf()).await() |
|
|
|
val items: List<Map<String, Any>> = Restore.jsonPath.parse(body).read("$") |
|
|
|
response.body()?.let { body -> |
|
|
|
for (item in items) { |
|
|
|
val sources = mutableListOf<RssSource>() |
|
|
|
val jsonItem = Restore.jsonPath.parse(item) |
|
|
|
val items: List<Map<String, Any>> = Restore.jsonPath.parse(body).read("$") |
|
|
|
GSON.fromJsonObject<RssSource>(jsonItem.jsonString())?.let { source -> |
|
|
|
for (item in items) { |
|
|
|
sources.add(source) |
|
|
|
val jsonItem = Restore.jsonPath.parse(item) |
|
|
|
|
|
|
|
GSON.fromJsonObject<RssSource>(jsonItem.jsonString())?.let { source -> |
|
|
|
|
|
|
|
sources.add(source) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
App.db.rssSourceDao().insert(*sources.toTypedArray()) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
App.db.rssSourceDao().insert(*sources.toTypedArray()) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|