Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
<a href="https://img.shields.io/badge/Android-5.0%2B-brightgreen" style="text-decoration:none" >
<img src="https://img.shields.io/badge/Android-5.0%2B-brightgreen" alt="Android version"/>
</a>
<a href="https://pd.qq.com/s/1cii5y637" style="text-decoration:none" >
<img src="https://img.shields.io/badge/QQ-频道-red" alt="GitHub license"/>
</a>
<a href="https://discord.com/invite/K5GN7FaQuX" style="text-decoration:none" >
<img src="https://img.shields.io/discord/1201109322936090637?logo=discord" alt="GitHub license"/>
</a>
Expand Down Expand Up @@ -61,7 +64,7 @@
* #### ⭐**Star**鼓励开发者
* #### 👁️Watch关注开发进度
* #### 📇Pull requests(**请尽量贴合项目的源码和commit风格**)
* #### 💡加入[群组](https://discord.com/invite/K5GN7FaQuX)讨论反馈
* #### 💡加入[群组](https://pd.qq.com/s/1cii5y637)讨论反馈

## 安全说明

Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/com/su/mediabox/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package com.su.mediabox
import android.annotation.SuppressLint
import android.app.Application
import android.content.Context
import android.os.Handler
import android.os.Looper
import android.util.Log
import android.webkit.WebView
import com.liulishuo.filedownloader.FileDownloader
Expand Down Expand Up @@ -83,6 +85,7 @@ class App : Application() {
companion object {
@SuppressLint("StaticFieldLeak")
lateinit var context: Context
val mainHandler = Handler(Looper.getMainLooper())

init {
// 防止内存泄漏
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/su/mediabox/config/Const.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ interface Const {
"https://ryensx.github.io/MediaBoxPluginRepository/"
const val GITHUB_PLUGIN_REPO_DEV_DOC_URL = "https://github.com/RyensX/MediaBox/wiki"
const val USER_NOTICE_VERSION = 2
const val GROUP_URL = "https://discord.com/invite/K5GN7FaQuX"
const val GROUP_URL = "https://pd.qq.com/s/1cii5y637"
const val ANNOUNCEMENT="https://raw.githubusercontent.com/RyensX/MediaBox/dev/doc/announcement.json"

val licenses = listOf(
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/su/mediabox/net/DnsServer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ object DnsServer {
override fun equals(other: Any?): Boolean {
return when (other) {
null -> false
other === this -> true
(other === this) -> true
is String -> other == dnsServer
is Dns -> other.dnsServer == this.dnsServer && other.dnsName == this.dnsName
else -> false
Expand Down
8 changes: 7 additions & 1 deletion app/src/main/java/com/su/mediabox/plugin/Plugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ import java.io.File

object PluginManager {

private const val TAG = "PluginManager"

val appApiVersion by unsafeLazy {
val appInfo: ApplicationInfo = App.context.packageManager
.getApplicationInfo(
Expand Down Expand Up @@ -284,7 +286,7 @@ object PluginManager {
* @param pluginInfo 至少要保证包含有效[PluginInfo.sourcePath](作为下载地址)
* @param directInstall 直接下载安装,一般只用于官方仓库插件,不经安装器验证直接安装
*/
fun downloadPlugin(pluginInfo: PluginInfo, directInstall: Boolean = false) {
fun downloadPlugin(pluginInfo: PluginInfo, directInstall: Boolean = false) = runCatching {
val downloadManager =
App.context.getSystemService(AppCompatActivity.DOWNLOAD_SERVICE) as DownloadManager
val uri: Uri = Uri
Expand All @@ -302,6 +304,10 @@ object PluginManager {
setAllowedOverRoaming(true)
}
downloadManager.enqueue(request)
}.onFailure {
logE(TAG, "downloadPlugin: error=${it.message} directInstall=$directInstall pluginInfo=$pluginInfo")
"插件下载失败: ${it.message}".showToast()
it.printStackTrace()
}

fun initPluginEnv() {
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/su/mediabox/util/Activity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ fun <T : Action> putAction(action: T) {
}

@Suppress("UNCHECKED_CAST")
fun <T : Action> getActionIns(actionClass: Class<T>): T? =
fun <T : Action> consumeActionIns(actionClass: Class<T>): T? =
(actionPoolMap[actionClass.simpleName] as? T)?.also {
actionPoolMap.remove(actionClass.simpleName)
}

inline fun <reified T : Action> getAction(): T? = getActionIns(T::class.java)
inline fun <reified T : Action> consumeAction(): T? = consumeActionIns(T::class.java)

fun <VB : ViewBinding> Activity.viewBind(inflater: (LayoutInflater) -> VB) =
lazy(LazyThreadSafetyMode.NONE) {
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/su/mediabox/util/CoroutineUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ private class ViewCoroutineInterceptor(
private class ViewStateListener(private val view: View, private val job: Job) :
View.OnAttachStateChangeListener, CompletionHandler {

override fun onViewAttachedToWindow(v: View?) {}
override fun onViewAttachedToWindow(v: View) {}

//在Recyclerview上使用LinearLayoutManager可能并不会调用,取决于mRecycleChildrenOnDetach,因此必须手动调用setRecycleChildrenOnDetach(true)
override fun onViewDetachedFromWindow(v: View?) {
override fun onViewDetachedFromWindow(v: View) {
logD("View协程", "分离视图->取消")
view.removeOnAttachStateChangeListener(this)
job.cancel()
Expand Down
9 changes: 5 additions & 4 deletions app/src/main/java/com/su/mediabox/util/coil/CoilUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ object CoilUtil {
logE("loadImage", "图片来源有误!")
return@runCatching
}
logD("加载图片","url=$urlOrBase64")
val time = System.currentTimeMillis()
when {
urlOrBase64.startsWith("data:image") -> {
Expand Down Expand Up @@ -90,10 +91,10 @@ object CoilUtil {
?.let {
addHeader("Referer", it)
}
addHeader("Host", URL(urlOrBase64).host)
addHeader("Accept", "*/*")
addHeader("Accept-Encoding", "gzip, deflate")
addHeader("Connection", "keep-alive")
// addHeader("Host", URL(urlOrBase64).host)
// addHeader("Accept", "*/*")
// addHeader("Accept-Encoding", "gzip, deflate")
// addHeader("Connection", "keep-alive")
addHeader("User-Agent", Constant.Request.getRandomUserAgent())
listener { _, _ ->
logD("图片加载完毕", "time=$time url=$urlOrBase64", false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ class GettingWebView @JvmOverloads constructor(
}
mWebSettings.javaScriptCanOpenWindowsAutomatically = true
mWebSettings.loadsImagesAutomatically = false
mWebSettings.setAppCacheEnabled(true)
mWebSettings.setAppCachePath(context.cacheDir.absolutePath)
mWebSettings.databaseEnabled = true
mWebSettings.setGeolocationDatabasePath(context.getDir("database", 0).path)
mWebSettings.setGeolocationEnabled(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,12 @@ class MediaClassifyActivity : BasePluginActivity() {
mBinding.mediaClassifyFabProgress.invisible()
"加载分类错误:${it.throwable?.message}".showToast()
}
else -> {}
}
}

//如果传入分类,则直接开始加载分类数据,否则自动加载分类项数据并打开弹窗
getAction<ClassifyAction>()?.also {
consumeAction<ClassifyAction>()?.also {
mediaClassify.currentClassifyAction = it
viewModel.getClassifyData(it)
} ?: viewModel.getClassifyItemData()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class MediaDetailActivity : BasePluginActivity() {

logD("获取VM", "@${viewModel}")

getAction<DetailAction>()?.also {
consumeAction<DetailAction>()?.also {
viewModel.partUrl = it.url
}

Expand Down Expand Up @@ -111,7 +111,7 @@ class MediaDetailActivity : BasePluginActivity() {
override fun startActivity(intent: Intent?, options: Bundle?) {
//主动向下一级路由目标提供一些信息
intent?.apply {
getAction<PlayAction>()?.apply {
consumeAction<PlayAction>()?.apply {
coverUrl = viewModel.cover
detailPartUrl = viewModel.partUrl
videoName = viewModel.title
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class MediaSearchActivity : BasePluginActivity() {
}
}

getAction<SearchAction>()?.also {
consumeAction<SearchAction>()?.also {
viewModel.getSearchData(it.keyWork)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class VideoMediaPlayActivity : BasePluginActivity(),
VideoMediaPlayer.PlayOperatingProxy {

companion object {
var playList: List<EpisodeData>? = null
private const val DEFAULT_SEEK_LENGTH = 15000L
const val DEFAULT_VIDEO_PRELOAD_SIZE = 5
}
Expand All @@ -63,10 +62,12 @@ class VideoMediaPlayActivity : BasePluginActivity(),

setFullScreen(window)

getAction<PlayAction>()?.also { action ->
consumeAction<PlayAction>()?.also { action ->
this.action = action
init()
viewModel.apply {
val playList = action.extraData as? List<EpisodeData>
playList?.let { init(it) }
detailPartUrl = action.detailPartUrl
coverUrl = action.coverUrl
videoName = action.videoName
Expand All @@ -85,6 +86,7 @@ class VideoMediaPlayActivity : BasePluginActivity(),
}
visible()
}

is DataState.Success -> dataState.data?.also {
mBinding.vmPlay.playVideo(
it.videoPlayUrl,
Expand All @@ -93,6 +95,7 @@ class VideoMediaPlayActivity : BasePluginActivity(),
mBinding.vmLoadingLayer.gone()
mBinding.vmErrorRetry.gone()
}

is DataState.Failed -> {
dataState.throwable?.message?.showToast()
mBinding.vmLoadingLayer.apply {
Expand All @@ -102,6 +105,7 @@ class VideoMediaPlayActivity : BasePluginActivity(),
visible()
}
}

else -> Unit
}
}
Expand Down Expand Up @@ -211,6 +215,7 @@ class VideoMediaPlayActivity : BasePluginActivity(),
onVideoResume()
}
}

KeyEvent.KEYCODE_DPAD_LEFT, KeyEvent.KEYCODE_MEDIA_STEP_BACKWARD ->
//减速
if (event?.isShiftPressed == true) {
Expand Down Expand Up @@ -270,8 +275,6 @@ class VideoMediaPlayActivity : BasePluginActivity(),
mBinding.vmPlay.setVideoAllCallBack(null)
GSYVideoManager.releaseAllVideos()
orientationUtils.releaseListener()
//释放播放列表
playList = null
}
super.onDestroy()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import com.su.mediabox.databinding.ActivityWebViewBinding
import com.su.mediabox.plugin.WebUtilImpl.clearWeb
import com.su.mediabox.pluginapi.action.WebBrowserAction
import com.su.mediabox.util.Util.openUrl
import com.su.mediabox.util.getAction
import com.su.mediabox.util.consumeAction
import com.su.mediabox.util.logD
import com.su.mediabox.util.logE
import com.su.mediabox.util.viewBind
Expand All @@ -27,7 +27,7 @@ class WebViewActivity : BasePluginActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

mAction = getAction() ?: run {
mAction = consumeAction() ?: run {
finish()
return
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/su/mediabox/view/component/PointView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ class PointView(context: Context, attributeSet: AttributeSet) : View(context, at
}
get() = paint.color

override fun onDraw(canvas: Canvas?) {
override fun onDraw(canvas: Canvas) {
super.onDraw(canvas)
val radius = pointSize / 2
canvas?.drawCircle(width / 2F, height / 2F, radius, paint)
canvas.drawCircle(width / 2F, height / 2F, radius, paint)
}

override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
Expand Down
Loading