Skip to content

Commit

Permalink
[optimize|chore]优化插件API及插件载入;改进路由设计;升级部分组件
Browse files Browse the repository at this point in the history
  • Loading branch information
RyensX committed Feb 13, 2022
1 parent 8902a2b commit 1c96e07
Show file tree
Hide file tree
Showing 122 changed files with 2,303 additions and 1,209 deletions.
1 change: 1 addition & 0 deletions CustomDataSourceSample1/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
35 changes: 35 additions & 0 deletions CustomDataSourceSample1/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
plugins {
id 'com.android.library'
id 'kotlin-android'
}

android {
compileSdkVersion 31

defaultConfig {
minSdkVersion 21
targetSdkVersion 31

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}

dependencies {
implementation project(path: ':plugin')
implementation deps.jsoup.jsoup
}
Empty file.
21 changes: 21 additions & 0 deletions CustomDataSourceSample1/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.su.mediabox.customdatasourcesample1

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.su.mediabox.customdatasourcesample1.test", appContext.packageName)
}
}
5 changes: 5 additions & 0 deletions CustomDataSourceSample1/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.su.mediabox.customdatasourcesample1">

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
package com.su.mediabox.customdatasourcesample1

import com.su.mediabox.customdatasourcesample1.ParseHtmlUtil.parseBotit
import com.su.mediabox.plugin.Constant
import com.su.mediabox.plugin.Text.buildRouteActionUrl
import com.su.mediabox.plugin.interfaces.IAnimeDetailModel
import com.su.mediabox.plugin.standard.been.*
import org.jsoup.select.Elements

class CustomAnimeDetailModel : IAnimeDetailModel {
override suspend fun getAnimeDetailData(
partUrl: String
): Triple<ImageBean, String, ArrayList<IAnimeDetailBean>> {
val animeDetailList: ArrayList<IAnimeDetailBean> = ArrayList()
val cover = ImageBean("", "", "", "")
var title = ""
val url = CustomConst.MAIN_URL() + partUrl
val document = JsoupUtil.getDocument(url)
//番剧头部信息
val area: Elements = document.getElementsByClass("area")
for (i in area.indices) {
val areaChildren = area[i].children()
for (j in areaChildren.indices) {
when (areaChildren[j].className()) {
"fire l" -> {
var alias = ""
var info = ""
var year = ""
var index = ""
var animeArea = ""
val animeType: MutableList<AnimeTypeBean> = ArrayList()
val tag: MutableList<AnimeTypeBean> = ArrayList()

val fireLChildren =
areaChildren[j].select("[class=fire l]")[0].children()
for (k in fireLChildren.indices) {
when (fireLChildren[k].className()) {
"thumb l" -> {
cover.url = fireLChildren[k]
.select("img").attr("src")
cover.referer = url
}
"rate r" -> { //其他信息,如标签、地区等
val rateR = fireLChildren[k]
title = rateR.select("h1").text()
val sinfo: Elements = rateR.select("[class=sinfo]")
val span: Elements = sinfo.select("span")
val p: Elements = sinfo.select("p")
if (p.size == 1) {
alias = p[0].text()
} else if (p.size == 2) {
alias = p[0].text()
info = p[1].text()
}
year = span[0].text()
animeArea = span[1].select("a").text()
index = span[3].select("a").text()
val typeElements: Elements = span[2].select("a")
for (l in typeElements.indices) {
animeType.add(
AnimeTypeBean(
"",
buildRouteActionUrl(
Constant.ActionUrl.ANIME_CLASSIFY,
typeElements[l].attr("href")
),
CustomConst.MAIN_URL() + typeElements[l].attr("href"),
typeElements[l].text()
)
)
}
val tagElements: Elements = span[4].select("a")
for (l in tagElements.indices) {
tag.add(
AnimeTypeBean(
"",
buildRouteActionUrl(
Constant.ActionUrl.ANIME_CLASSIFY,
tagElements[l].attr("href")
),
CustomConst.MAIN_URL() + tagElements[l].attr("href"),
tagElements[l].text()
)
)
}
}
"tabs", "tabs noshow" -> { //播放列表+header
animeDetailList.add(
AnimeDetailBean(
Constant.ViewHolderTypeString.HEADER_1, "",
fireLChildren[k].select("[class=menu0]")
.select("li").text(),
"", null
)
)

animeDetailList.add(
AnimeDetailBean(
Constant.ViewHolderTypeString.HORIZONTAL_RECYCLER_VIEW_1,
"",
"",
"",
ParseHtmlUtil.parseMovurls(
fireLChildren[k].select("[class=main0]")
.select("[class=movurl]")[0]
)
)
)
}
"botit" -> { //其它header
animeDetailList.add(
AnimeDetailBean(
Constant.ViewHolderTypeString.HEADER_1, "",
parseBotit(fireLChildren[k]),
"", null
)
)
}
"dtit" -> { //其它header
animeDetailList.add(
AnimeDetailBean(
Constant.ViewHolderTypeString.HEADER_1, "",
ParseHtmlUtil.parseDtit(fireLChildren[k]),
"", null
)
)
}
"info" -> { //动漫介绍
animeDetailList.add(
AnimeDetailBean(
Constant.ViewHolderTypeString.ANIME_DESCRIBE_1, "",
"",
fireLChildren[k].select("[class=info]").text(),
null
)
)
}
"img" -> { //系列动漫推荐
animeDetailList.addAll(
ParseHtmlUtil.parseImg(fireLChildren[k], url)
)
}
}
}
val animeInfoBean = AnimeInfoBean(
"", "", title,
ImageBean("", "", cover.url, url),
alias, animeArea, year, index, animeType, tag, info
)
animeDetailList.add(
0,
AnimeDetailBean(
Constant.ViewHolderTypeString.ANIME_INFO_1, "",
"",
"",
headerInfo = animeInfoBean
)
)
}
}
}
}
return Triple(cover, title, animeDetailList)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
package com.su.mediabox.customdatasourcesample1

import com.su.mediabox.plugin.Constant
import com.su.mediabox.plugin.interfaces.IAnimeShowModel
import com.su.mediabox.plugin.standard.been.AnimeShowBean
import com.su.mediabox.plugin.standard.been.IAnimeShowBean
import com.su.mediabox.plugin.standard.been.PageNumberBean
import org.jsoup.select.Elements

class CustomAnimeShowModel : IAnimeShowModel {
override suspend fun getAnimeShowData(
partUrl: String
): Pair<ArrayList<IAnimeShowBean>, PageNumberBean?> {
val url = CustomConst.MAIN_URL() + partUrl
var pageNumberBean: PageNumberBean? = null
val document = JsoupUtil.getDocument(url)
val animeShowList: ArrayList<IAnimeShowBean> = ArrayList()
//banner
val foucsBgElements: Elements = document.getElementsByClass("foucs bg")
for (i in foucsBgElements.indices) {
val foucsBgChildren: Elements = foucsBgElements[i].children()
for (j in foucsBgChildren.indices) {
when (foucsBgChildren[j].className()) {
"hero-wrap" -> {
animeShowList.add(
AnimeShowBean(
Constant.ViewHolderTypeString.BANNER_1, "",
"", "", "", null, "",
ParseHtmlUtil.parseHeroWrap(
foucsBgChildren[j],
url
)
)
)
}
}
}
}
//area
var area: Elements = document.getElementsByClass("area")
if (partUrl == "/") //首页,有右边栏
area = document.getElementsByClass("area").select("[class=firs l]")
for (i in area.indices) {
val elements: Elements = area[i].children()
for (j in elements.indices) {
when (elements[j].className()) {
"dtit" -> {
val a = elements[j].select("h2").select("a")
if (a.size == 0) { //只有一个标题
animeShowList.add(
AnimeShowBean(
Constant.ViewHolderTypeString.HEADER_1,
"",
"",
elements[j].select("h2").text(),
"",
null,
""
)
)
} else { //有右侧“更多”
animeShowList.add(
AnimeShowBean(
Constant.ViewHolderTypeString.HEADER_1,
a.attr("href"),
CustomConst.MAIN_URL() + a.attr("href"),
a.text(),
elements[j].select("span").select("a").text(),
null,
""
)
)
}
}
"img", "imgs" -> {
animeShowList.addAll(
ParseHtmlUtil.parseImg(
elements[j],
url
)
)
}
"fire l" -> { //右侧前半tab内容
val firsLChildren = elements[j].children()
for (k in firsLChildren.indices) {
when (firsLChildren[k].className()) {
"lpic" -> {
animeShowList.addAll(
ParseHtmlUtil.parseLpic(
firsLChildren[k],
url
)
)
}
"pages" -> {
pageNumberBean =
ParseHtmlUtil.parseNextPages(
firsLChildren[k]
)
}
}
}
}
"dnews" -> { //右侧后半tab内容,cover4
animeShowList.addAll(
ParseHtmlUtil.parseDnews(
elements[j],
url
)
)
}
"topli" -> { //右侧后半tab内容,cover5
animeShowList.addAll(
ParseHtmlUtil.parseTopli(
elements[j]
)
)
}
"pages" -> {
pageNumberBean =
ParseHtmlUtil.parseNextPages(
elements[j]
)
}
}
}
}
return Pair(animeShowList, pageNumberBean)
}
}
Loading

0 comments on commit 1c96e07

Please sign in to comment.