@@ -127,22 +127,32 @@ public Boolean call(Boolean shouldComplete) {
127
127
new Func1 <LifecycleEvent , LifecycleEvent >() {
128
128
@ Override
129
129
public LifecycleEvent call (LifecycleEvent lastEvent ) {
130
- if (lastEvent != null ) {
131
- switch (lastEvent ) {
132
- case CREATE :
133
- return LifecycleEvent .DESTROY ;
134
- case START :
135
- return LifecycleEvent .STOP ;
136
- case RESUME :
137
- return LifecycleEvent .PAUSE ;
138
- case PAUSE :
139
- return LifecycleEvent .STOP ;
140
- case STOP :
141
- return LifecycleEvent .DESTROY ;
142
- }
130
+ if (lastEvent == null ) {
131
+ throw new NullPointerException ("Cannot bind to null LifecycleEvent." );
143
132
}
144
133
145
- throw new IllegalStateException ("Cannot bind to Activity lifecycle when outside of it." );
134
+ switch (lastEvent ) {
135
+ case CREATE :
136
+ return LifecycleEvent .DESTROY ;
137
+ case START :
138
+ return LifecycleEvent .STOP ;
139
+ case RESUME :
140
+ return LifecycleEvent .PAUSE ;
141
+ case PAUSE :
142
+ return LifecycleEvent .STOP ;
143
+ case STOP :
144
+ return LifecycleEvent .DESTROY ;
145
+ case DESTROY :
146
+ throw new IllegalStateException ("Cannot bind to Activity lifecycle when outside of it." );
147
+ case ATTACH :
148
+ case CREATE_VIEW :
149
+ case DESTROY_VIEW :
150
+ case DETACH :
151
+ throw new IllegalStateException ("Cannot bind to " + lastEvent + " for an Activity." );
152
+ default :
153
+ throw new UnsupportedOperationException ("Binding to LifecycleEvent " + lastEvent
154
+ + " not yet implemented" );
155
+ }
146
156
}
147
157
};
148
158
@@ -151,30 +161,35 @@ public LifecycleEvent call(LifecycleEvent lastEvent) {
151
161
new Func1 <LifecycleEvent , LifecycleEvent >() {
152
162
@ Override
153
163
public LifecycleEvent call (LifecycleEvent lastEvent ) {
154
- if (lastEvent != null ) {
155
- switch (lastEvent ) {
156
- case ATTACH :
157
- return LifecycleEvent .DETACH ;
158
- case CREATE :
159
- return LifecycleEvent .DESTROY ;
160
- case CREATE_VIEW :
161
- return LifecycleEvent .DESTROY_VIEW ;
162
- case START :
163
- return LifecycleEvent .STOP ;
164
- case RESUME :
165
- return LifecycleEvent .PAUSE ;
166
- case PAUSE :
167
- return LifecycleEvent .STOP ;
168
- case STOP :
169
- return LifecycleEvent .DESTROY_VIEW ;
170
- case DESTROY_VIEW :
171
- return LifecycleEvent .DESTROY ;
172
- case DESTROY :
173
- return LifecycleEvent .DETACH ;
174
- }
164
+ if (lastEvent == null ) {
165
+ throw new NullPointerException ("Cannot bind to null LifecycleEvent." );
175
166
}
176
167
177
- throw new IllegalStateException ("Cannot bind to Fragment lifecycle when outside of it." );
168
+ switch (lastEvent ) {
169
+ case ATTACH :
170
+ return LifecycleEvent .DETACH ;
171
+ case CREATE :
172
+ return LifecycleEvent .DESTROY ;
173
+ case CREATE_VIEW :
174
+ return LifecycleEvent .DESTROY_VIEW ;
175
+ case START :
176
+ return LifecycleEvent .STOP ;
177
+ case RESUME :
178
+ return LifecycleEvent .PAUSE ;
179
+ case PAUSE :
180
+ return LifecycleEvent .STOP ;
181
+ case STOP :
182
+ return LifecycleEvent .DESTROY_VIEW ;
183
+ case DESTROY_VIEW :
184
+ return LifecycleEvent .DESTROY ;
185
+ case DESTROY :
186
+ return LifecycleEvent .DETACH ;
187
+ case DETACH :
188
+ throw new IllegalStateException ("Cannot bind to Fragment lifecycle when outside of it." );
189
+ default :
190
+ throw new UnsupportedOperationException ("Binding to LifecycleEvent " + lastEvent
191
+ + " not yet implemented" );
192
+ }
178
193
}
179
194
};
180
195
}
0 commit comments