-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
05a4cd0
commit 498c4d5
Showing
13 changed files
with
659 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
rxutil2/src/main/java/com/xuexiang/rxutil2/lifecycle/ActivityLifecycle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.xuexiang.rxutil2.lifecycle; | ||
|
||
/** | ||
* Activity的生命周期 | ||
* | ||
* @author xuexiang | ||
* @since 2018/6/11 上午12:45 | ||
*/ | ||
public enum ActivityLifecycle { | ||
onCreate, | ||
onStart, | ||
onResume, | ||
onPause, | ||
onStop, | ||
onDestroy, | ||
} |
48 changes: 48 additions & 0 deletions
48
rxutil2/src/main/java/com/xuexiang/rxutil2/lifecycle/ActivityRxLifecycleCallbacks.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.xuexiang.rxutil2.lifecycle; | ||
|
||
import android.app.Activity; | ||
import android.app.Application; | ||
import android.os.Bundle; | ||
|
||
/** | ||
* 应用的生命周期 | ||
* | ||
* @author xuexiang | ||
* @since 2018/6/11 上午1:09 | ||
*/ | ||
final class ActivityRxLifecycleCallbacks implements Application.ActivityLifecycleCallbacks { | ||
@Override | ||
public void onActivityCreated(Activity activity, Bundle savedInstanceState) { | ||
RxLifecycle.injectRxLifecycle(activity); | ||
} | ||
|
||
@Override | ||
public void onActivityStarted(Activity activity) { | ||
|
||
} | ||
|
||
@Override | ||
public void onActivityResumed(Activity activity) { | ||
|
||
} | ||
|
||
@Override | ||
public void onActivityPaused(Activity activity) { | ||
|
||
} | ||
|
||
@Override | ||
public void onActivityStopped(Activity activity) { | ||
|
||
} | ||
|
||
@Override | ||
public void onActivitySaveInstanceState(Activity activity, Bundle outState) { | ||
|
||
} | ||
|
||
@Override | ||
public void onActivityDestroyed(Activity activity) { | ||
|
||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
rxutil2/src/main/java/com/xuexiang/rxutil2/lifecycle/LifecycleFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package com.xuexiang.rxutil2.lifecycle; | ||
|
||
import android.app.Fragment; | ||
import android.os.Bundle; | ||
import android.support.annotation.Nullable; | ||
|
||
import io.reactivex.Observable; | ||
import io.reactivex.subjects.BehaviorSubject; | ||
|
||
|
||
/** | ||
* 用于添加到Activity中的Fragment,使得和activity的生命周期同步,从而间接绑定了activity的生命周期 | ||
* | ||
* @author xuexiang | ||
* @since 2018/6/11 上午12:58 | ||
*/ | ||
public class LifecycleFragment extends Fragment implements LifecycleManager { | ||
private final BehaviorSubject<ActivityLifecycle> mLifecycleSubject; | ||
|
||
public LifecycleFragment() { | ||
mLifecycleSubject = BehaviorSubject.create(); | ||
} | ||
|
||
@Override | ||
public void onCreate(@Nullable Bundle savedInstanceState) { | ||
mLifecycleSubject.onNext(ActivityLifecycle.onCreate); | ||
super.onCreate(savedInstanceState); | ||
} | ||
|
||
@Override | ||
public void onStart() { | ||
mLifecycleSubject.onNext(ActivityLifecycle.onStart); | ||
super.onStart(); | ||
} | ||
|
||
@Override | ||
public void onResume() { | ||
mLifecycleSubject.onNext(ActivityLifecycle.onResume); | ||
super.onResume(); | ||
} | ||
|
||
@Override | ||
public void onPause() { | ||
mLifecycleSubject.onNext(ActivityLifecycle.onPause); | ||
super.onPause(); | ||
} | ||
|
||
@Override | ||
public void onStop() { | ||
mLifecycleSubject.onNext(ActivityLifecycle.onStop); | ||
super.onStop(); | ||
} | ||
|
||
@Override | ||
public void onDestroy() { | ||
mLifecycleSubject.onNext(ActivityLifecycle.onDestroy); | ||
super.onDestroy(); | ||
} | ||
|
||
@Override | ||
public Observable<ActivityLifecycle> getActivityLifecycle() { | ||
return mLifecycleSubject; | ||
} | ||
|
||
@Override | ||
public <T> LifecycleTransformer<T> bindToActivityLifecycle(final ActivityLifecycle activityLifecycle) { | ||
return new LifecycleTransformer<>(mLifecycleSubject, activityLifecycle); | ||
} | ||
|
||
@Override | ||
public <T> LifecycleTransformer<T> bindToLifecycle() { | ||
return new LifecycleTransformer<>(mLifecycleSubject); | ||
} | ||
|
||
@Override | ||
public <T> LifecycleTransformer<T> bindOnDestroy() { | ||
return bindToActivityLifecycle(ActivityLifecycle.onDestroy); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
rxutil2/src/main/java/com/xuexiang/rxutil2/lifecycle/LifecycleManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.xuexiang.rxutil2.lifecycle; | ||
|
||
import io.reactivex.Observable; | ||
|
||
/** | ||
* 生命周期管理者,绑定生命周期 | ||
* | ||
* @author xuexiang | ||
* @since 2018/6/11 上午12:49 | ||
*/ | ||
public interface LifecycleManager { | ||
|
||
/** | ||
* 获取Activity绑定的生命周期 | ||
* @return | ||
*/ | ||
Observable<ActivityLifecycle> getActivityLifecycle(); | ||
|
||
/** | ||
* 绑定到特定的Activity生命周期进行订阅注销 | ||
* @param activityLifecycle | ||
* @param <T> | ||
* @return | ||
*/ | ||
<T> LifecycleTransformer<T> bindToActivityLifecycle(ActivityLifecycle activityLifecycle); | ||
|
||
/** | ||
* 自动绑定Activity生命周期进行订阅注销 | ||
* @param <T> | ||
* @return | ||
*/ | ||
<T> LifecycleTransformer<T> bindToLifecycle(); | ||
|
||
/** | ||
* 绑定到Activity的OnDestroy进行订阅注销 | ||
* @param <T> | ||
* @return | ||
*/ | ||
<T> LifecycleTransformer<T> bindOnDestroy(); | ||
|
||
} |
Oops, something went wrong.