diff --git a/Aria/build.gradle b/Aria/build.gradle index eb4bcee7..9ae11290 100644 --- a/Aria/build.gradle +++ b/Aria/build.gradle @@ -25,6 +25,7 @@ dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') testImplementation(libs.bundles.android.test) implementation(libs.appcompat) + implementation(libs.timber) api project(path: ':AriaAnnotations') api project(path: ':PublicComponent') api project(path: ':HttpComponent') diff --git a/Aria/src/main/java/com/arialyy/aria/core/Dua.kt b/Aria/src/main/java/com/arialyy/aria/core/Dua.kt new file mode 100644 index 00000000..e8366a0d --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/core/Dua.kt @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.arialyy.aria.core + +import androidx.lifecycle.DefaultLifecycleObserver +import androidx.lifecycle.Lifecycle.Event +import androidx.lifecycle.LifecycleEventObserver +import androidx.lifecycle.LifecycleOwner +import com.arialyy.aria.core.common.receiver.LifLifecycleReceiver + +/** + * @Author laoyuyu + * @Description + * @Date 10:48 AM 2023/1/20 + **/ +object Dua { + + fun with(lifecycle: LifecycleOwner): LifLifecycleReceiver { + return LifLifecycleReceiver(lifecycle) + } +} \ No newline at end of file diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/receiver/LifLifecycleReceiver.kt b/Aria/src/main/java/com/arialyy/aria/core/common/receiver/LifLifecycleReceiver.kt new file mode 100644 index 00000000..83a1b66d --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/core/common/receiver/LifLifecycleReceiver.kt @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.arialyy.aria.core.common.receiver + +import androidx.lifecycle.DefaultLifecycleObserver +import androidx.lifecycle.LifecycleOwner +import com.arialyy.aria.core.inf.IComponentLoader +import com.arialyy.aria.core.inf.IDuaReceiver +import com.arialyy.aria.core.scheduler.TaskSchedulers +import java.lang.reflect.Proxy + +/** + * @Author laoyuyu + * @Description + * @Date 11:42 AM 2023/1/20 + **/ +class LifLifecycleReceiver(val lifecycle: LifecycleOwner) : IDuaReceiver { + + /** + * You need to associate the appropriate component dependencies + * @param clazz eg: HttpLoader, FtpLoader + */ + fun setLoader(clazz: Class): T { + return Proxy.newProxyInstance( + javaClass.classLoader, arrayOf(IComponentLoader::class.java) + ) { proxy, method, args -> + val result = method.invoke(proxy, args) + if (method.name in IComponentLoader.proxyMethods) { + lifecycle.lifecycle.addObserver(object : DefaultLifecycleObserver { + override fun onCreate(owner: LifecycleOwner) { + super.onCreate(owner) + TaskSchedulers.getInstance() + .register(lifecycle, (proxy as IComponentLoader).getTaskEnum()) + } + + override fun onDestroy(owner: LifecycleOwner) { + super.onDestroy(owner) + TaskSchedulers.getInstance().unRegister(lifecycle) + } + }) + } + return@newProxyInstance result + } as T + } +} \ No newline at end of file diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/IDuaReceiver.kt b/Aria/src/main/java/com/arialyy/aria/core/inf/IDuaReceiver.kt new file mode 100644 index 00000000..fae483c6 --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/IDuaReceiver.kt @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.arialyy.aria.core.inf + +/** + * @Author laoyuyu + * @Description + * @Date 11:34 AM 2023/1/20 + **/ +interface IDuaReceiver { +} \ No newline at end of file diff --git a/Aria/src/main/java/com/arialyy/aria/core/manager/LifecycleManager.kt b/Aria/src/main/java/com/arialyy/aria/core/manager/LifecycleManager.kt new file mode 100644 index 00000000..c125edb4 --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/core/manager/LifecycleManager.kt @@ -0,0 +1,91 @@ +/* + * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.arialyy.aria.core.manager + +import androidx.lifecycle.DefaultLifecycleObserver +import androidx.lifecycle.Lifecycle +import androidx.lifecycle.LifecycleOwner +import com.arialyy.annotations.TaskEnum +import com.arialyy.aria.core.common.ProxyHelper +import com.arialyy.aria.core.download.DownloadGroupTaskListener +import com.arialyy.aria.core.download.DownloadTaskListener +import com.arialyy.aria.core.scheduler.M3U8PeerTaskListener +import com.arialyy.aria.core.scheduler.SubTaskListener +import com.arialyy.aria.core.scheduler.TaskInternalListenerInterface +import com.arialyy.aria.core.scheduler.TaskSchedulers +import com.arialyy.aria.util.ALog +import timber.log.Timber +import java.util.Timer + +/** + * @Author laoyuyu + * @Description + * @Date 10:55 AM 2023/1/20 + **/ +object LifecycleManager { + + private fun register(obj: Any) { + if (obj is TaskInternalListenerInterface) { + ProxyHelper.getInstance().checkProxyType(obj.javaClass) + if (obj is DownloadTaskListener) { + TaskSchedulers.getInstance().register(obj, TaskEnum.DOWNLOAD) + } + if (obj is DownloadGroupTaskListener) { + TaskSchedulers.getInstance().register(obj, TaskEnum.DOWNLOAD_GROUP) + } + if (obj is M3U8PeerTaskListener) { + TaskSchedulers.getInstance().register(obj, TaskEnum.M3U8_PEER) + } + if (obj is SubTaskListener<*, *>) { + TaskSchedulers.getInstance().register(obj, TaskEnum.DOWNLOAD_GROUP_SUB) + } + return + } + val set: Set = ProxyHelper.getInstance().checkProxyType(obj.javaClass) + if (set.isNotEmpty()) { + for (type in set) { + when (type) { + ProxyHelper.PROXY_TYPE_DOWNLOAD -> { + TaskSchedulers.getInstance().register(obj, TaskEnum.DOWNLOAD) + } + ProxyHelper.PROXY_TYPE_DOWNLOAD_GROUP -> { + TaskSchedulers.getInstance().register(obj, TaskEnum.DOWNLOAD_GROUP) + } + ProxyHelper.PROXY_TYPE_M3U8_PEER -> { + TaskSchedulers.getInstance().register(obj, TaskEnum.M3U8_PEER) + } + ProxyHelper.PROXY_TYPE_DOWNLOAD_GROUP_SUB -> { + TaskSchedulers.getInstance().register(obj, TaskEnum.DOWNLOAD_GROUP_SUB) + } + } + } + return + } + Timber.e("没有Aria的注解方法,详情见:https://aria.laoyuyu.me/aria_doc/other/annotaion_invalid.html") + } + + fun addObserver(lifecycle: Lifecycle) { + lifecycle.addObserver(DuaObserver(lifecycle)) + } + + private class DuaObserver(val obj: Lifecycle) : DefaultLifecycleObserver { + override fun onCreate(owner: LifecycleOwner) { + super.onCreate(owner) + register(obj) + } + } +} + diff --git a/HttpComponent/src/main/java/com/arialyy/aria/http/HttpComponentLoader.kt b/HttpComponent/src/main/java/com/arialyy/aria/http/HttpComponentLoader.kt new file mode 100644 index 00000000..3d87162b --- /dev/null +++ b/HttpComponent/src/main/java/com/arialyy/aria/http/HttpComponentLoader.kt @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.arialyy.aria.http + +import com.arialyy.annotations.TaskEnum +import com.arialyy.aria.core.inf.IBaseLoader +import com.arialyy.aria.core.inf.IComponentLoader +import com.arialyy.aria.core.inf.IDownloader +import com.arialyy.aria.http.download.HttpDownloader +import kotlin.LazyThreadSafetyMode.SYNCHRONIZED + +/** + * @Author laoyuyu + * @Description + * @Date 14:07 AM 2023/1/20 + **/ +class HttpComponentLoader : IComponentLoader { + + private val downloader by lazy(SYNCHRONIZED) { + HttpDownloader() + } + private lateinit var loader: IBaseLoader + + override fun download(): T { + loader = downloader + return downloader as T + } + + override fun getTaskEnum(): TaskEnum { + return loader.getTaskEnum() + } +} \ No newline at end of file diff --git a/HttpComponent/src/main/java/com/arialyy/aria/http/HttpOption.kt b/HttpComponent/src/main/java/com/arialyy/aria/http/HttpOption.kt new file mode 100644 index 00000000..6df412ff --- /dev/null +++ b/HttpComponent/src/main/java/com/arialyy/aria/http/HttpOption.kt @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.arialyy.aria.http + +/** + * @Author laoyuyu + * @Description + * @Date 14:27 AM 2023/1/20 + **/ +class HttpOption { + + fun se + +} diff --git a/HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDownloader.kt b/HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDownloader.kt new file mode 100644 index 00000000..b16ba7d5 --- /dev/null +++ b/HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDownloader.kt @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.arialyy.aria.http.download + +import com.arialyy.annotations.TaskEnum +import com.arialyy.annotations.TaskEnum.DOWNLOAD +import com.arialyy.aria.core.inf.IDownloader +import com.arialyy.aria.http.HttpOption + +/** + * @Author laoyuyu + * @Description + * @Date 14:11 AM 2023/1/20 + **/ +internal class HttpDownloader : IDownloader { + private lateinit var uri: String + private lateinit var savePath: String + private var httpOption = HttpOption() + + override fun getTaskEnum(): TaskEnum { + return DOWNLOAD + } + + fun setSourceUri(uri: String): HttpDownloader { + this.uri = uri + return this + } + + fun setSavePath(savePath: String): HttpDownloader { + this.savePath = savePath + return this + } + + fun setHttpOption(httpOption: HttpOption): HttpDownloader { + this.httpOption = httpOption + return this + } + + +} \ No newline at end of file diff --git a/PublicComponent/build.gradle b/PublicComponent/build.gradle index ce6d8d73..710e14b7 100644 --- a/PublicComponent/build.gradle +++ b/PublicComponent/build.gradle @@ -26,22 +26,22 @@ android { lintOptions { abortOnError false } - } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) + api project(path: ':AriaAnnotations') testImplementation(libs.bundles.android.test) implementation(libs.appcompat) implementation(libs.bundles.room) implementation(libs.startup) - implementation(libs.timber) + api(libs.timber) implementation(libs.gson) kapt libs.room.compiler } //apply from: 'bintray-release.gradle' -ext{ +ext { PUBLISH_ARTIFACT_ID = 'public' } apply from: '../gradle/mavenCentral-release.gradle' \ No newline at end of file diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/DuaContext.kt b/PublicComponent/src/main/java/com/arialyy/aria/core/DuaContext.kt index c6a650db..38ea5dcd 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/DuaContext.kt +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/DuaContext.kt @@ -34,4 +34,5 @@ internal object DuaContext { fun isService(serviceName: String) = serviceName in serviceArray fun getServiceManager() = ServiceManager + } \ No newline at end of file diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/inf/IBaseLoader.kt b/PublicComponent/src/main/java/com/arialyy/aria/core/inf/IBaseLoader.kt new file mode 100644 index 00000000..7247a7fd --- /dev/null +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/inf/IBaseLoader.kt @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.arialyy.aria.core.inf + +import com.arialyy.annotations.TaskEnum + +/** + * @Author laoyuyu + * @Description + * @Date 14:16 AM 2023/1/20 + **/ +interface IBaseLoader { + fun getTaskEnum(): TaskEnum +} \ No newline at end of file diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/inf/IComponentLoader.kt b/PublicComponent/src/main/java/com/arialyy/aria/core/inf/IComponentLoader.kt new file mode 100644 index 00000000..43701e4a --- /dev/null +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/inf/IComponentLoader.kt @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.arialyy.aria.core.inf + +import com.arialyy.annotations.TaskEnum + +/** + * @Author laoyuyu + * @Description + * @Date 10:44 AM 2023/1/20 + **/ +interface IComponentLoader { + + companion object { + val proxyMethods = arrayOf("download", "upload") + } + + // fun upload() + + fun download(): T + + fun getTaskEnum(): TaskEnum +} \ No newline at end of file diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/inf/IDownloader.kt b/PublicComponent/src/main/java/com/arialyy/aria/core/inf/IDownloader.kt new file mode 100644 index 00000000..60a49b53 --- /dev/null +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/inf/IDownloader.kt @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.arialyy.aria.core.inf + +/** + * @Author laoyuyu + * @Description + * @Date 14:04 AM 2023/1/20 + **/ +interface IDownloader : IBaseLoader { + +} \ No newline at end of file