在线朗读改为自定义

pull/332/head
gedoor 4 years ago
parent 4ae244acab
commit c3461f78b4
  1. 3
      app/src/main/java/io/legado/app/data/dao/HttpTTSDao.kt
  2. 13
      app/src/main/java/io/legado/app/ui/main/MainViewModel.kt

@ -13,6 +13,9 @@ interface HttpTTSDao {
@Query("select * from httpTTS order by name")
fun observeAll(): LiveData<List<HttpTTS>>
@get:Query("select count(*) from httpTTS")
val count: Int
@Query("select * from httpTTS where id = :id")
fun get(id: Long): HttpTTS?

@ -6,15 +6,13 @@ import io.legado.app.base.BaseViewModel
import io.legado.app.constant.BookType
import io.legado.app.constant.EventBus
import io.legado.app.data.entities.Book
import io.legado.app.data.entities.HttpTTS
import io.legado.app.data.entities.RssSource
import io.legado.app.help.AppConfig
import io.legado.app.help.http.HttpHelper
import io.legado.app.help.storage.Restore
import io.legado.app.model.WebBook
import io.legado.app.utils.FileUtils
import io.legado.app.utils.GSON
import io.legado.app.utils.fromJsonObject
import io.legado.app.utils.postEvent
import io.legado.app.utils.*
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.asCoroutineDispatcher
import kotlinx.coroutines.delay
@ -97,6 +95,13 @@ class MainViewModel(application: Application) : BaseViewModel(application) {
fun postLoad() {
execute {
FileUtils.deleteFile(FileUtils.getPath(context.cacheDir, "Fonts"))
if (App.db.httpTTSDao().count == 0) {
@Suppress("BlockingMethodInNonBlockingContext")
val json = String(App.INSTANCE.assets.open("httpTTS.json").readBytes())
GSON.fromJsonArray<HttpTTS>(json)?.let {
App.db.httpTTSDao().insert(*it.toTypedArray())
}
}
}
}
}
Loading…
Cancel
Save