|
20 | 20 | import android.app.AlertDialog; |
21 | 21 | import android.app.PendingIntent; |
22 | 22 | import android.content.Intent; |
23 | | -import android.content.IntentSender; |
24 | 23 | import android.content.IntentSender.SendIntentException; |
25 | 24 | import android.os.Bundle; |
26 | 25 | import android.text.Html; |
|
39 | 38 | import com.google.android.gms.samples.wallet.util.Json; |
40 | 39 | import com.google.android.gms.samples.wallet.util.PaymentsUtil; |
41 | 40 | import com.google.android.gms.tasks.OnCompleteListener; |
42 | | -import com.google.android.gms.tasks.OnFailureListener; |
43 | | -import com.google.android.gms.tasks.OnSuccessListener; |
44 | 41 | import com.google.android.gms.tasks.Task; |
45 | 42 | import com.google.android.gms.wallet.AutoResolveHelper; |
46 | 43 | import com.google.android.gms.wallet.CreditCardExpirationDate; |
47 | 44 | import com.google.android.gms.wallet.IsReadyToPayRequest; |
48 | 45 | import com.google.android.gms.wallet.PaymentCardRecognitionIntentRequest; |
49 | | -import com.google.android.gms.wallet.PaymentCardRecognitionIntentResponse; |
50 | 46 | import com.google.android.gms.wallet.PaymentCardRecognitionResult; |
51 | 47 | import com.google.android.gms.wallet.PaymentData; |
52 | 48 | import com.google.android.gms.wallet.PaymentDataRequest; |
@@ -170,21 +166,10 @@ private void initializeUi() { |
170 | 166 |
|
171 | 167 | // The Google Pay button is a layout file – take the root view |
172 | 168 | googlePayButton = layoutBinding.googlePayButton.getRoot(); |
173 | | - googlePayButton.setOnClickListener( |
174 | | - new View.OnClickListener() { |
175 | | - @Override |
176 | | - public void onClick(View view) { |
177 | | - requestPayment(view); |
178 | | - } |
179 | | - }); |
| 169 | + googlePayButton.setOnClickListener(this::requestPayment); |
180 | 170 |
|
181 | 171 | paymentCardOcrButton = layoutBinding.paymentCardOcrButton; |
182 | | - paymentCardOcrButton.setOnClickListener(new View.OnClickListener() { |
183 | | - @Override |
184 | | - public void onClick(View view) { |
185 | | - startPaymentCardOcr(view); |
186 | | - } |
187 | | - }); |
| 172 | + paymentCardOcrButton.setOnClickListener(this::startPaymentCardOcr); |
188 | 173 | } |
189 | 174 |
|
190 | 175 | private void displayGarment(JSONObject garment) throws JSONException { |
@@ -220,16 +205,13 @@ private void possiblyShowGooglePayButton() { |
220 | 205 | // The call to isReadyToPay is asynchronous and returns a Task. We need to provide an |
221 | 206 | // OnCompleteListener to be triggered when the result of the call is known. |
222 | 207 | IsReadyToPayRequest request = IsReadyToPayRequest.fromJson(isReadyToPayJson.get().toString()); |
223 | | - Task<Boolean> task = paymentsClient.isReadyToPay(request); |
224 | | - task.addOnCompleteListener(this, |
225 | | - new OnCompleteListener<Boolean>() { |
226 | | - @Override |
227 | | - public void onComplete(@NonNull Task<Boolean> task) { |
228 | | - if (task.isSuccessful()) { |
229 | | - setGooglePayAvailable(task.getResult()); |
230 | | - } else { |
231 | | - Log.w("isReadyToPay failed", task.getException()); |
232 | | - } |
| 208 | + Task<Boolean> requestTask = paymentsClient.isReadyToPay(request); |
| 209 | + requestTask.addOnCompleteListener(this, |
| 210 | + task -> { |
| 211 | + if (task.isSuccessful()) { |
| 212 | + setGooglePayAvailable(task.getResult()); |
| 213 | + } else { |
| 214 | + Log.w("isReadyToPay failed", task.getException()); |
233 | 215 | } |
234 | 216 | }); |
235 | 217 | } |
@@ -307,7 +289,7 @@ private void handleCardRecognitionSuccess(PaymentCardRecognitionResult cardResul |
307 | 289 | CreditCardExpirationDate cardExpirationDate = cardResult.getCreditCardExpirationDate(); |
308 | 290 | if(cardExpirationDate != null) { |
309 | 291 | expirationDate = String.format(locale, |
310 | | - "%02d/%02d", cardExpirationDate.getMonth(), cardExpirationDate.getYear()); |
| 292 | + "%02d/%d", cardExpirationDate.getMonth(), cardExpirationDate.getYear()); |
311 | 293 | } |
312 | 294 |
|
313 | 295 | String cardResultString = String.format(locale, |
|
0 commit comments