Skip to content

Commit

Permalink
修改RxAppLifecycle
Browse files Browse the repository at this point in the history
  • Loading branch information
K0170016 authored and K0170016 committed Jun 6, 2019
1 parent 0d99a70 commit 12458c5
Show file tree
Hide file tree
Showing 43 changed files with 199 additions and 448 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

/**
* 标注Application生命周期观察者
* <p>
* Created by liujunfeng on 2019/1/1.
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.CLASS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

/**
* 标注Application本身,生命周期持有者,被观察者
* <p>
* Created by liujunfeng on 2019/1/1.
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.CLASS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

/**
* 标注{@link RxAppObserver}索引类
* <p>
* Created by liujunfeng on 2019/1/1.
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.CLASS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

/**
* Utilities for writing classes and logging.
* <p>
* Created by liujunfeng on 2019/1/1.
*/
final class ProcessorUtil {
/**
Expand Down Expand Up @@ -70,9 +72,6 @@ void process() {

/**
* 判断该类是否是RxApp的子类
*
* @param element
* @return
*/
boolean isRxApp(TypeElement element) {
return mProcessingEnv.getTypeUtils().isAssignable(element.asType(),
Expand All @@ -81,9 +80,6 @@ boolean isRxApp(TypeElement element) {

/**
* 判断该类是否是RxAppLifecycle的实现类
*
* @param element
* @return
*/
boolean isRxAppLifecycle(TypeElement element) {
return mProcessingEnv.getTypeUtils().isAssignable(element.asType(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

/**
* 生成com.huyingbao.core.arch.RxAppLifecycleOwner类
* <p>
* Created by liujunfeng on 2019/1/1.
*/
final class RxAppLifecycleOwnerGenerator {
private static final String PACKAGE_LIFECYCLE = "androidx.lifecycle";
Expand All @@ -40,9 +42,6 @@ final class RxAppLifecycleOwnerGenerator {

/**
* 生成类
*
* @param rxAppLifecycleClassNames
* @return
*/
TypeSpec generate(Set<String> rxAppLifecycleClassNames) {
List<String> orderedRxAppLifecycleClassNames = new ArrayList<>(rxAppLifecycleClassNames);
Expand All @@ -65,8 +64,6 @@ TypeSpec generate(Set<String> rxAppLifecycleClassNames) {

/**
* 生成类注解
*
* @return
*/
private AnnotationSpec generateAnnotation() {
return AnnotationSpec.builder(SuppressWarnings.class)
Expand All @@ -76,9 +73,6 @@ private AnnotationSpec generateAnnotation() {

/**
* 生成构造方法
*
* @param rxAppLifecycleClassNames
* @return
*/
private MethodSpec generateConstructor(Collection<String> rxAppLifecycleClassNames) {
//方法入参
Expand All @@ -101,8 +95,6 @@ private MethodSpec generateConstructor(Collection<String> rxAppLifecycleClassNam

/**
* 生成成员变量
*
* @return
*/
private FieldSpec generateField() {
//获取类名
Expand All @@ -115,8 +107,6 @@ private FieldSpec generateField() {

/**
* 生成getLifecycle()方法
*
* @return
*/
private MethodSpec generateGetLifecycle() {
MethodSpec.Builder builder = MethodSpec.methodBuilder("getLifecycle")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
import javax.lang.model.element.PackageElement;
import javax.lang.model.element.TypeElement;

/**
* Created by liujunfeng on 2019/1/1.
*/
public class RxArchProcessor extends AbstractProcessor {
private static final String COMPILER_PACKAGE_NAME = RxArchProcessor.class.getPackage().getName();
static final boolean DEBUG = false;
Expand All @@ -33,8 +36,6 @@ public class RxArchProcessor extends AbstractProcessor {
* 比如文件相关的辅助类 Filer;
* 元素相关的辅助类Elements;
* 日志相关的辅助类Messager;
*
* @param processingEnvironment
*/
@Override
public synchronized void init(ProcessingEnvironment processingEnvironment) {
Expand Down Expand Up @@ -65,10 +66,6 @@ public SourceVersion getSupportedSourceVersion() {

/**
* 生成Java文件
*
* @param set
* @param roundEnvironment
* @return
*/
@Override
public boolean process(Set<? extends TypeElement> set, RoundEnvironment roundEnvironment) {
Expand All @@ -89,9 +86,6 @@ public boolean process(Set<? extends TypeElement> set, RoundEnvironment roundEnv

/**
* 检索{@link RxAppObserver},生成Application生命周期观察者索引文件
*
* @param roundEnvironment
* @return
*/
private boolean processIndex(RoundEnvironment roundEnvironment) {
List<TypeElement> elements = mProcessorUtil.getElementsFor(RxAppObserver.class, roundEnvironment);
Expand All @@ -106,8 +100,6 @@ private boolean processIndex(RoundEnvironment roundEnvironment) {

/**
* 检查使用{@link RxAppOwner}注解的类中是否有RxApp子类,如果有则取出,且RxApp子类只能有一个。
*
* @param env
*/
private void processRxAppOwner(RoundEnvironment env) {
for (TypeElement element : mProcessorUtil.getElementsFor(RxAppOwner.class, env)) {
Expand All @@ -123,8 +115,6 @@ private void processRxAppOwner(RoundEnvironment env) {

/**
* 生成RxAppLifecycleOwner类
*
* @return
*/
private boolean processRxAppLifecycleOwner() {
if (mRxAppList.isEmpty()) {
Expand All @@ -142,11 +132,7 @@ private boolean processRxAppLifecycleOwner() {
}

/**
* 从当前包附加的类中获取到所有编译生成的Index类
* 再从Index类的{@link RxIndex}注解中取出modules中存储的自定义RxAppLifecycle类名
*
* @param packageElement
* @return
* 从当前包附加的类中获取到所有编译生成的Index类,再从Index类的{@link RxIndex}注解中取出modules中存储的自定义RxAppLifecycle类名
*/
@SuppressWarnings("unchecked")
private Set<String> getIndexedClassNames(PackageElement packageElement) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

/**
* 生成索引文件
* <p>
* Created by liujunfeng on 2019/1/1.
*/
final class RxIndexerGenerator {
private static final String INDEXER_NAME_PREFIX = "RxIndexer_";
Expand Down
12 changes: 4 additions & 8 deletions core-arch/src/main/java/com/huyingbao/core/arch/RxApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,9 @@
import static com.huyingbao.core.arch.RxFlux.TAG;

/**
* Application实现相应的接口
* HasActivityInjector、
* HasFragmentInjector、
* HasSupportFragmentInjector、
* HasServiceInjector、
* HasBroadcastReceiverInjector
* Application实现Dagger.Android依赖注入。
* <p>
* 通过反射获取RxAppLifecycleOwner,并实现生命周期状态分发到{@link RxAppLifecycle}。
* <p>
* Created by liujunfeng on 2019/1/1.
*/
Expand All @@ -46,8 +43,7 @@ protected void attachBaseContext(Context base) {
@Override
public void onCreate() {
super.onCreate();
//application创建的时候调用该方法,
//使RxFlux可以接受Activity生命周期回调
//application创建的时候调用该方法,使RxFlux可以接受Activity生命周期回调
registerActivityLifecycleCallbacks(mRxFlux);
if (mLifecycleRegistry != null) {
mLifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_CREATE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import androidx.lifecycle.OnLifecycleEvent;

/**
* 跟随App生命周期
* 跟随Application生命周期
* <p>
* Created by liujunfeng on 2019/1/1.
*/
Expand Down
25 changes: 5 additions & 20 deletions core-arch/src/main/java/com/huyingbao/core/arch/RxFlux.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,7 @@
import javax.inject.Singleton;

/**
* 主类
* 必须在application创建的时候调用该类的实例方法, 并仅调用一次.
* 这个类会自动跟踪应用程序的生命周期,
* 并且注销每个activity剩余的订阅subscriptions
* <p>
* 抽象的类并不能实例化
* 自动跟踪Activity/Fragment的生命周期,管理Activity/Fragment订阅,必须在Application创建的时候调用该类的实例方法, 并仅调用一次。
* <p>
* Created by liujunfeng on 2019/1/1.
*/
Expand Down Expand Up @@ -118,9 +113,7 @@ public void onFragmentStarted(FragmentManager fm, Fragment f) {


/**
* RxFluxView能响应时,注册订阅
*
* @param activity
* {@link RxSubscriberView}注册订阅
*/
@Override
public void onActivityResumed(Activity activity) {
Expand All @@ -134,10 +127,7 @@ public void onActivityResumed(Activity activity) {
}

/**
* RxFluxView能响应时,注册订阅
*
* @param fm
* @param f
* {@link RxSubscriberView}注册订阅
*/
@Override
public void onFragmentResumed(@NonNull FragmentManager fm, @NonNull Fragment f) {
Expand All @@ -153,9 +143,7 @@ public void onFragmentResumed(@NonNull FragmentManager fm, @NonNull Fragment f)


/**
* RxFluxView不能响应时,取消订阅
*
* @param activity
* {@link RxSubscriberView}取消订阅
*/
@Override
public void onActivityPaused(Activity activity) {
Expand All @@ -166,10 +154,7 @@ public void onActivityPaused(Activity activity) {
}

/**
* RxFluxView不能响应时,取消订阅
*
* @param fm
* @param f
* {@link RxSubscriberView}取消订阅
*/
@Override
public void onFragmentPaused(@NonNull FragmentManager fm, @NonNull Fragment f) {
Expand Down
Loading

0 comments on commit 12458c5

Please sign in to comment.