From 507ac06777ffaf3fb417d5c62bfde8e117d2066c Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 19 Aug 2019 09:23:02 +0800 Subject: [PATCH] up --- app/src/main/java/io/legado/app/base/BaseViewModel.kt | 3 +++ .../legado/app/ui/changesource/ChangeSourceViewModel.kt | 9 +++++---- 2 files changed, 8 insertions(+), 4 deletions(-) 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 df58bf2cb..096c6d562 100644 --- a/app/src/main/java/io/legado/app/base/BaseViewModel.kt +++ b/app/src/main/java/io/legado/app/base/BaseViewModel.kt @@ -1,6 +1,7 @@ package io.legado.app.base import android.app.Application +import android.content.Context import androidx.lifecycle.AndroidViewModel import io.legado.app.App import io.legado.app.help.coroutine.Coroutine @@ -11,6 +12,8 @@ import org.jetbrains.anko.toast open class BaseViewModel(application: Application) : AndroidViewModel(application), CoroutineScope by MainScope(), AnkoLogger { + val context: Context = this.getApplication() + fun execute(scope: CoroutineScope = this, block: suspend CoroutineScope.() -> T): Coroutine { return Coroutine.async(scope) { block() } } diff --git a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt index 998fab1e7..b4e889b96 100644 --- a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt @@ -9,6 +9,7 @@ import io.legado.app.data.entities.Book import io.legado.app.data.entities.SearchBook import io.legado.app.model.WebBook import kotlinx.coroutines.Dispatchers +import org.jetbrains.anko.debug class ChangeSourceViewModel(application: Application) : BaseViewModel(application) { var curBookUrl = "" @@ -56,9 +57,9 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio .onSuccess { it?.let { loadChapter(it) } }.onError { - toast(R.string.error_get_book_info) + debug { context.getString(R.string.error_get_book_info) } } - } ?: toast(R.string.error_no_source) + } ?: debug { context.getString(R.string.error_no_source) } } private fun loadChapter(book: Book) { @@ -72,9 +73,9 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio App.db.searchBookDao().insert(searchBook) } }.onError { - toast(R.string.error_get_chapter_list) + debug { context.getString(R.string.error_get_chapter_list) } } - } ?: toast(R.string.error_no_source) + } ?: debug { R.string.error_no_source } } fun screen(key: String?) {