Skip to content

Commit 73e6699

Browse files
committed
Merge pull request ReactiveX#93 from dlew/dlew/reactive-ui
Added reactive versions of Activities and Fragments
2 parents 0c3bd58 + c5504c0 commit 73e6699

File tree

10 files changed

+602
-1
lines changed

10 files changed

+602
-1
lines changed

rxandroid-framework/src/main/java/rx/android/app/ReactiveDialog.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* @param <T> The type of data expected as return value from the fragment, can be boolean for confirmation dialogs,
3131
* or more complex for data input dialogs.
3232
*/
33-
public class ReactiveDialog<T> extends DialogFragment {
33+
public class ReactiveDialog<T> extends RxDialogFragment {
3434

3535
private static final String REACTIVE_DIALOG_KEY = "REACTIVE_DIALOG_KEY";
3636

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/**
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
15+
package rx.android.app;
16+
17+
import android.os.Bundle;
18+
import rx.Observable;
19+
import rx.android.lifecycle.LifecycleEvent;
20+
import rx.subjects.BehaviorSubject;
21+
22+
/**
23+
* An Activity with reactive extensions.
24+
*/
25+
public class RxActivity extends android.app.Activity {
26+
27+
private final BehaviorSubject<LifecycleEvent> lifecycleSubject = BehaviorSubject.create();
28+
29+
public Observable<LifecycleEvent> lifecycle() {
30+
return lifecycleSubject.asObservable();
31+
}
32+
33+
@Override
34+
protected void onCreate(Bundle savedInstanceState) {
35+
super.onCreate(savedInstanceState);
36+
lifecycleSubject.onNext(LifecycleEvent.CREATE);
37+
}
38+
39+
@Override
40+
protected void onStart() {
41+
super.onStart();
42+
lifecycleSubject.onNext(LifecycleEvent.START);
43+
}
44+
45+
@Override
46+
protected void onResume() {
47+
super.onResume();
48+
lifecycleSubject.onNext(LifecycleEvent.RESUME);
49+
}
50+
51+
@Override
52+
protected void onPause() {
53+
lifecycleSubject.onNext(LifecycleEvent.PAUSE);
54+
super.onPause();
55+
}
56+
57+
@Override
58+
protected void onStop() {
59+
lifecycleSubject.onNext(LifecycleEvent.STOP);
60+
super.onStop();
61+
}
62+
63+
@Override
64+
protected void onDestroy() {
65+
lifecycleSubject.onNext(LifecycleEvent.DESTROY);
66+
super.onDestroy();
67+
}
68+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/**
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
15+
package rx.android.app;
16+
17+
import android.os.Bundle;
18+
import android.view.View;
19+
import rx.Observable;
20+
import rx.android.lifecycle.LifecycleEvent;
21+
import rx.subjects.BehaviorSubject;
22+
23+
/**
24+
* A DialogFragment with reactive extensions.
25+
*/
26+
public class RxDialogFragment extends android.app.DialogFragment {
27+
28+
private final BehaviorSubject<LifecycleEvent> lifecycleSubject = BehaviorSubject.create();
29+
30+
public Observable<LifecycleEvent> lifecycle() {
31+
return lifecycleSubject.asObservable();
32+
}
33+
34+
@Override
35+
public void onAttach(android.app.Activity activity) {
36+
super.onAttach(activity);
37+
lifecycleSubject.onNext(LifecycleEvent.ATTACH);
38+
}
39+
40+
@Override
41+
public void onCreate(Bundle savedInstanceState) {
42+
super.onCreate(savedInstanceState);
43+
lifecycleSubject.onNext(LifecycleEvent.CREATE);
44+
}
45+
46+
@Override
47+
public void onViewCreated(View view, Bundle savedInstanceState) {
48+
super.onViewCreated(view, savedInstanceState);
49+
lifecycleSubject.onNext(LifecycleEvent.CREATE_VIEW);
50+
}
51+
52+
@Override
53+
public void onStart() {
54+
super.onStart();
55+
lifecycleSubject.onNext(LifecycleEvent.START);
56+
}
57+
58+
@Override
59+
public void onResume() {
60+
super.onResume();
61+
lifecycleSubject.onNext(LifecycleEvent.RESUME);
62+
}
63+
64+
@Override
65+
public void onPause() {
66+
lifecycleSubject.onNext(LifecycleEvent.PAUSE);
67+
super.onPause();
68+
}
69+
70+
@Override
71+
public void onStop() {
72+
lifecycleSubject.onNext(LifecycleEvent.STOP);
73+
super.onStop();
74+
}
75+
76+
@Override
77+
public void onDestroyView() {
78+
lifecycleSubject.onNext(LifecycleEvent.DESTROY_VIEW);
79+
super.onDestroyView();
80+
}
81+
82+
@Override
83+
public void onDestroy() {
84+
lifecycleSubject.onNext(LifecycleEvent.DESTROY);
85+
super.onDestroy();
86+
}
87+
88+
@Override
89+
public void onDetach() {
90+
lifecycleSubject.onNext(LifecycleEvent.DETACH);
91+
super.onDetach();
92+
}
93+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/**
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
15+
package rx.android.app;
16+
17+
import android.os.Bundle;
18+
import android.view.View;
19+
import rx.Observable;
20+
import rx.android.lifecycle.LifecycleEvent;
21+
import rx.subjects.BehaviorSubject;
22+
23+
/**
24+
* A Fragment with reactive extensions.
25+
*/
26+
public class RxFragment extends android.app.Fragment {
27+
28+
private final BehaviorSubject<LifecycleEvent> lifecycleSubject = BehaviorSubject.create();
29+
30+
public Observable<LifecycleEvent> lifecycle() {
31+
return lifecycleSubject.asObservable();
32+
}
33+
34+
@Override
35+
public void onAttach(android.app.Activity activity) {
36+
super.onAttach(activity);
37+
lifecycleSubject.onNext(LifecycleEvent.ATTACH);
38+
}
39+
40+
@Override
41+
public void onCreate(Bundle savedInstanceState) {
42+
super.onCreate(savedInstanceState);
43+
lifecycleSubject.onNext(LifecycleEvent.CREATE);
44+
}
45+
46+
@Override
47+
public void onViewCreated(View view, Bundle savedInstanceState) {
48+
super.onViewCreated(view, savedInstanceState);
49+
lifecycleSubject.onNext(LifecycleEvent.CREATE_VIEW);
50+
}
51+
52+
@Override
53+
public void onStart() {
54+
super.onStart();
55+
lifecycleSubject.onNext(LifecycleEvent.START);
56+
}
57+
58+
@Override
59+
public void onResume() {
60+
super.onResume();
61+
lifecycleSubject.onNext(LifecycleEvent.RESUME);
62+
}
63+
64+
@Override
65+
public void onPause() {
66+
lifecycleSubject.onNext(LifecycleEvent.PAUSE);
67+
super.onPause();
68+
}
69+
70+
@Override
71+
public void onStop() {
72+
lifecycleSubject.onNext(LifecycleEvent.STOP);
73+
super.onStop();
74+
}
75+
76+
@Override
77+
public void onDestroyView() {
78+
lifecycleSubject.onNext(LifecycleEvent.DESTROY_VIEW);
79+
super.onDestroyView();
80+
}
81+
82+
@Override
83+
public void onDestroy() {
84+
lifecycleSubject.onNext(LifecycleEvent.DESTROY);
85+
super.onDestroy();
86+
}
87+
88+
@Override
89+
public void onDetach() {
90+
lifecycleSubject.onNext(LifecycleEvent.DETACH);
91+
super.onDetach();
92+
}
93+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/**
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
15+
package rx.android.app.support;
16+
17+
import android.os.Bundle;
18+
import android.view.View;
19+
import rx.Observable;
20+
import rx.android.lifecycle.LifecycleEvent;
21+
import rx.subjects.BehaviorSubject;
22+
23+
/**
24+
* A DialogFragment with reactive extensions.
25+
*/
26+
public class RxDialogFragment extends android.support.v4.app.DialogFragment {
27+
28+
private final BehaviorSubject<LifecycleEvent> lifecycleSubject = BehaviorSubject.create();
29+
30+
public Observable<LifecycleEvent> lifecycle() {
31+
return lifecycleSubject.asObservable();
32+
}
33+
34+
@Override
35+
public void onAttach(android.app.Activity activity) {
36+
super.onAttach(activity);
37+
lifecycleSubject.onNext(LifecycleEvent.ATTACH);
38+
}
39+
40+
@Override
41+
public void onCreate(Bundle savedInstanceState) {
42+
super.onCreate(savedInstanceState);
43+
lifecycleSubject.onNext(LifecycleEvent.CREATE);
44+
}
45+
46+
@Override
47+
public void onViewCreated(View view, Bundle savedInstanceState) {
48+
super.onViewCreated(view, savedInstanceState);
49+
lifecycleSubject.onNext(LifecycleEvent.CREATE_VIEW);
50+
}
51+
52+
@Override
53+
public void onStart() {
54+
super.onStart();
55+
lifecycleSubject.onNext(LifecycleEvent.START);
56+
}
57+
58+
@Override
59+
public void onResume() {
60+
super.onResume();
61+
lifecycleSubject.onNext(LifecycleEvent.RESUME);
62+
}
63+
64+
@Override
65+
public void onPause() {
66+
lifecycleSubject.onNext(LifecycleEvent.PAUSE);
67+
super.onPause();
68+
}
69+
70+
@Override
71+
public void onStop() {
72+
lifecycleSubject.onNext(LifecycleEvent.STOP);
73+
super.onStop();
74+
}
75+
76+
@Override
77+
public void onDestroyView() {
78+
lifecycleSubject.onNext(LifecycleEvent.DESTROY_VIEW);
79+
super.onDestroyView();
80+
}
81+
82+
@Override
83+
public void onDestroy() {
84+
lifecycleSubject.onNext(LifecycleEvent.DESTROY);
85+
super.onDestroy();
86+
}
87+
88+
@Override
89+
public void onDetach() {
90+
lifecycleSubject.onNext(LifecycleEvent.DETACH);
91+
super.onDetach();
92+
}
93+
}

0 commit comments

Comments
 (0)