pull/1155/head
gedoor 3 years ago
parent a3f278551a
commit 87e4ee063d
  1. 2
      app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt
  2. 3
      app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt
  3. 8
      app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineViewModel.kt
  4. 9
      app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt
  5. 2
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt
  6. 5
      app/src/main/java/io/legado/app/ui/dict/DictViewModel.kt
  7. 4
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt
  8. 3
      app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt
  9. 13
      app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt
  10. 2
      app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt

@ -135,7 +135,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
}
}
}.onError {
toastOnUi("LoadTocError:${it.localizedMessage}")
context.toastOnUi("LoadTocError:${it.localizedMessage}")
}
}

@ -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)
}

@ -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("导入失败")
}
}

@ -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")
}
}
}

@ -178,7 +178,7 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application)
}.onSuccess {
success.invoke(it)
}.onError {
toastOnUi(it.msg)
context.toastOnUi(it.msg)
}
}

@ -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)
}
}

@ -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)
}
}

@ -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)
}
}

@ -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)
}
}

@ -120,7 +120,7 @@ class RssSourceViewModel(application: Application) : BaseViewModel(application)
}.onSuccess {
success.invoke(it)
}.onError {
toastOnUi(it.msg)
context.toastOnUi(it.msg)
}
}

Loading…
Cancel
Save