Skip to content

Commit be439e3

Browse files
author
Aaron Mandle
committed
Fix the taskbar showing on invisible activities.
Change-Id: Ib94320b887fabba1771ed36f62075c077a147ef4
1 parent 1106c29 commit be439e3

20 files changed

+328
-387
lines changed

auth/src/main/java/com/firebase/ui/auth/ui/email/AcquireEmailActivity.java renamed to auth/src/main/java/com/firebase/ui/auth/ui/AcquireEmailHelper.java

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@
1212
* limitations under the License.
1313
*/
1414

15-
package com.firebase.ui.auth.ui.email;
15+
package com.firebase.ui.auth.ui;
1616

1717
import android.content.Intent;
1818
import android.support.annotation.NonNull;
1919

2020
import com.firebase.ui.auth.R;
2121
import com.firebase.ui.auth.choreographer.ControllerConstants;
22-
import com.firebase.ui.auth.ui.NoControllerBaseActivity;
2322
import com.firebase.ui.auth.ui.account_link.WelcomeBackIDPPrompt;
23+
import com.firebase.ui.auth.ui.email.RegisterEmailActivity;
24+
import com.firebase.ui.auth.ui.email.SignInActivity;
2425
import com.google.android.gms.tasks.OnCompleteListener;
2526
import com.google.android.gms.tasks.Task;
2627
import com.google.firebase.auth.EmailAuthProvider;
@@ -30,19 +31,25 @@
3031
import java.util.Arrays;
3132
import java.util.List;
3233

33-
public abstract class AcquireEmailActivity extends NoControllerBaseActivity {
34-
protected static final int RC_REGISTER_ACCOUNT = 14;
35-
protected static final int RC_WELCOME_BACK_IDP = 15;
36-
protected static final int RC_SIGN_IN = 16;
37-
private static final List<Integer> REQUEST_CODES = Arrays.asList(
34+
public class AcquireEmailHelper {
35+
public static final int RC_REGISTER_ACCOUNT = 14;
36+
public static final int RC_WELCOME_BACK_IDP = 15;
37+
public static final int RC_SIGN_IN = 16;
38+
public static final List<Integer> REQUEST_CODES = Arrays.asList(
3839
RC_REGISTER_ACCOUNT,
3940
RC_WELCOME_BACK_IDP,
4041
RC_SIGN_IN
4142
);
4243

43-
protected void checkAccountExists(final String email) {
44-
FirebaseAuth firebaseAuth = getFirebaseAuth();
45-
showLoadingDialog(R.string.progress_dialog_loading);
44+
private ActivityHelper mActivityHelper;
45+
46+
public AcquireEmailHelper(ActivityHelper activityHelper) {
47+
mActivityHelper = activityHelper;
48+
}
49+
50+
public void checkAccountExists(final String email) {
51+
FirebaseAuth firebaseAuth = mActivityHelper.getFirebaseAuth();
52+
mActivityHelper.showLoadingDialog(R.string.progress_dialog_loading);
4653
if (email != null && !email.isEmpty()) {
4754
firebaseAuth.fetchProvidersForEmail(email).addOnCompleteListener(
4855
new OnCompleteListener<ProviderQueryResult>() {
@@ -56,53 +63,51 @@ public void onComplete(@NonNull Task<ProviderQueryResult> task) {
5663
}
5764

5865
private void startEmailHandler(String email, List<String> providers) {
59-
dismissDialog();
66+
mActivityHelper.dismissDialog();
6067
if (providers == null || providers.isEmpty()) {
6168
// account doesn't exist yet
6269
Intent registerIntent = RegisterEmailActivity.createIntent(
63-
AcquireEmailActivity.this,
70+
mActivityHelper.getApplicationContext(),
6471
email,
65-
mTermsOfServiceUrl,
66-
mAppName
72+
mActivityHelper.termsOfServiceUrl,
73+
mActivityHelper.appName
6774
);
68-
startActivityForResult(registerIntent, RC_REGISTER_ACCOUNT);
75+
mActivityHelper.startActivityForResult(registerIntent, RC_REGISTER_ACCOUNT);
6976
return;
7077
} else {
7178
// account does exist
7279
for (String provider: providers) {
7380
if (provider.equalsIgnoreCase(EmailAuthProvider.PROVIDER_ID)) {
7481
Intent signInIntent = SignInActivity.createIntent(
75-
this,
76-
mAppName,
82+
mActivityHelper.getApplicationContext(),
83+
mActivityHelper.appName,
7784
email,
78-
mProviderParcels
85+
mActivityHelper.providerParcels
7986
);
80-
startActivityForResult(signInIntent, RC_SIGN_IN);
87+
mActivityHelper.startActivityForResult(signInIntent, RC_SIGN_IN);
8188
return;
8289
}
8390
Intent intent = WelcomeBackIDPPrompt.createIntent(
84-
AcquireEmailActivity.this,
91+
mActivityHelper.getApplicationContext(),
8592
provider,
86-
mProviderParcels,
87-
mAppName,
93+
mActivityHelper.providerParcels,
94+
mActivityHelper.appName,
8895
email);
89-
startActivityForResult(intent, RC_WELCOME_BACK_IDP);
96+
mActivityHelper.startActivityForResult(intent, RC_WELCOME_BACK_IDP);
9097
return;
9198
}
9299

93100
Intent signInIntent = new Intent(
94-
AcquireEmailActivity.this, SignInActivity.class);
101+
mActivityHelper.getApplicationContext(), SignInActivity.class);
95102
signInIntent.putExtra(ControllerConstants.EXTRA_EMAIL, email);
96-
startActivityForResult(signInIntent, RC_SIGN_IN);
103+
mActivityHelper.startActivityForResult(signInIntent, RC_SIGN_IN);
97104
return;
98105
}
99106
}
100107

101-
@Override
102-
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
103-
super.onActivityResult(requestCode, resultCode, data);
108+
public void onActivityResult(int requestCode, int resultCode, Intent data) {
104109
if (REQUEST_CODES.contains(requestCode)) {
105-
finish(resultCode, new Intent());
110+
mActivityHelper.finish(resultCode, new Intent());
106111
}
107112
}
108113
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2016 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5+
* in compliance with the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the
10+
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
* express or implied. See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
15+
package com.firebase.ui.auth.ui;
16+
17+
import android.app.Activity;
18+
import android.content.Intent;
19+
import android.os.Bundle;
20+
21+
public class ActivityBase extends Activity {
22+
protected ActivityHelper mActivityHelper;
23+
24+
@Override
25+
protected void onCreate(Bundle savedInstance) {
26+
super.onCreate(savedInstance);
27+
mActivityHelper = new ActivityHelper(this, getIntent());
28+
}
29+
30+
public void finish(int resultCode, Intent intent) {
31+
mActivityHelper.finish(resultCode, intent);
32+
}
33+
34+
}
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/*
2+
* Copyright 2016 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5+
* in compliance with the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the
10+
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
* express or implied. See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
15+
package com.firebase.ui.auth.ui;
16+
17+
import android.app.Activity;
18+
import android.app.ProgressDialog;
19+
import android.content.Context;
20+
import android.content.Intent;
21+
import android.support.annotation.StringRes;
22+
23+
import com.firebase.ui.auth.AuthUI;
24+
import com.firebase.ui.auth.choreographer.ControllerConstants;
25+
import com.firebase.ui.auth.choreographer.idp.provider.IDPProviderParcel;
26+
import com.google.firebase.FirebaseApp;
27+
import com.google.firebase.FirebaseOptions;
28+
import com.google.firebase.auth.FirebaseAuth;
29+
import com.google.firebase.auth.FirebaseUser;
30+
31+
import java.util.ArrayList;
32+
33+
public class ActivityHelper {
34+
private ProgressDialog mProgressDialog;
35+
private Activity mActivity;
36+
37+
public String appName;
38+
public ArrayList<IDPProviderParcel> providerParcels;
39+
public String termsOfServiceUrl;
40+
public int theme;
41+
42+
43+
public ActivityHelper(Activity activity, Intent intent) {
44+
mActivity = activity;
45+
appName = intent.getStringExtra(ControllerConstants.EXTRA_APP_NAME);
46+
providerParcels = intent.getParcelableArrayListExtra(
47+
ControllerConstants.EXTRA_PROVIDERS);
48+
termsOfServiceUrl = intent.getStringExtra(
49+
ControllerConstants.EXTRA_TERMS_OF_SERVICE_URL);
50+
theme = intent.getIntExtra(
51+
ControllerConstants.EXTRA_THEME,
52+
AuthUI.DEFAULT_THEME);
53+
}
54+
55+
public void dismissDialog() {
56+
if (mProgressDialog != null && mProgressDialog.isShowing()) {
57+
mProgressDialog.dismiss();
58+
mProgressDialog = null;
59+
}
60+
}
61+
62+
public void showLoadingDialog(String message) {
63+
dismissDialog();
64+
mProgressDialog = ProgressDialog.show(mActivity, "", message, true);
65+
}
66+
67+
public void showLoadingDialog(@StringRes int stringResource) {
68+
showLoadingDialog(mActivity.getString(stringResource));
69+
}
70+
71+
72+
private Intent addExtras(Intent intent) {
73+
intent.putExtra(ControllerConstants.EXTRA_APP_NAME, appName)
74+
.putExtra(ControllerConstants.EXTRA_TERMS_OF_SERVICE_URL, termsOfServiceUrl)
75+
.putExtra(ControllerConstants.EXTRA_THEME, theme)
76+
.putExtra(ControllerConstants.EXTRA_PROVIDERS, providerParcels);
77+
return intent;
78+
}
79+
80+
public void startActivityForResult(Intent intent, int requestCode) {
81+
mActivity.startActivityForResult(intent, requestCode);
82+
}
83+
84+
public void finish(int resultCode, Intent intent) {
85+
mActivity.setResult(resultCode, addExtras(intent));
86+
mActivity.finish();
87+
}
88+
89+
public Context getApplicationContext() {
90+
return mActivity.getApplicationContext();
91+
}
92+
93+
94+
public FirebaseApp getFirebaseApp() {
95+
return FirebaseApp.getInstance(appName);
96+
}
97+
98+
public FirebaseApp getFirebaseApp(String apiaryKey, String applicationId) {
99+
try{
100+
return FirebaseApp.getInstance(appName);
101+
} catch (IllegalStateException e) {
102+
FirebaseOptions options
103+
= new FirebaseOptions.Builder()
104+
.setApiKey(apiaryKey)
105+
.setApplicationId(applicationId)
106+
.build();
107+
return FirebaseApp.initializeApp(mActivity, options, appName);
108+
}
109+
}
110+
111+
public FirebaseAuth getFirebaseAuth() {
112+
return FirebaseAuth.getInstance(getFirebaseApp());
113+
}
114+
115+
public FirebaseUser getCurrentUser() {
116+
return getFirebaseAuth().getCurrentUser();
117+
}
118+
119+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2016 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5+
* in compliance with the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the
10+
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
* express or implied. See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
15+
package com.firebase.ui.auth.ui;
16+
17+
import android.content.Intent;
18+
import android.os.Bundle;
19+
20+
public class AppCompatBase extends android.support.v7.app.AppCompatActivity {
21+
protected ActivityHelper mActivityHelper;
22+
23+
@Override
24+
protected void onCreate(Bundle savedInstance) {
25+
super.onCreate(savedInstance);
26+
mActivityHelper = new ActivityHelper(this, getIntent());
27+
}
28+
29+
public void finish(int resultCode, Intent intent) {
30+
mActivityHelper.finish(resultCode, intent);
31+
}
32+
33+
}

0 commit comments

Comments
 (0)