-
Notifications
You must be signed in to change notification settings - Fork 203
Expand file tree
/
Copy pathCustomHomeModel.kt
More file actions
39 lines (37 loc) · 1.66 KB
/
CustomHomeModel.kt
File metadata and controls
39 lines (37 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package com.skyd.imomoe.model.impls.custom
import com.skyd.imomoe.bean.TabBean
import com.skyd.imomoe.config.Api
import com.skyd.imomoe.config.UnknownActionUrl
import com.skyd.imomoe.model.util.JsoupUtil
import com.skyd.imomoe.model.interfaces.IHomeModel
import com.skyd.imomoe.util.eventbus.SelectHomeTabEvent
import org.greenrobot.eventbus.EventBus
import org.jsoup.select.Elements
class CustomHomeModel : IHomeModel {
override suspend fun getAllTabData(): ArrayList<TabBean> {
return ArrayList<TabBean>().apply {
val document = JsoupUtil.getDocument(Api.MAIN_URL)
val menu: Elements = document.getElementsByClass("menu")
val dmx_l: Elements = menu.select("[class=dmx l]").select("li")
for (i in dmx_l.indices) {
val url = dmx_l[i].select("a").attr("href")
add(TabBean("", url, Api.MAIN_URL + url, dmx_l[i].text()))
UnknownActionUrl.actionMap[url] = object : UnknownActionUrl.Action {
override fun action() {
EventBus.getDefault().post(SelectHomeTabEvent(url))
}
}
}
val dme_r: Elements = menu.select("[class=dme r]").select("li")
for (i in dme_r.indices) {
val url = dme_r[i].select("a").attr("href")
add(TabBean("", url, Api.MAIN_URL + url, dme_r[i].text()))
UnknownActionUrl.actionMap[url] = object : UnknownActionUrl.Action {
override fun action() {
EventBus.getDefault().post(SelectHomeTabEvent(url))
}
}
}
}
}
}