From 26aa55285d6fed56c19d12362f3580f8d974f89a Mon Sep 17 00:00:00 2001 From: tianxiangyu <96164429+FlyJingFish@users.noreply.github.com> Date: Fri, 10 May 2024 18:48:54 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E5=8D=87=E7=BA=A7=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 59 ++++++++++++++++++++++++++++++++++++++++------ README_EN.md | 57 +++++++++++++++++++++++++++++++++++++++----- gradle.properties | 2 +- version.properties | 4 ++-- 4 files changed, 106 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index bfe2eba0..f5d085b2 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ plugins { //必须项 👇 apply 设置为 true 自动为所有module“预”配置debugMode,false则按下边步骤五的方式二 - id "io.github.FlyJingFish.AndroidAop.android-aop" version "1.7.3" apply true + id "io.github.FlyJingFish.AndroidAop.android-aop" version "1.7.4" apply true } ``` @@ -80,7 +80,7 @@ plugins { buildscript { dependencies { //必须项 👇 - classpath 'io.github.FlyJingFish.AndroidAop:android-aop-plugin:1.7.3' + classpath 'io.github.FlyJingFish.AndroidAop:android-aop-plugin:1.7.4' } } // 👇加上这句自动为所有module“预”配置debugMode,不加则按下边步骤五的方式二 @@ -115,7 +115,7 @@ apply plugin: 'android.aop' //最好放在最后一行 //必须项 👇 plugins { ... - id "io.github.FlyJingFish.AndroidAop.android-aop" version "1.7.3" + id "io.github.FlyJingFish.AndroidAop.android-aop" version "1.7.4" } ``` @@ -141,17 +141,17 @@ plugins { dependencies { //必须项 👇 - implementation 'io.github.FlyJingFish.AndroidAop:android-aop-core:1.7.3' - implementation 'io.github.FlyJingFish.AndroidAop:android-aop-annotation:1.7.3' + implementation 'io.github.FlyJingFish.AndroidAop:android-aop-core:1.7.4' + implementation 'io.github.FlyJingFish.AndroidAop:android-aop-annotation:1.7.4' //必须项 👇如果您项目内已经有了这项不用加也可以 implementation 'androidx.appcompat:appcompat:1.3.0' // 至少在1.3.0及以上 //非必须项 👇,如果你想自定义切面需要用到,⚠️支持Java和Kotlin代码写的切面 - ksp 'io.github.FlyJingFish.AndroidAop:android-aop-ksp:1.7.3' + ksp 'io.github.FlyJingFish.AndroidAop:android-aop-ksp:1.7.4' //非必须项 👇,如果你想自定义切面需要用到,⚠️只适用于Java代码写的切面 - annotationProcessor 'io.github.FlyJingFish.AndroidAop:android-aop-processor:1.7.3' + annotationProcessor 'io.github.FlyJingFish.AndroidAop:android-aop-processor:1.7.4' //⚠️上边的 android-aop-ksp 和 android-aop-processor 二选一 } ``` @@ -378,6 +378,7 @@ AndroidAop.INSTANCE.setOnToastListener(new OnToastListener() { - @AndroidAopMatchClassMethod 是匹配类的方法的切面 - @AndroidAopReplaceClass 是替换方法调用的 - @AndroidAopModifyExtendsClass 是修改继承类 +- @AndroidAopCollectMethod 是收集直接的继承类 #### 一、**@AndroidAopPointCut** 是在方法上通过注解的形式做切面的,上述中注解都是通过这个做的,[详细使用请看wiki文档](https://github.com/FlyJingFish/AndroidAOP/wiki/@AndroidAopPointCut) @@ -594,6 +595,50 @@ public class ReplaceImageView extends ImageView { } ``` +#### 五、**@AndroidAopCollectMethod** 是收集直接的继承类[详细使用方式](https://github.com/FlyJingFish/AndroidAOP/wiki/@AndroidAopCollectMethod) + +使用起来极其简单,示例代码已经说明了 + +- Kotlin + +```kotlin +object InitCollect { + private val collects = mutableListOf() + + @AndroidAopCollectMethod + @JvmStatic + fun collect(sub: SubApplication){ + collects.add(sub) + } + + //直接调这个方法 collects 集合就是有数据的 + fun init(application: Application){ + for (collect in collects) { + collect.onCreate(application) + } + } +} +``` + +- Java + +```java +public class InitCollect2 { + private static List collects = new ArrayList<>(); + @AndroidAopCollectMethod + public static void collect(SubApplication2 sub){ + collects.add(sub); + } + + //直接调这个方法 collects 集合就是有数据的 + public static void init(Application application){ + Log.e("InitCollect2","----init----"); + for (SubApplication2 collect : collects) { + collect.onCreate(application); + } + } +} +``` ### 常见问题 diff --git a/README_EN.md b/README_EN.md index e098da8e..cbcc2acc 100644 --- a/README_EN.md +++ b/README_EN.md @@ -76,7 +76,7 @@ plugins { buildscript { dependencies { //Required items 👇 - classpath 'io.github.FlyJingFish.AndroidAop:android-aop-plugin:1.7.3' + classpath 'io.github.FlyJingFish.AndroidAop:android-aop-plugin:1.7.4' } } //👇Add this sentence to automatically apply debugMode to all modules. If not, follow step 5 below. @@ -114,7 +114,7 @@ Add directly to ```build.gradle``` of **app** //Required items 👇 plugins { ... - id "io.github.FlyJingFish.AndroidAop.android-aop" version "1.7.3" + id "io.github.FlyJingFish.AndroidAop.android-aop" version "1.7.4" } ``` @@ -144,16 +144,16 @@ plugins { dependencies { //Required items 👇 - implementation 'io.github.FlyJingFish.AndroidAop:android-aop-core:1.7.3' - implementation 'io.github.FlyJingFish.AndroidAop:android-aop-annotation:1.7.3' + implementation 'io.github.FlyJingFish.AndroidAop:android-aop-core:1.7.4' + implementation 'io.github.FlyJingFish.AndroidAop:android-aop-annotation:1.7.4' //Required item 👇If you already have this item in your project, you don’t need to add it. implementation 'androidx.appcompat:appcompat:1.3.0' // At least in 1.3.0 and above //Optional 👇, if you want to customize aspects, you need to use them, ⚠️supports aspects written in Java and Kotlin code - ksp 'io.github.FlyJingFish.AndroidAop:android-aop-ksp:1.7.3' + ksp 'io.github.FlyJingFish.AndroidAop:android-aop-ksp:1.7.4' //Optional 👇, if you want to customize aspects, you need to use them, ⚠️only applies to aspects written in Java code - annotationProcessor 'io.github.FlyJingFish.AndroidAop:android-aop-processor:1.7.3' + annotationProcessor 'io.github.FlyJingFish.AndroidAop:android-aop-processor:1.7.4' //⚠️Choose one of the above android-aop-ksp and android-aop-processor } ``` @@ -358,6 +358,7 @@ AndroidAop.INSTANCE.setOnToastListener(new OnToastListener() { - @AndroidAopMatchClassMethod is the aspect of matching class methods - @AndroidAopReplaceClass is called by the replacement method - @AndroidAopModifyExtendsClass is a modified inherited class +- @AndroidAopCollectMethod is the direct inheritance class of collection #### 1. **@AndroidAopPointCut** is used to make aspects in the form of annotations on the method. The above annotations are all made through this. [Please see the wiki document for detailed usage](https://github.com/FlyJingFish/AndroidAOP/wiki/@AndroidAopPointCut) @@ -554,6 +555,50 @@ public class ReplaceImageView extends ImageView { } ``` +#### 5. **@AndroidAopCollectMethod** is a direct inheritance class of collection [detailed usage] (https://github.com/FlyJingFish/AndroidAOP/wiki/@AndroidAopCollectMethod) + +It is extremely simple to use, the sample code has already explained + +- Kotlin + +```kotlin +objectInitCollect { + private val collects = mutableListOf() + + @AndroidAopCollectMethod + @JvmStatic + fun collect(sub: SubApplication){ + collects.add(sub) + } + + // Call this method directly. The collects collection contains data. + fun init(application: Application){ + for (collect in collects) { + collect.onCreate(application) + } + } +} +``` + +-Java + +```java +public class InitCollect2 { + private static List collects = new ArrayList<>(); + @AndroidAopCollectMethod + public static void collect(SubApplication2 sub){ + collects.add(sub); + } + + // Call this method directly. The collects collection contains data. + public static void init(Application application){ + Log.e("InitCollect2","----init----"); + for (SubApplication2 collect : collects) { + collect.onCreate(application); + } + } +} +``` ### common problem diff --git a/gradle.properties b/gradle.properties index 6b51ec17..0de48053 100644 --- a/gradle.properties +++ b/gradle.properties @@ -41,7 +41,7 @@ DEVELOPER_ID=FlyJingFish DEVELOPER_NAME=FlyJingFish DEVELOPER_EMAIL=749617782@qq.com -TestVersion = 1.7.3 +TestVersion = 1.7.4 SonatypeTestCode = 1395 TestType = 0 androidAop.debugMode = true diff --git a/version.properties b/version.properties index a4091036..2e6c56d5 100644 --- a/version.properties +++ b/version.properties @@ -1,2 +1,2 @@ -#Thu May 09 11:47:14 CST 2024 -PROJ_VERSION=1.7.3 +#Fri May 10 18:38:56 CST 2024 +PROJ_VERSION=1.7.4