pull/32/head
kunfei 5 years ago
parent a41346b6de
commit f78616d605
  1. 27
      app/src/main/java/io/legado/app/base/BaseViewModel.kt
  2. 5
      app/src/main/java/io/legado/app/ui/readbook/ReadBookViewModel.kt

@ -2,12 +2,11 @@ package io.legado.app.base
import android.app.Application
import androidx.lifecycle.AndroidViewModel
import io.legado.app.App
import io.legado.app.help.coroutine.Coroutine
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.cancel
import kotlinx.coroutines.*
import org.jetbrains.anko.AnkoLogger
import org.jetbrains.anko.toast
open class BaseViewModel(application: Application) : AndroidViewModel(application), CoroutineScope by MainScope(),
AnkoLogger {
@ -26,6 +25,26 @@ open class BaseViewModel(application: Application) : AndroidViewModel(applicatio
}
open fun toast(message: Int) {
launch {
getApplication<App>().toast(message)
}
}
open fun toast(message: CharSequence) {
launch {
getApplication<App>().toast(message)
}
}
open fun longToast(message: Int) {
launch {
getApplication<App>().toast(message)
}
}
open fun longToast(message: CharSequence) {
launch {
getApplication<App>().toast(message)
}
}
}

@ -12,7 +12,6 @@ import io.legado.app.data.entities.BookChapter
import io.legado.app.data.entities.BookSource
import io.legado.app.help.BookHelp
import io.legado.app.model.WebBook
import io.legado.app.utils.toast
import kotlinx.coroutines.Dispatchers.IO
class ReadBookViewModel(application: Application) : BaseViewModel(application) {
@ -43,10 +42,10 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
App.db.bookChapterDao().insert(*cList.toTypedArray())
chapterMaxIndex.postValue(cList.size)
} else {
toast(R.string.load_toc_error)
}
}?.onError {
getApplication<App>().toast(R.string.load_toc_error)
toast(R.string.load_toc_error)
} ?: autoChangeSource()
} else {
chapterMaxIndex.postValue(count)

Loading…
Cancel
Save