# Conflicts: # app/src/main/java/io/legado/app/model/analyzeRule/RuleAnalyzer.ktpull/1114/head
commit
126f4d3991
@ -1,11 +1,30 @@ |
||||
package io.legado.app.ui.dict |
||||
|
||||
import android.app.Application |
||||
import androidx.lifecycle.AndroidViewModel |
||||
import androidx.lifecycle.MutableLiveData |
||||
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 org.jsoup.Jsoup |
||||
|
||||
class DictViewModel(application: Application) : AndroidViewModel(application) { |
||||
class DictViewModel(application: Application) : BaseViewModel(application) { |
||||
|
||||
var word: String? = null |
||||
var dictHtmlData: MutableLiveData<String> = MutableLiveData() |
||||
|
||||
fun dict(word: String) { |
||||
execute { |
||||
val body = okHttpClient.newCallStrResponse { |
||||
get("http://apii.dict.cn/mini.php", mapOf(Pair("q", word))) |
||||
}.body |
||||
val jsoup = Jsoup.parse(body) |
||||
jsoup.body() |
||||
}.onSuccess { |
||||
dictHtmlData.postValue(it.html()) |
||||
}.onError { |
||||
toastOnUi(it.localizedMessage) |
||||
} |
||||
|
||||
} |
||||
|
||||
} |
@ -0,0 +1,11 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content"> |
||||
|
||||
<TextView |
||||
android:id="@+id/tv_dict" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" /> |
||||
|
||||
</LinearLayout> |
Loading…
Reference in new issue