10
10
import android .view .KeyEvent ;
11
11
import android .view .inputmethod .EditorInfo ;
12
12
import android .view .inputmethod .InputMethodManager ;
13
- import android .widget .FrameLayout ;
14
13
import android .widget .TextView ;
15
14
16
15
import com .stripe .android .ActivitySourceCallback ;
@@ -42,7 +41,6 @@ public class AddSourceActivity extends StripeActivity {
42
41
43
42
@ Nullable private CardMultilineWidget mCardMultilineWidget ;
44
43
@ Nullable private CustomerSessionProxy mCustomerSessionProxy ;
45
- private FrameLayout mErrorLayout ;
46
44
@ Nullable private StripeProvider mStripeProvider ;
47
45
48
46
private boolean mStartedFromPaymentSession ;
@@ -90,8 +88,7 @@ protected void onCreate(Bundle savedInstanceState) {
90
88
mViewStub .inflate ();
91
89
mCardMultilineWidget = findViewById (R .id .add_source_card_entry_widget );
92
90
initEnterListeners ();
93
- mErrorLayout = findViewById (R .id .add_source_error_container );
94
- boolean showZip = getIntent ().getBooleanExtra (EXTRA_SHOW_ZIP , false );
91
+ final boolean showZip = getIntent ().getBooleanExtra (EXTRA_SHOW_ZIP , false );
95
92
mUpdatesCustomer = getIntent ().getBooleanExtra (EXTRA_UPDATE_CUSTOMER , false );
96
93
mStartedFromPaymentSession =
97
94
getIntent ().getBooleanExtra (EXTRA_PAYMENT_SESSION_ACTIVE , true );
@@ -123,7 +120,7 @@ void initCustomerSessionTokens() {
123
120
124
121
@ Override
125
122
protected void onActionSave () {
126
- final Card card = mCardMultilineWidget .getCard ();
123
+ final Card card = mCardMultilineWidget != null ? mCardMultilineWidget .getCard () : null ;
127
124
if (card == null ) {
128
125
// In this case, the error will be displayed on the card widget itself.
129
126
return ;
@@ -142,20 +139,7 @@ protected void onActionSave() {
142
139
143
140
private void attachCardToCustomer (@ NonNull final StripePaymentSource source ) {
144
141
final CustomerSession .SourceRetrievalListener listener =
145
- new CustomerSession .SourceRetrievalListener () {
146
- @ Override
147
- public void onSourceRetrieved (@ NonNull Source source ) {
148
- finishWithSource (source );
149
- }
150
-
151
- @ Override
152
- public void onError (int errorCode , @ Nullable String errorMessage ,
153
- @ Nullable StripeError stripeError ) {
154
- // No need to show this error, because it will be broadcast
155
- // from the CustomerSession
156
- setCommunicatingProgress (false );
157
- }
158
- };
142
+ new SourceRetrievalListenerImpl (this );
159
143
160
144
if (mCustomerSessionProxy == null ) {
161
145
@ Source .SourceType final String sourceType ;
@@ -277,4 +261,34 @@ public void onSuccess(@NonNull Source source) {
277
261
}
278
262
}
279
263
}
264
+
265
+ private static final class SourceRetrievalListenerImpl
266
+ extends CustomerSession .ActivitySourceRetrievalListener <AddSourceActivity > {
267
+ private SourceRetrievalListenerImpl (@ NonNull AddSourceActivity activity ) {
268
+ super (activity );
269
+ }
270
+
271
+ @ Override
272
+ public void onSourceRetrieved (@ NonNull Source source ) {
273
+ final AddSourceActivity activity = getActivity ();
274
+ if (activity == null ) {
275
+ return ;
276
+ }
277
+
278
+ activity .finishWithSource (source );
279
+ }
280
+
281
+ @ Override
282
+ public void onError (int errorCode , @ Nullable String errorMessage ,
283
+ @ Nullable StripeError stripeError ) {
284
+ final AddSourceActivity activity = getActivity ();
285
+ if (activity == null ) {
286
+ return ;
287
+ }
288
+
289
+ // No need to show this error, because it will be broadcast
290
+ // from the CustomerSession
291
+ activity .setCommunicatingProgress (false );
292
+ }
293
+ }
280
294
}
0 commit comments