Skip to content

Commit 2b99139

Browse files
committed
Merge branch 'puf-kill-switches' of github.com:firebase/FirebaseUI-Android into puf-kill-switches
2 parents 6c47885 + e50e0c6 commit 2b99139

File tree

14 files changed

+104
-122
lines changed

14 files changed

+104
-122
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,10 @@ public class MainActivity extends FirebaseLoginBaseActivity {
175175
protected void onStart() {
176176
super.onStart();
177177
// All providers are optional! Remove any you don't want.
178-
setEnabledAuthProvider(SocialProvider.facebook);
179-
setEnabledAuthProvider(SocialProvider.twitter);
180-
setEnabledAuthProvider(SocialProvider.google);
181-
setEnabledAuthProvider(SocialProvider.password);
178+
setEnabledAuthProvider(AuthProviderType.FACEBOOK);
179+
setEnabledAuthProvider(AuthProviderType.TWITTER);
180+
setEnabledAuthProvider(AuthProviderType.GOOGLE);
181+
setEnabledAuthProvider(AuthProviderType.PASSWORD);
182182
}
183183
```
184184

@@ -327,7 +327,7 @@ protected void onCreate(Bundle savedInstanceState) {
327327
328328
mAdapter = new FirebaseListAdapter<ChatMessage>(this, ChatMessage.class, android.R.layout.two_line_list_item, ref) {
329329
@Override
330-
protected void populateView(View view, ChatMessage chatMessage) {
330+
protected void populateView(View view, ChatMessage chatMessage, int position) {
331331
((TextView)view.findViewById(android.R.id.text1)).setText(chatMessage.getName());
332332
((TextView)view.findViewById(android.R.id.text2)).setText(chatMessage.getMessage());
333333
@@ -381,7 +381,7 @@ protected void onCreate(Bundle savedInstanceState) {
381381

382382
mAdapter = new FirebaseListAdapter<ChatMessage>(this, ChatMessage.class, android.R.layout.two_line_list_item, ref) {
383383
@Override
384-
protected void populateView(View view, ChatMessage chatMessage) {
384+
protected void populateView(View view, ChatMessage chatMessage, int position) {
385385
((TextView)view.findViewById(android.R.id.text1)).setText(chatMessage.getName());
386386
((TextView)view.findViewById(android.R.id.text2)).setText(chatMessage.getMessage());
387387
}
@@ -424,7 +424,7 @@ If we use the same layout as before (`android.R.layout.two_line_list_item`), the
424424
We can wrap that in a ViewHolder with:
425425

426426
```java
427-
private static class ChatMessageViewHolder extends RecyclerView.ViewHolder {
427+
public static class ChatMessageViewHolder extends RecyclerView.ViewHolder {
428428
TextView messageText;
429429
TextView nameText;
430430

@@ -449,7 +449,7 @@ recycler.setLayoutManager(new LinearLayoutManager(this));
449449
450450
mAdapter = new FirebaseRecyclerViewAdapter<ChatMessage, ChatMessageViewHolder>(ChatMessage.class, android.R.layout.two_line_list_item, ChatMessageViewHolder.class, mRef) {
451451
@Override
452-
public void populateViewHolder(ChatMessageViewHolder chatMessageViewHolder, ChatMessage chatMessage) {
452+
public void populateViewHolder(ChatMessageViewHolder chatMessageViewHolder, ChatMessage chatMessage, int position) {
453453
chatMessageViewHolder.nameText.setText(chatMessage.getName());
454454
chatMessageViewHolder.messageText.setText(chatMessage.getMessage());
455455
}

app/build.gradle

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
apply plugin: 'com.android.application'
2-
apply plugin: 'com.google.gms.google-services'
32

43
android {
54
compileSdkVersion 22
@@ -23,7 +22,7 @@ android {
2322
exclude 'META-INF/NOTICE'
2423
exclude 'META-INF/NOTICE.txt'
2524
}
26-
25+
2726
}
2827

2928
dependencies {
@@ -34,4 +33,4 @@ dependencies {
3433
compile 'com.android.support:recyclerview-v7:22.2.1'
3534
compile 'com.facebook.android:facebook-android-sdk:4.6.0'
3635
compile project(':library')
37-
}
36+
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import com.firebase.ui.auth.core.FirebaseLoginBaseActivity;
2424
import com.firebase.ui.FirebaseRecyclerAdapter;
2525
import com.firebase.ui.auth.core.FirebaseLoginError;
26-
import com.firebase.ui.auth.core.SocialProvider;
26+
import com.firebase.ui.auth.core.AuthProviderType;
2727

2828
public class RecyclerViewDemoActivity extends FirebaseLoginBaseActivity {
2929

@@ -99,10 +99,10 @@ public void populateViewHolder(ChatHolder chatView, Chat chat, int position) {
9999
@Override
100100
protected void onStart() {
101101
super.onStart();
102-
setEnabledAuthProvider(SocialProvider.FACEBOOK);
103-
setEnabledAuthProvider(SocialProvider.TWITTER);
104-
setEnabledAuthProvider(SocialProvider.GOOGLE);
105-
setEnabledAuthProvider(SocialProvider.PASSWORD);
102+
setEnabledAuthProvider(AuthProviderType.FACEBOOK);
103+
setEnabledAuthProvider(AuthProviderType.TWITTER);
104+
setEnabledAuthProvider(AuthProviderType.GOOGLE);
105+
setEnabledAuthProvider(AuthProviderType.PASSWORD);
106106
}
107107

108108
@Override

codelabs/chat/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,14 +282,14 @@ Let's take this in chunks: first we'll create a Java class to represent each mes
282282
mListAdapter = new FirebaseListAdapter<ChatMessage>(this, ChatMessage.class,
283283
android.R.layout.two_line_list_item, mFirebaseRef) {
284284
@Override
285-
protected void populateView(View v, ChatMessage model) {
285+
protected void populateView(View v, ChatMessage model, int position) {
286286
((TextView)v.findViewById(android.R.id.text1)).setText(model.getName());
287287
((TextView)v.findViewById(android.R.id.text2)).setText(model.getText());
288288
}
289289
};
290290
setListAdapter(mListAdapter);
291291

292-
The FirebaseListAdapter maps the data from your Firebase database into the ListView that you added to the layout. It creates a new instance of your `two_line_list_item` for each `ChatMessage` and calls the `populateView method`. We override this method and put the name and text in the correct subviews.
292+
The FirebaseListAdapter maps the data from your Firebase database into the ListView that you added to the layout. It creates a new instance of your `two_line_list_item` for each `ChatMessage` and calls the `populateView` method. We override this method and put the name and text in the correct subviews.
293293

294294
![MainActivity code](images/5_6.png)
295295

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

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import android.view.ViewGroup;
3434
import android.widget.BaseAdapter;
3535

36+
import com.firebase.client.DataSnapshot;
3637
import com.firebase.client.Firebase;
3738
import com.firebase.client.Query;
3839

@@ -48,7 +49,7 @@
4849
* Firebase ref = new Firebase("https://<yourapp>.firebaseio.com");
4950
* ListAdapter adapter = new FirebaseListAdapter<ChatMessage>(this, ChatMessage.class, android.R.layout.two_line_list_item, mRef)
5051
* {
51-
* protected void populateView(View view, ChatMessage chatMessage)
52+
* protected void populateView(View view, ChatMessage chatMessage, int position)
5253
* {
5354
* ((TextView)view.findViewById(android.R.id.text1)).setText(chatMessage.getName());
5455
* ((TextView)view.findViewById(android.R.id.text2)).setText(chatMessage.getMessage());
@@ -111,7 +112,20 @@ public int getCount() {
111112
}
112113

113114
@Override
114-
public T getItem(int i) { return mSnapshots.getItem(i).getValue(mModelClass); }
115+
public T getItem(int position) {
116+
return parseSnapshot(mSnapshots.getItem(position));
117+
}
118+
119+
/**
120+
* This method parses the DataSnapshot into the requested type. You can override it in subclasses
121+
* to do custom parsing.
122+
*
123+
* @param snapshot the DataSnapshot to extract the model from
124+
* @return the model extracted from the DataSnapshot
125+
*/
126+
protected T parseSnapshot(DataSnapshot snapshot) {
127+
return snapshot.getValue(mModelClass);
128+
}
115129

116130
public Firebase getRef(int position) { return mSnapshots.getItem(position).getRef(); }
117131

@@ -127,7 +141,7 @@ public View getView(int position, View view, ViewGroup viewGroup) {
127141
view = mActivity.getLayoutInflater().inflate(mLayout, viewGroup, false);
128142
}
129143

130-
T model = mSnapshots.getItem(position).getValue(mModelClass);
144+
T model = getItem(position);
131145

132146
// Call out to subclass to marshall this model into the provided view
133147
populateView(view, model, position);
@@ -140,30 +154,11 @@ public View getView(int position, View view, ViewGroup viewGroup) {
140154
* this class. The third argument is the item's position in the list.
141155
* <p>
142156
* Your implementation should populate the view using the data contained in the model.
143-
* You should implement either this method or the other {@link FirebaseListAdapter#populateView(View, Object)} method
144-
* but not both.
145157
*
146158
* @param v The view to populate
147159
* @param model The object containing the data used to populate the view
148160
* @param position The position in the list of the view being populated
149161
*/
150-
protected void populateView(View v, T model, int position) {
151-
populateView(v, model);
152-
}
153-
154-
/**
155-
* This is a backwards compatible version of populateView.
156-
* <p>
157-
* You should implement either this method or the other {@link FirebaseListAdapter#populateView(View, Object, int)} method
158-
* but not both.
159-
*
160-
* @see FirebaseListAdapter#populateView(View, Object, int)
161-
*
162-
* @param v The view to populate
163-
* @param model The object containing the data used to populate the view
164-
*/
165-
@Deprecated
166-
protected void populateView(View v, T model) {
162+
abstract protected void populateView(View v, T model, int position);
167163

168-
}
169164
}

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

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import android.view.View;
3434
import android.view.ViewGroup;
3535

36+
import com.firebase.client.DataSnapshot;
3637
import com.firebase.client.Firebase;
3738
import com.firebase.client.Query;
3839

@@ -68,7 +69,7 @@
6869
* recycler.setLayoutManager(new LinearLayoutManager(this));
6970
*
7071
* adapter = new FirebaseRecyclerAdapter<ChatMessage, ChatMessageViewHolder>(ChatMessage.class, android.R.layout.two_line_list_item, ChatMessageViewHolder.class, mRef) {
71-
* public void populateViewHolder(ChatMessageViewHolder chatMessageViewHolder, ChatMessage chatMessage) {
72+
* public void populateViewHolder(ChatMessageViewHolder chatMessageViewHolder, ChatMessage chatMessage, int position) {
7273
* chatMessageViewHolder.nameText.setText(chatMessage.getName());
7374
* chatMessageViewHolder.messageText.setText(chatMessage.getMessage());
7475
* }
@@ -136,7 +137,6 @@ public FirebaseRecyclerAdapter(Class<T> modelClass, int modelLayout, Class<VH> v
136137
this(modelClass, modelLayout, viewHolderClass, (Query) ref);
137138
}
138139

139-
140140
public void cleanup() {
141141
mSnapshots.cleanup();
142142
}
@@ -147,7 +147,18 @@ public int getItemCount() {
147147
}
148148

149149
public T getItem(int position) {
150-
return mSnapshots.getItem(position).getValue(mModelClass);
150+
return parseSnapshot(mSnapshots.getItem(position));
151+
}
152+
153+
/**
154+
* This method parses the DataSnapshot into the requested type. You can override it in subclasses
155+
* to do custom parsing.
156+
*
157+
* @param snapshot the DataSnapshot to extract the model from
158+
* @return the model extracted from the DataSnapshot
159+
*/
160+
protected T parseSnapshot(DataSnapshot snapshot) {
161+
return snapshot.getValue(mModelClass);
151162
}
152163

153164
public Firebase getRef(int position) { return mSnapshots.getItem(position).getRef(); }
@@ -186,29 +197,10 @@ public void onBindViewHolder(VH viewHolder, int position) {
186197
* this class. The third argument is the item's position in the list.
187198
* <p>
188199
* Your implementation should populate the view using the data contained in the model.
189-
* You should implement either this method or the other FirebaseRecyclerAdapter#populateViewHolder(VH, Object) method
190-
* but not both.
191200
*
192201
* @param viewHolder The view to populate
193202
* @param model The object containing the data used to populate the view
194203
* @param position The position in the list of the view being populated
195204
*/
196-
protected void populateViewHolder(VH viewHolder, T model, int position) {
197-
populateViewHolder(viewHolder, model);
198-
};
199-
/**
200-
* This is a backwards compatible version of populateViewHolder.
201-
* <p>
202-
* You should implement either this method or the other FirebaseRecyclerAdapter#populateViewHolder(VH, T, int) method
203-
* but not both.
204-
*
205-
* @see FirebaseListAdapter#populateView(View, Object, int)
206-
*
207-
* @param viewHolder The view to populate
208-
* @param model The object containing the data used to populate the view
209-
*/
210-
@Deprecated
211-
protected void populateViewHolder(VH viewHolder, T model) {
212-
};
213-
205+
abstract protected void populateViewHolder(VH viewHolder, T model, int position);
214206
}

library/src/main/java/com/firebase/ui/auth/core/SocialProvider.java renamed to library/src/main/java/com/firebase/ui/auth/core/AuthProviderType.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,20 @@
1111

1212
import java.lang.reflect.InvocationTargetException;
1313

14-
public enum SocialProvider {
15-
GOOGLE ("google", GoogleAuthProvider.class, R.id.google_button),
16-
FACEBOOK("facebook", FacebookAuthProvider.class, R.id.facebook_button),
17-
TWITTER ("twitter", TwitterAuthProvider.class, R.id.twitter_button),
18-
PASSWORD("password", PasswordAuthProvider.class, R.id.password_button);
14+
public enum AuthProviderType {
15+
GOOGLE ("google", "google.GoogleAuthProvider", R.id.google_button),
16+
FACEBOOK("facebook", "facebook.FacebookAuthProvider", R.id.facebook_button),
17+
TWITTER ("twitter", "twitter.TwitterAuthProvider", R.id.twitter_button),
18+
PASSWORD("password", "password.PasswordAuthProvider", R.id.password_button);
1919

20+
private final static String AUTH_PACKAGE = "com.firebase.ui.auth.";
2021
private final String mName;
21-
private final Class<? extends FirebaseAuthProvider> mClass;
22+
private final String mProviderName;
2223
private final int mButtonId;
2324

24-
SocialProvider(String name, Class<? extends FirebaseAuthProvider> clazz, int button_id) {
25+
AuthProviderType(String name, String providerName, int button_id) {
2526
this.mName = name;
26-
this.mClass = clazz;
27+
this.mProviderName = providerName;
2728
this.mButtonId = button_id;
2829
}
2930

@@ -36,7 +37,8 @@ public int getButtonId() {
3637

3738
public FirebaseAuthProvider createProvider(Context context, Firebase ref, TokenAuthHandler handler) {
3839
try {
39-
return mClass.getConstructor(Context.class, SocialProvider.class, String.class, Firebase.class, TokenAuthHandler.class).newInstance(context, this, this.getName(), ref, handler);
40+
Class<? extends FirebaseAuthProvider> clazz = (Class<? extends FirebaseAuthProvider>) Class.forName(AUTH_PACKAGE+mProviderName);
41+
return clazz.getConstructor(Context.class, AuthProviderType.class, String.class, Firebase.class, TokenAuthHandler.class).newInstance(context, this, this.getName(), ref, handler);
4042
} catch (NoSuchMethodException e) {
4143
throw new RuntimeException(e);
4244
} catch (IllegalAccessException e) {
@@ -45,10 +47,12 @@ public FirebaseAuthProvider createProvider(Context context, Firebase ref, TokenA
4547
throw new RuntimeException(e);
4648
} catch (InvocationTargetException e) {
4749
throw new RuntimeException(e);
50+
} catch (ClassNotFoundException e) {
51+
throw new RuntimeException(e);
4852
}
4953
}
50-
public static SocialProvider getTypeForProvider(FirebaseAuthProvider provider) {
51-
for (SocialProvider type : SocialProvider.values()) {
54+
public static AuthProviderType getTypeForProvider(FirebaseAuthProvider provider) {
55+
for (AuthProviderType type : AuthProviderType.values()) {
5256
if (provider.getProviderName() == type.getName()) {
5357
return type;
5458
}

library/src/main/java/com/firebase/ui/auth/core/FirebaseAuthProvider.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.firebase.ui.auth.core;
22

33
import android.content.Context;
4+
import android.content.Intent;
45
import android.util.Log;
56

67
import com.firebase.client.AuthData;
@@ -13,37 +14,49 @@
1314
public abstract class FirebaseAuthProvider {
1415
private static final String TAG = "FirebaseAuthProvider";
1516
private final Context mContext;
16-
private final SocialProvider mProviderType;
17+
private final AuthProviderType mAuthProviderType;
1718
private final String mProviderName;
1819
private final Firebase mRef;
1920
private final TokenAuthHandler mHandler;
2021

2122
public abstract void logout();
2223
public Context getContext() { return mContext; }
23-
public SocialProvider getProviderType() { return mProviderType; }
24+
public AuthProviderType getProviderType() { return mAuthProviderType; }
2425
public String getProviderName() { return mProviderName; }
2526
public Firebase getFirebaseRef() { return mRef; }
2627
public TokenAuthHandler getHandler() { return mHandler; }
2728

28-
protected FirebaseAuthProvider(Context context, SocialProvider providerType, String providerName, Firebase ref, TokenAuthHandler handler) {
29+
protected FirebaseAuthProvider(Context context, AuthProviderType providerType, String providerName, Firebase ref, TokenAuthHandler handler) {
2930
mContext = context;
30-
mProviderType = providerType;
31+
mAuthProviderType = providerType;
3132
mProviderName = providerName;
3233
mRef = ref;
3334
mHandler = handler;
3435
}
3536

3637
public void login() {
37-
Log.d("FirebaseAuthProvider", "Login() is not supported for provider type " + getProviderName());
38+
Log.w("FirebaseAuthProvider", "Login() is not supported for provider type " + getProviderName());
3839
};
3940
public void login(String email, String password) {
40-
Log.d("FirebaseAuthProvider", "Login(String email, String password) is not supported for provider type " + getProviderName());
41+
Log.w("FirebaseAuthProvider", "Login(String email, String password) is not supported for provider type " + getProviderName());
4142
};
4243

4344
public void onFirebaseTokenReceived(FirebaseOAuthToken token, TokenAuthHandler handler) {
4445
authenticateRefWithOAuthFirebasetoken(token, handler);
4546
}
4647

48+
/**
49+
* Override this method in your provider subclass if you start an activity from the login() method.
50+
* Receive the result from a previous call to startActivityForResult(Intent, int). This follows
51+
* the related Activity API as described there in onActivityResult(int, int, Intent).
52+
* @param requestCode The integer request code originally supplied to startActivityForResult(),
53+
* allowing you to identify who this result came from/
54+
* @param resultCode The integer result code returned by the child activity through its setResult().
55+
* @param data An Intent, which can return result data to the caller (various data can be attached to Intent "extras").
56+
*/
57+
public void onActivityResult(int requestCode, int resultCode, Intent data) {
58+
}
59+
4760
private void authenticateRefWithOAuthFirebasetoken(FirebaseOAuthToken token, final TokenAuthHandler handler) {
4861
Firebase.AuthResultHandler authResultHandler = new Firebase.AuthResultHandler() {
4962
@Override

0 commit comments

Comments
 (0)