diff --git a/app/src/main/java/io/legado/app/base/BaseViewModel.kt b/app/src/main/java/io/legado/app/base/BaseViewModel.kt index e14fa7a3d..df58bf2cb 100644 --- a/app/src/main/java/io/legado/app/base/BaseViewModel.kt +++ b/app/src/main/java/io/legado/app/base/BaseViewModel.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().toast(message) + } + } + + open fun toast(message: CharSequence) { + launch { + getApplication().toast(message) + } + } + + open fun longToast(message: Int) { + launch { + getApplication().toast(message) + } + } + open fun longToast(message: CharSequence) { + launch { + getApplication().toast(message) + } } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/readbook/ReadBookViewModel.kt b/app/src/main/java/io/legado/app/ui/readbook/ReadBookViewModel.kt index 6b023c7a0..69e0d11b7 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/ReadBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/ReadBookViewModel.kt @@ -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().toast(R.string.load_toc_error) + toast(R.string.load_toc_error) } ?: autoChangeSource() } else { chapterMaxIndex.postValue(count)