From 87e4ee063da508f2b3b4d74042012d41a8c64c02 Mon Sep 17 00:00:00 2001 From: gedoor Date: Thu, 22 Jul 2021 09:37:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/book/info/BookInfoViewModel.kt | 2 +- .../io/legado/app/ui/book/read/ReadBookViewModel.kt | 3 ++- .../app/ui/book/read/config/SpeakEngineViewModel.kt | 8 ++++---- .../ui/book/source/edit/BookSourceEditViewModel.kt | 9 +++++---- .../ui/book/source/manage/BookSourceViewModel.kt | 2 +- .../java/io/legado/app/ui/dict/DictViewModel.kt | 5 +++-- .../app/ui/main/bookshelf/BookshelfViewModel.kt | 4 ++-- .../app/ui/rss/article/RssArticlesViewModel.kt | 3 ++- .../ui/rss/source/edit/RssSourceEditViewModel.kt | 13 +++++-------- .../app/ui/rss/source/manage/RssSourceViewModel.kt | 2 +- 10 files changed, 26 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt index 69431dda2..ddb0f9b0d 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt @@ -135,7 +135,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { } } }.onError { - toastOnUi("LoadTocError:${it.localizedMessage}") + context.toastOnUi("LoadTocError:${it.localizedMessage}") } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt index ebafa58d0..036096cf3 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt @@ -20,6 +20,7 @@ import io.legado.app.service.BaseReadAloudService import io.legado.app.service.help.ReadAloud import io.legado.app.service.help.ReadBook import io.legado.app.utils.msg +import io.legado.app.utils.toastOnUi import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.withContext @@ -221,7 +222,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { }.onStart { ReadBook.upMsg(context.getString(R.string.source_auto_changing)) }.onError { - toastOnUi(it.msg) + context.toastOnUi(it.msg) }.onFinally { ReadBook.upMsg(null) } diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineViewModel.kt b/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineViewModel.kt index 89246859e..db11b0383 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineViewModel.kt @@ -27,9 +27,9 @@ class SpeakEngineViewModel(application: Application) : BaseViewModel(application import(json) } }.onSuccess { - toastOnUi("导入成功") + context.toastOnUi("导入成功") }.onError { - toastOnUi("导入失败") + context.toastOnUi("导入失败") } } @@ -39,9 +39,9 @@ class SpeakEngineViewModel(application: Application) : BaseViewModel(application import(it) } }.onSuccess { - toastOnUi("导入成功") + context.toastOnUi("导入成功") }.onError { - toastOnUi("导入失败") + context.toastOnUi("导入失败") } } diff --git a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt index 52818c97e..dbdd53ffd 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt @@ -9,6 +9,7 @@ import io.legado.app.help.storage.OldRule import io.legado.app.utils.GSON import io.legado.app.utils.fromJsonObject import io.legado.app.utils.getClipText +import io.legado.app.utils.toastOnUi import kotlinx.coroutines.Dispatchers class BookSourceEditViewModel(application: Application) : BaseViewModel(application) { @@ -46,7 +47,7 @@ class BookSourceEditViewModel(application: Application) : BaseViewModel(applicat }.onSuccess { success?.invoke() }.onError { - toastOnUi(it.localizedMessage) + context.toastOnUi(it.localizedMessage) it.printStackTrace() } } @@ -59,13 +60,13 @@ class BookSourceEditViewModel(application: Application) : BaseViewModel(applicat } source }.onError { - toastOnUi(it.localizedMessage) + context.toastOnUi(it.localizedMessage) it.printStackTrace() }.onSuccess { if (it != null) { onSuccess(it) } else { - toastOnUi("格式不对") + context.toastOnUi("格式不对") } } } @@ -77,7 +78,7 @@ class BookSourceEditViewModel(application: Application) : BaseViewModel(applicat finally.invoke(it) } }.onError { - toastOnUi(it.localizedMessage ?: "Error") + context.toastOnUi(it.localizedMessage ?: "Error") } } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt index 1432429ee..6cc8ea56a 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt @@ -178,7 +178,7 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application) }.onSuccess { success.invoke(it) }.onError { - toastOnUi(it.msg) + context.toastOnUi(it.msg) } } diff --git a/app/src/main/java/io/legado/app/ui/dict/DictViewModel.kt b/app/src/main/java/io/legado/app/ui/dict/DictViewModel.kt index 774876f76..473e424d6 100644 --- a/app/src/main/java/io/legado/app/ui/dict/DictViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/dict/DictViewModel.kt @@ -6,6 +6,7 @@ import io.legado.app.base.BaseViewModel import io.legado.app.help.http.get import io.legado.app.help.http.newCallStrResponse import io.legado.app.help.http.okHttpClient +import io.legado.app.utils.toastOnUi import org.jsoup.Jsoup class DictViewModel(application: Application) : BaseViewModel(application) { @@ -17,12 +18,12 @@ class DictViewModel(application: Application) : BaseViewModel(application) { val body = okHttpClient.newCallStrResponse { get("http://apii.dict.cn/mini.php", mapOf(Pair("q", word))) }.body - val jsoup = Jsoup.parse(body) + val jsoup = Jsoup.parse(body!!) jsoup.body() }.onSuccess { dictHtmlData.postValue(it.html()) }.onError { - toastOnUi(it.localizedMessage) + context.toastOnUi(it.localizedMessage) } } diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt index 2a178394a..7e8519cac 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt @@ -102,7 +102,7 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application) } } }.onError { - toastOnUi(it.localizedMessage ?: "ERROR") + context.toastOnUi(it.localizedMessage ?: "ERROR") } } @@ -125,7 +125,7 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application) } } }.onFinally { - toastOnUi(R.string.success) + context.toastOnUi(R.string.success) } } diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt index 0c672841f..b30579356 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt @@ -9,6 +9,7 @@ import io.legado.app.data.appDb import io.legado.app.data.entities.RssArticle import io.legado.app.data.entities.RssSource import io.legado.app.model.rss.Rss +import io.legado.app.utils.toastOnUi import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext @@ -52,7 +53,7 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application }.onError { loadFinally.postValue(false) it.printStackTrace() - toastOnUi(it.localizedMessage) + context.toastOnUi(it.localizedMessage) } } diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt index 38ace84df..7e14a56e8 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt @@ -5,10 +5,7 @@ import android.content.Intent import io.legado.app.base.BaseViewModel import io.legado.app.data.appDb import io.legado.app.data.entities.RssSource -import io.legado.app.utils.GSON -import io.legado.app.utils.fromJsonObject -import io.legado.app.utils.getClipText -import io.legado.app.utils.msg +import io.legado.app.utils.* import kotlinx.coroutines.Dispatchers class RssSourceEditViewModel(application: Application) : BaseViewModel(application) { @@ -40,7 +37,7 @@ class RssSourceEditViewModel(application: Application) : BaseViewModel(applicati }.onSuccess { success() }.onError { - toastOnUi(it.localizedMessage) + context.toastOnUi(it.localizedMessage) it.printStackTrace() } } @@ -53,12 +50,12 @@ class RssSourceEditViewModel(application: Application) : BaseViewModel(applicati } source }.onError { - toastOnUi(it.localizedMessage) + context.toastOnUi(it.localizedMessage) }.onSuccess { if (it != null) { onSuccess(it) } else { - toastOnUi("格式不对") + context.toastOnUi("格式不对") } } } @@ -70,7 +67,7 @@ class RssSourceEditViewModel(application: Application) : BaseViewModel(applicati finally.invoke(it) } }.onError { - toastOnUi(it.msg) + context.toastOnUi(it.msg) } } diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt index 408ca10f8..76b0ac1fe 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt @@ -120,7 +120,7 @@ class RssSourceViewModel(application: Application) : BaseViewModel(application) }.onSuccess { success.invoke(it) }.onError { - toastOnUi(it.msg) + context.toastOnUi(it.msg) } }