Skip to content

Commit cd26654

Browse files
authored
Offline Auth method picker (#1586)
1 parent 2ca60dd commit cd26654

File tree

5 files changed

+23
-21
lines changed

5 files changed

+23
-21
lines changed

auth/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ android {
1313
disable("UnusedQuantity")
1414
disable("UnknownNullness") // TODO fix in future PR
1515
disable("TypographyQuotes") // Straight versus directional quotes
16+
disable("MissingTranslation") // STOPSHIP: Get translations
1617
}
1718

1819
testOptions {

auth/src/main/java/com/firebase/ui/auth/KickoffActivity.java

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import android.arch.lifecycle.ViewModelProviders;
44
import android.content.Context;
55
import android.content.Intent;
6-
import android.net.ConnectivityManager;
76
import android.os.Bundle;
87
import android.support.annotation.NonNull;
98
import android.support.annotation.Nullable;
@@ -62,12 +61,7 @@ public void onSuccess(Void aVoid) {
6261
return;
6362
}
6463

65-
if (isOffline()) {
66-
finish(RESULT_CANCELED, IdpResponse.getErrorIntent(
67-
new FirebaseUiException(ErrorCodes.NO_NETWORK)));
68-
} else {
69-
mKickstarter.start();
70-
}
64+
mKickstarter.start();
7165
}
7266
})
7367
.addOnFailureListener(this, new OnFailureListener() {
@@ -98,18 +92,4 @@ public void invalidateEmailLink() {
9892
setIntent(getIntent().putExtra(ExtraConstants.FLOW_PARAMS,
9993
flowParameters));
10094
}
101-
102-
/**
103-
* Check if there is an active or soon-to-be-active network connection.
104-
*
105-
* @return true if there is no network connection, false otherwise.
106-
*/
107-
private boolean isOffline() {
108-
ConnectivityManager manager = (ConnectivityManager) getApplicationContext()
109-
.getSystemService(Context.CONNECTIVITY_SERVICE);
110-
111-
return !(manager != null
112-
&& manager.getActiveNetworkInfo() != null
113-
&& manager.getActiveNetworkInfo().isConnectedOrConnecting());
114-
}
11595
}

auth/src/main/java/com/firebase/ui/auth/ui/HelperActivityBase.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.app.Activity;
44
import android.content.Context;
55
import android.content.Intent;
6+
import android.net.ConnectivityManager;
67
import android.support.annotation.NonNull;
78
import android.support.annotation.Nullable;
89
import android.support.annotation.RestrictTo;
@@ -75,4 +76,18 @@ public void startSaveCredentials(
7576
this, getFlowParams(), credential, response);
7677
startActivityForResult(intent, RequestCodes.CRED_SAVE_FLOW);
7778
}
79+
80+
/**
81+
* Check if there is an active or soon-to-be-active network connection.
82+
*
83+
* @return true if there is no network connection, false otherwise.
84+
*/
85+
protected boolean isOffline() {
86+
ConnectivityManager manager = (ConnectivityManager) getApplicationContext()
87+
.getSystemService(Context.CONNECTIVITY_SERVICE);
88+
89+
return !(manager != null
90+
&& manager.getActiveNetworkInfo() != null
91+
&& manager.getActiveNetworkInfo().isConnectedOrConnecting());
92+
}
7893
}

auth/src/main/java/com/firebase/ui/auth/ui/idp/AuthMethodPickerActivity.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,11 @@ private void handleResponse(@NonNull IdpResponse response) {
307307
view.setOnClickListener(new View.OnClickListener() {
308308
@Override
309309
public void onClick(View view) {
310+
if (isOffline()) {
311+
Toast.makeText(AuthMethodPickerActivity.this, getString(R.string.fui_no_internet), Toast.LENGTH_SHORT).show();
312+
return;
313+
}
314+
310315
provider.startSignIn(AuthMethodPickerActivity.this);
311316
}
312317
});

auth/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<string name="fui_continue" translation_description="Button text to continue">Continue</string>
1010
<string name="fui_tos_and_pp" translation_description="Global ToS and privacy policy message">By continuing, you are indicating that you accept our <xliff:g example="https://google.com/terms" id="tos" translation_description="Terms of service text">%1$s</xliff:g> and <xliff:g example="https://google.com/privacy" id="pp" translation_description="Privacy policy text">%2$s</xliff:g>.</string>
1111
<string name="fui_tos_and_pp_footer" translation_description="Global ToS and Privacy policy footer"><xliff:g example="https://google.com/terms" id="tos" translation_description="Footer ToS text">%1$s</xliff:g> \u00A0 \u00A0 <xliff:g example="https://google.com/privacy" id="pp" translation_description="Footer privacy policy text">%2$s</xliff:g></string>
12+
<string name="fui_no_internet" translation_descripition="User message shown when sign-in is attempted while offline.">Network error, check your internet connection.</string>
1213

1314
<!-- Provider -->
1415
<string name="fui_idp_name_google">Google</string>

0 commit comments

Comments
 (0)