@@ -368,46 +368,12 @@ public Void then(@NonNull Task<GoogleApiClient> task) throws Exception {
368
368
*/
369
369
@ Deprecated
370
370
public Task <Void > delete (@ NonNull Activity activity ) {
371
- FirebaseUser firebaseUser = FirebaseAuth .getInstance ().getCurrentUser ();
372
- if (firebaseUser == null ) {
373
- // If the current user is null, return a failed task immediately
374
- return Tasks .forException (new Exception ("No currently signed in user." ));
375
- }
376
-
377
- // Delete the Firebase user
378
- Task <Void > deleteUserTask = firebaseUser .delete ();
379
-
380
371
// Initialize SmartLock helper
381
372
GoogleApiClientTaskHelper gacHelper = GoogleApiClientTaskHelper .getInstance (activity );
382
373
gacHelper .getBuilder ().addApi (Auth .CREDENTIALS_API );
383
374
CredentialApiHelper credentialHelper = CredentialsApiHelper .getInstance (gacHelper );
384
375
385
- // Get all SmartLock credentials associated with the user
386
- List <Credential > credentials = SmartLockBase .credentialsFromFirebaseUser (firebaseUser );
387
-
388
- // For each Credential in the list, create a task to delete it.
389
- List <Task <?>> credentialTasks = new ArrayList <>();
390
- for (Credential credential : credentials ) {
391
- credentialTasks .add (credentialHelper .delete (credential ));
392
- }
393
-
394
- // Create a combined task that will succeed when all credential delete operations
395
- // have completed (even if they fail).
396
- final Task <Void > combinedCredentialTask = Tasks .whenAll (credentialTasks );
397
-
398
- // Chain the Firebase Auth delete task with the combined Credentials task
399
- // and return.
400
- return deleteUserTask .continueWithTask (new Continuation <Void , Task <Void >>() {
401
- @ Override
402
- public Task <Void > then (@ NonNull Task <Void > task ) throws Exception {
403
- // Call getResult() to propagate failure by throwing an exception
404
- // if there was one.
405
- task .getResult (Exception .class );
406
-
407
- // Return the combined credential task
408
- return combinedCredentialTask ;
409
- }
410
- });
376
+ return getDeleteTask (credentialHelper );
411
377
}
412
378
413
379
/**
@@ -447,6 +413,13 @@ public Task<Void> signOut(@NonNull FragmentActivity activity) {
447
413
* @param activity the calling {@link Activity}.
448
414
*/
449
415
public Task <Void > delete (@ NonNull FragmentActivity activity ) {
416
+ // Initialize SmartLock helper
417
+ CredentialApiHelper credentialHelper = GoogleSignInHelper .getInstance (activity );
418
+
419
+ return getDeleteTask (credentialHelper );
420
+ }
421
+
422
+ private Task <Void > getDeleteTask (CredentialApiHelper credentialHelper ) {
450
423
FirebaseUser firebaseUser = FirebaseAuth .getInstance ().getCurrentUser ();
451
424
if (firebaseUser == null ) {
452
425
// If the current user is null, return a failed task immediately
@@ -456,9 +429,6 @@ public Task<Void> delete(@NonNull FragmentActivity activity) {
456
429
// Delete the Firebase user
457
430
Task <Void > deleteUserTask = firebaseUser .delete ();
458
431
459
- // Initialize SmartLock helper
460
- GoogleSignInHelper credentialHelper = GoogleSignInHelper .getInstance (activity );
461
-
462
432
// Get all SmartLock credentials associated with the user
463
433
List <Credential > credentials = SmartLockBase .credentialsFromFirebaseUser (firebaseUser );
464
434
0 commit comments