Skip to content

Offline Auth method picker #1586

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions auth/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ android {
disable("UnusedQuantity")
disable("UnknownNullness") // TODO fix in future PR
disable("TypographyQuotes") // Straight versus directional quotes
disable("MissingTranslation") // STOPSHIP: Get translations
}

testOptions {
Expand Down
22 changes: 1 addition & 21 deletions auth/src/main/java/com/firebase/ui/auth/KickoffActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import android.arch.lifecycle.ViewModelProviders;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
Expand Down Expand Up @@ -62,12 +61,7 @@ public void onSuccess(Void aVoid) {
return;
}

if (isOffline()) {
finish(RESULT_CANCELED, IdpResponse.getErrorIntent(
new FirebaseUiException(ErrorCodes.NO_NETWORK)));
} else {
mKickstarter.start();
}
mKickstarter.start();
}
})
.addOnFailureListener(this, new OnFailureListener() {
Expand Down Expand Up @@ -98,18 +92,4 @@ public void invalidateEmailLink() {
setIntent(getIntent().putExtra(ExtraConstants.FLOW_PARAMS,
flowParameters));
}

/**
* Check if there is an active or soon-to-be-active network connection.
*
* @return true if there is no network connection, false otherwise.
*/
private boolean isOffline() {
ConnectivityManager manager = (ConnectivityManager) getApplicationContext()
.getSystemService(Context.CONNECTIVITY_SERVICE);

return !(manager != null
&& manager.getActiveNetworkInfo() != null
&& manager.getActiveNetworkInfo().isConnectedOrConnecting());
}
}
15 changes: 15 additions & 0 deletions auth/src/main/java/com/firebase/ui/auth/ui/HelperActivityBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.RestrictTo;
Expand Down Expand Up @@ -75,4 +76,18 @@ public void startSaveCredentials(
this, getFlowParams(), credential, response);
startActivityForResult(intent, RequestCodes.CRED_SAVE_FLOW);
}

/**
* Check if there is an active or soon-to-be-active network connection.
*
* @return true if there is no network connection, false otherwise.
*/
protected boolean isOffline() {
ConnectivityManager manager = (ConnectivityManager) getApplicationContext()
.getSystemService(Context.CONNECTIVITY_SERVICE);

return !(manager != null
&& manager.getActiveNetworkInfo() != null
&& manager.getActiveNetworkInfo().isConnectedOrConnecting());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,11 @@ private void handleResponse(@NonNull IdpResponse response) {
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (isOffline()) {
Toast.makeText(AuthMethodPickerActivity.this, getString(R.string.fui_no_internet), Toast.LENGTH_SHORT).show();
return;
}

provider.startSignIn(AuthMethodPickerActivity.this);
}
});
Expand Down
1 change: 1 addition & 0 deletions auth/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<string name="fui_continue" translation_description="Button text to continue">Continue</string>
<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>
<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>
<string name="fui_no_internet" translation_descripition="User message shown when sign-in is attempted while offline.">Network error, check your internet connection.</string>

<!-- Provider -->
<string name="fui_idp_name_google">Google</string>
Expand Down