Skip to content

Commit 6148882

Browse files
committed
More cleanup of errors and keys
1 parent 17ba409 commit 6148882

18 files changed

+235
-158
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,17 @@
2020
<category android:name="android.intent.category.LAUNCHER" />
2121
</intent-filter>
2222
</activity>
23-
<activity android:name="com.firebase.ui.authimpl.TwitterPromptActivity"></activity>
2423

24+
<!-- Twitter Configuration -->
25+
<activity android:name="com.firebase.ui.auth.TwitterPromptActivity" />
26+
<meta-data
27+
android:name="com.firebase.ui.TwitterKey"
28+
android:value="@string/twitter_app_key"/>
29+
<meta-data
30+
android:name="com.firebase.ui.TwitterSecret"
31+
android:value="@string/twitter_app_secret"/>
32+
33+
<!-- Facebook Configuration -->
2534
<activity
2635
android:name="com.facebook.FacebookActivity"
2736
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
@@ -30,6 +39,8 @@
3039
<meta-data
3140
android:name="com.facebook.sdk.ApplicationId"
3241
android:value="@string/facebook_app_id" />
42+
43+
3344
</application>
3445

3546
</manifest>

app/src/main/java/com/firebase/uidemo/RecyclerViewDemoActivity.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -71,23 +71,23 @@ protected void updateChat() {
7171
messages.setLayoutManager(manager);
7272

7373
Query recentMessages = mRef.limitToLast(50);
74-
FirebaseRecyclerViewAdapter<Chat, ChatHolder> adapter = new FirebaseRecyclerViewAdapter<Chat, ChatHolder>(Chat.class, android.R.layout.two_line_list_item, ChatHolder.class, recentMessages) {
74+
FirebaseRecyclerViewAdapter<Chat, ChatHolder> adapter = new FirebaseRecyclerViewAdapter<Chat, ChatHolder>(Chat.class, R.layout.message, ChatHolder.class, recentMessages) {
7575
@Override
7676
public void populateViewHolder(ChatHolder chatView, Chat chat) {
7777
chatView.textView.setText(chat.getText());
78-
chatView.textView.setPadding(30, 30, 30, 0);
79-
chatView.nameView.setText(chat.getName());
80-
chatView.nameView.setPadding(30, 0, 30, 30);
81-
chatView.textView.setTextColor(Color.parseColor("#000000"));
82-
chatView.textView.setTypeface(null, Typeface.NORMAL);
78+
// chatView.textView.setPadding(30, 30, 30, 0);
79+
// chatView.nameView.setText(chat.getName());
80+
// chatView.nameView.setPadding(30, 0, 30, 30);
81+
// chatView.textView.setTextColor(Color.parseColor("#000000"));
82+
// chatView.textView.setTypeface(null, Typeface.NORMAL);
8383
if (mAuthData != null && chat.getUid().equals(mAuthData.getUid())) {
84-
chatView.textView.setGravity(Gravity.END);
85-
chatView.nameView.setGravity(Gravity.END);
86-
chatView.nameView.setTextColor(Color.parseColor("#AAAAAA"));
87-
chatView.itemView.setBackground(getDrawable(R.drawable.outgoing_message));
84+
// chatView.textView.setGravity(Gravity.END);
85+
// chatView.nameView.setGravity(Gravity.END);
86+
// chatView.nameView.setTextColor(Color.parseColor("#AAAAAA"));
87+
// chatView.itemView.setBackground(getDrawable(R.drawable.outgoing_message));
8888
} else {
89-
chatView.nameView.setTextColor(Color.parseColor("#00BCD4"));
90-
chatView.itemView.setBackground(getDrawable(R.drawable.incoming_message));
89+
// chatView.nameView.setTextColor(Color.parseColor("#00BCD4"));
90+
// chatView.itemView.setBackground(getDrawable(R.drawable.incoming_message));
9191
}
9292
}
9393
};
@@ -158,12 +158,12 @@ public void onFirebaseLogout() {
158158

159159
@Override
160160
public void onFirebaseLoginProviderError(FirebaseError firebaseError) {
161-
Log.e(TAG, firebaseError.toString());
161+
Log.i(TAG, "Login provider error: " + firebaseError.toString());
162162
}
163163

164164
@Override
165165
public void onFirebaseLoginUserError(FirebaseError firebaseError) {
166-
Log.i(TAG, "Login cancelled");
166+
Log.i(TAG, "Login user error: " + firebaseError.toString());
167167
}
168168

169169
@Override
@@ -207,8 +207,8 @@ public static class ChatHolder extends RecyclerView.ViewHolder {
207207
public ChatHolder(View itemView) {
208208
super(itemView);
209209
this.itemView = itemView;
210-
nameView = (TextView) itemView.findViewById(android.R.id.text2);
211-
textView = (TextView) itemView.findViewById(android.R.id.text1);
210+
//nameView = (TextView) itemView.findViewById(android.R.id.text2);
211+
textView = (TextView) itemView.findViewById(R.id.message_text);
212212
}
213213
}
214214
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<resources>
22
<string name="app_name">FirebaseUI Chat</string>
3+
<!-- FirebaseUI Configuration -->
34
<string name="facebook_app_id">547033782072218</string>
5+
<string name="twitter_app_key">mbX13kp9wqi3JzmwXwATvciAZ</string>
6+
<string name="twitter_app_secret">8QObfaBn0YxzvZ0RiyoW8BUL8o3LBSfeElRHPR5ppvkFRqEMTq</string>
47
</resources>

library/src/main/java/com/firebase/ui/FirebaseLoginBaseActivity.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
import com.firebase.client.AuthData;
88
import com.firebase.client.Firebase;
99
import com.firebase.client.FirebaseError;
10-
import com.firebase.ui.authimpl.FacebookAuthHelper;
11-
import com.firebase.ui.authimpl.GoogleAuthHelper;
12-
import com.firebase.ui.authimpl.PasswordAuthHelper;
13-
import com.firebase.ui.authimpl.SocialProvider;
14-
import com.firebase.ui.authimpl.TokenAuthHandler;
15-
import com.firebase.ui.authimpl.TwitterAuthHelper;
10+
import com.firebase.ui.auth.FacebookAuthHelper;
11+
import com.firebase.ui.auth.GoogleAuthHelper;
12+
import com.firebase.ui.auth.PasswordAuthHelper;
13+
import com.firebase.ui.auth.SocialProvider;
14+
import com.firebase.ui.auth.TokenAuthHandler;
15+
import com.firebase.ui.auth.TwitterAuthHelper;
1616

1717
public abstract class FirebaseLoginBaseActivity extends AppCompatActivity {
1818

library/src/main/java/com/firebase/ui/FirebaseLoginDialog.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import android.view.View;
99
import android.widget.EditText;
1010

11-
import com.firebase.ui.authimpl.FirebaseAuthHelper;
11+
import com.firebase.ui.auth.FirebaseAuthHelper;
1212

1313
public class FirebaseLoginDialog extends DialogFragment {
1414

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
package com.firebase.ui.auth;
2+
3+
import android.app.Activity;
4+
import android.content.Context;
5+
import android.content.pm.ApplicationInfo;
6+
import android.content.pm.PackageManager;
7+
import android.os.Bundle;
8+
9+
import com.facebook.AccessToken;
10+
import com.facebook.CallbackManager;
11+
import com.facebook.FacebookCallback;
12+
import com.facebook.FacebookException;
13+
import com.facebook.FacebookSdk;
14+
import com.facebook.login.LoginManager;
15+
import com.facebook.login.LoginResult;
16+
import com.firebase.client.Firebase;
17+
import com.firebase.client.FirebaseError;
18+
19+
import java.util.Arrays;
20+
import java.util.Collection;
21+
22+
public class FacebookAuthHelper extends FirebaseAuthHelper {
23+
24+
private final String LOG_TAG = "FacebookAuthHelper";
25+
26+
public static final String PROVIDER_NAME = "facebook";
27+
28+
private LoginManager mLoginManager;
29+
public CallbackManager mCallbackManager;
30+
private TokenAuthHandler mHandler;
31+
private Activity mActivity;
32+
private Firebase mRef;
33+
private Boolean isReady = false;
34+
35+
public FacebookAuthHelper(Context context, Firebase ref, final TokenAuthHandler handler) {
36+
mActivity = (Activity) context;
37+
FacebookSdk.sdkInitialize(context.getApplicationContext());
38+
39+
mLoginManager = LoginManager.getInstance();
40+
mCallbackManager = CallbackManager.Factory.create();
41+
mHandler = handler;
42+
mRef = ref;
43+
44+
mLoginManager.registerCallback(mCallbackManager,
45+
new FacebookCallback<LoginResult>() {
46+
@Override
47+
public void onSuccess(LoginResult loginResult) {
48+
AccessToken token = loginResult.getAccessToken();
49+
50+
FirebaseOAuthToken foToken = new FirebaseOAuthToken(
51+
PROVIDER_NAME,
52+
token.getToken().toString());
53+
54+
onFirebaseTokenReceived(foToken, handler);
55+
}
56+
57+
@Override
58+
public void onCancel() {
59+
mHandler.onUserError(new FirebaseError(0, "User closed login prompt."));
60+
}
61+
62+
@Override
63+
public void onError(FacebookException ex) {
64+
mHandler.onProviderError(new FirebaseError(1, ex.toString()));
65+
}
66+
}
67+
);
68+
69+
String facebookAppId = "";
70+
71+
try {
72+
ApplicationInfo ai = mActivity.getPackageManager().getApplicationInfo(mActivity.getPackageName(), PackageManager.GET_META_DATA);
73+
Bundle bundle = ai.metaData;
74+
facebookAppId = bundle.getString("com.facebook.sdk.ApplicationId");
75+
} catch (PackageManager.NameNotFoundException e) {
76+
} catch (NullPointerException e) {}
77+
78+
if (facebookAppId == null) {
79+
mHandler.onProviderError(new FirebaseError(FirebaseStatuses.PROVIDER_ERROR, "Invalid Facebook Application ID, is it set in your AndroidManifest.xml?"));
80+
return;
81+
}
82+
83+
if (facebookAppId.compareTo("") == 0) {
84+
mHandler.onProviderError(new FirebaseError(FirebaseStatuses.PROVIDER_ERROR, "Invalid Facebook Application ID, is it set in your res/values/strings.xml?"));
85+
return;
86+
}
87+
88+
isReady = true;
89+
}
90+
91+
public void login() {
92+
if (isReady) {
93+
Collection<String> permissions = Arrays.asList("public_profile");
94+
mLoginManager.logInWithReadPermissions(mActivity, permissions);
95+
}
96+
}
97+
98+
public String getProviderName() {
99+
return PROVIDER_NAME;
100+
}
101+
102+
public Firebase getFirebaseRef() {return mRef; }
103+
104+
public void logout() {
105+
mLoginManager.logOut();
106+
}
107+
}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.firebase.ui.authimpl;
1+
package com.firebase.ui.auth;
22

33
import android.util.Log;
44

@@ -26,37 +26,29 @@ public void onFirebaseTokenReceived(FirebaseOAuthToken token, TokenAuthHandler h
2626
}
2727

2828
private void authenticateRefWithOAuthFirebasetoken(FirebaseOAuthToken token, final TokenAuthHandler handler) {
29+
Firebase.AuthResultHandler authResultHandler = new Firebase.AuthResultHandler() {
30+
@Override
31+
public void onAuthenticated(AuthData authData) {
32+
// Do nothing. Auth updates are handled in the AuthStateListener
33+
}
34+
35+
@Override
36+
public void onAuthenticationError(FirebaseError firebaseError) {
37+
handler.onProviderError(new FirebaseError(0, "Make sure " + getProviderName() + " login is enabled and configured in your Firebase."));
38+
}
39+
};
40+
2941
if (token.mode == FirebaseOAuthToken.SIMPLE) {
3042
// Simple mode is used for Facebook and Google auth
31-
getFirebaseRef().authWithOAuthToken(token.provider, token.token, new Firebase.AuthResultHandler() {
32-
@Override
33-
public void onAuthenticated(AuthData authData) {
34-
// Do nothing. Auth updates are handled in the AuthStateListener
35-
}
36-
37-
@Override
38-
public void onAuthenticationError(FirebaseError firebaseError) {
39-
handler.onUserError(new FirebaseError(0, "auth_error"));
40-
}
41-
});
43+
getFirebaseRef().authWithOAuthToken(token.provider, token.token, authResultHandler);
4244
} else if (token.mode == FirebaseOAuthToken.COMPLEX) {
4345
// Complex mode is used for Twitter auth
4446
Map<String, String> options = new HashMap<>();
4547
options.put("oauth_token", token.token);
4648
options.put("oauth_token_secret", token.secret);
4749
options.put("user_id", token.uid);
4850

49-
getFirebaseRef().authWithOAuthToken(token.provider, options, new Firebase.AuthResultHandler() {
50-
@Override
51-
public void onAuthenticated(AuthData authData) {
52-
// Do nothing. Auth updates are handled in the AuthStateListener
53-
}
54-
55-
@Override
56-
public void onAuthenticationError(FirebaseError firebaseError) {
57-
handler.onUserError(new FirebaseError(0, "auth_error"));
58-
}
59-
});
51+
getFirebaseRef().authWithOAuthToken(token.provider, options, authResultHandler);
6052
}
6153
}
6254
}

library/src/main/java/com/firebase/ui/authimpl/FirebaseOAuthToken.java renamed to library/src/main/java/com/firebase/ui/auth/FirebaseOAuthToken.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.firebase.ui.authimpl;
1+
package com.firebase.ui.auth;
22

33
public class FirebaseOAuthToken {
44
public String token;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.firebase.ui.auth;
2+
3+
/**
4+
* Created by abehaskins on 11/9/15.
5+
*/
6+
public class FirebaseStatuses {
7+
public static final int LOGIN = 0;
8+
public static final int USER_ERROR = 1;
9+
public static final int PROVIDER_ERROR = 2;
10+
public static final int SUCCESS = 3;
11+
}
12+

library/src/main/java/com/firebase/ui/authimpl/GoogleAuthHelper.java renamed to library/src/main/java/com/firebase/ui/auth/GoogleAuthHelper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.firebase.ui.authimpl;
1+
package com.firebase.ui.auth;
22

33
import android.app.Activity;
44
import android.content.Context;
@@ -77,7 +77,7 @@ public void onTokenReceived(String token) {
7777
FirebaseOAuthToken foToken = new FirebaseOAuthToken(
7878
PROVIDER_NAME,
7979
token);
80-
//mHandler.onTokenReceived(foToken);
80+
onFirebaseTokenReceived(foToken, mHandler);
8181
}
8282

8383
@Override

0 commit comments

Comments
 (0)