Skip to content

Commit a4d7ad1

Browse files
committed
Merge branch 'FirebaseArray' into firebase-array-explore
2 parents be09c80 + 15eb5d8 commit a4d7ad1

File tree

7 files changed

+147
-76
lines changed

7 files changed

+147
-76
lines changed

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

Lines changed: 60 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414

1515
package com.firebase.uidemo;
1616

17-
import android.content.Context;
1817
import android.content.Intent;
1918
import android.os.Bundle;
19+
import android.support.annotation.StringRes;
2020
import android.support.v7.app.AppCompatActivity;
21+
import android.support.v7.widget.LinearLayoutManager;
22+
import android.support.v7.widget.RecyclerView;
2123
import android.view.LayoutInflater;
2224
import android.view.View;
2325
import android.view.ViewGroup;
24-
import android.widget.ArrayAdapter;
25-
import android.widget.ListView;
2626
import android.widget.TextView;
2727

2828
import com.firebase.uidemo.auth.AuthUiActivity;
@@ -31,73 +31,82 @@
3131

3232
import butterknife.BindView;
3333
import butterknife.ButterKnife;
34-
import butterknife.OnItemClick;
3534

3635
public class ChooserActivity extends AppCompatActivity {
37-
38-
private static final Class[] CLASSES = new Class[]{
39-
ChatActivity.class,
40-
AuthUiActivity.class,
41-
ImageActivity.class,
42-
};
43-
44-
private static final int[] DESCRIPTION_NAMES = new int[] {
45-
R.string.name_chat,
46-
R.string.name_auth_ui,
47-
R.string.name_image
48-
};
49-
50-
private static final int[] DESCRIPTION_IDS = new int[] {
51-
R.string.desc_chat,
52-
R.string.desc_auth_ui,
53-
R.string.desc_image
54-
};
55-
56-
@BindView(R.id.list_view)
57-
ListView mListView;
36+
@BindView(R.id.activities)
37+
RecyclerView mActivities;
5838

5939
@Override
6040
protected void onCreate(Bundle savedInstanceState) {
6141
super.onCreate(savedInstanceState);
6242
setContentView(R.layout.activity_chooser);
6343
ButterKnife.bind(this);
6444

65-
mListView.setAdapter(new MyArrayAdapter(
66-
this,
67-
android.R.layout.simple_list_item_2,
68-
CLASSES));
45+
mActivities.setLayoutManager(new LinearLayoutManager(this));
46+
mActivities.setAdapter(new ActivityChooserAdapter());
47+
mActivities.setHasFixedSize(true);
6948
}
7049

71-
@OnItemClick(R.id.list_view)
72-
public void onItemClick(int position) {
73-
Class clicked = CLASSES[position];
74-
startActivity(new Intent(this, clicked));
75-
}
50+
private static class ActivityChooserAdapter extends RecyclerView.Adapter<ActivityStarterHolder> {
51+
private static final Class[] CLASSES = new Class[]{
52+
ChatActivity.class,
53+
AuthUiActivity.class,
54+
ImageActivity.class,
55+
};
56+
57+
private static final int[] DESCRIPTION_NAMES = new int[]{
58+
R.string.name_chat,
59+
R.string.name_auth_ui,
60+
R.string.name_image
61+
};
62+
63+
private static final int[] DESCRIPTION_IDS = new int[]{
64+
R.string.desc_chat,
65+
R.string.desc_auth_ui,
66+
R.string.desc_image
67+
};
7668

77-
public static class MyArrayAdapter extends ArrayAdapter<Class> {
78-
79-
private Context mContext;
69+
@Override
70+
public ActivityStarterHolder onCreateViewHolder(ViewGroup parent, int viewType) {
71+
return new ActivityStarterHolder(
72+
LayoutInflater.from(parent.getContext())
73+
.inflate(R.layout.activity_chooser_item, parent, false));
74+
}
8075

81-
public MyArrayAdapter(Context context, int resource, Class... objects) {
82-
super(context, resource, objects);
83-
mContext = context;
76+
@Override
77+
public void onBindViewHolder(ActivityStarterHolder holder, int position) {
78+
holder.bind(CLASSES[position], DESCRIPTION_NAMES[position], DESCRIPTION_IDS[position]);
8479
}
8580

8681
@Override
87-
public View getView(int position, View convertView, ViewGroup parent) {
88-
View view;
82+
public int getItemCount() {
83+
return CLASSES.length;
84+
}
85+
}
86+
87+
private static class ActivityStarterHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
88+
private TextView mTitle;
89+
private TextView mDescription;
90+
91+
private Class mStarterClass;
8992

90-
if (convertView == null) {
91-
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
92-
view = inflater.inflate(android.R.layout.simple_list_item_2, null);
93-
} else {
94-
view = convertView;
95-
}
93+
public ActivityStarterHolder(View itemView) {
94+
super(itemView);
95+
mTitle = (TextView) itemView.findViewById(R.id.text1);
96+
mDescription = (TextView) itemView.findViewById(R.id.text2);
97+
}
98+
99+
private void bind(Class aClass, @StringRes int name, @StringRes int description) {
100+
mStarterClass = aClass;
96101

97-
((TextView) view.findViewById(android.R.id.text1)).setText(DESCRIPTION_NAMES[position]);
98-
((TextView) view.findViewById(android.R.id.text2)).setText(DESCRIPTION_IDS[position]);
102+
mTitle.setText(name);
103+
mDescription.setText(description);
104+
itemView.setOnClickListener(this);
105+
}
99106

100-
return view;
107+
@Override
108+
public void onClick(View v) {
109+
itemView.getContext().startActivity(new Intent(itemView.getContext(), mStarterClass));
101110
}
102111
}
103112
}

app/src/main/res/layout/activity_chooser.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
android:paddingRight="@dimen/activity_horizontal_margin"
1010
android:paddingTop="@dimen/activity_vertical_margin">
1111

12-
<ListView
13-
android:id="@+id/list_view"
12+
<android.support.v7.widget.RecyclerView
13+
android:id="@+id/activities"
1414
android:layout_width="match_parent"
1515
android:layout_height="match_parent"/>
1616

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<android.support.v7.widget.CardView
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
xmlns:app="http://schemas.android.com/apk/res-auto"
5+
android:layout_width="wrap_content"
6+
android:layout_height="wrap_content"
7+
android:background="?android:attr/selectableItemBackground"
8+
app:cardCornerRadius="5dp"
9+
app:cardUseCompatPadding="true">
10+
11+
<RelativeLayout
12+
android:layout_width="match_parent"
13+
android:layout_height="wrap_content"
14+
android:layout_marginTop="8dp"
15+
android:layout_marginBottom="8dp"
16+
android:layout_marginStart="16dp"
17+
android:layout_marginEnd="16dp">
18+
19+
<TextView
20+
android:id="@+id/text1"
21+
android:layout_width="match_parent"
22+
android:layout_height="wrap_content"
23+
android:textAppearance="?android:attr/textAppearanceListItem"
24+
android:textIsSelectable="false"
25+
android:textStyle="bold"/>
26+
27+
<TextView
28+
android:id="@+id/text2"
29+
android:layout_width="match_parent"
30+
android:layout_height="wrap_content"
31+
android:layout_alignLeft="@id/text1"
32+
android:layout_alignStart="@id/text1"
33+
android:layout_below="@id/text1"
34+
android:textAppearance="?android:attr/textAppearanceListItem"
35+
android:textIsSelectable="false"/>
36+
37+
</RelativeLayout>
38+
39+
</android.support.v7.widget.CardView>

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

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
import java.util.Collections;
5656
import java.util.HashSet;
5757
import java.util.IdentityHashMap;
58-
import java.util.LinkedHashSet;
5958
import java.util.List;
6059
import java.util.Set;
6160

@@ -356,11 +355,33 @@ public void writeToParcel(Parcel parcel, int i) {
356355
parcel.writeStringList(mScopes);
357356
}
358357

358+
@Override
359+
public boolean equals(Object o) {
360+
if (this == o) return true;
361+
if (o == null || getClass() != o.getClass()) return false;
362+
363+
IdpConfig config = (IdpConfig) o;
364+
365+
return mProviderId.equals(config.mProviderId);
366+
}
367+
368+
@Override
369+
public int hashCode() {
370+
return mProviderId.hashCode();
371+
}
372+
373+
@Override
374+
public String toString() {
375+
return "IdpConfig{" +
376+
"mProviderId='" + mProviderId + '\'' +
377+
", mScopes=" + mScopes +
378+
'}';
379+
}
380+
359381
public static class Builder {
360382
private String mProviderId;
361383
private List<String> mScopes = new ArrayList<>();
362384

363-
364385
/**
365386
* Builds the configuration parameters for an identity provider.
366387
*
@@ -406,13 +427,12 @@ public IdpConfig build() {
406427
public final class SignInIntentBuilder {
407428
private int mLogo = NO_LOGO;
408429
private int mTheme = getDefaultTheme();
409-
private LinkedHashSet<IdpConfig> mProviders = new LinkedHashSet<>();
430+
private List<IdpConfig> mProviders = new ArrayList<>();
410431
private String mTosUrl;
411432
private boolean mIsSmartLockEnabled = true;
412433
private boolean mAllowNewEmailAccounts = true;
413434

414435
private SignInIntentBuilder() {
415-
mProviders.add(new IdpConfig.Builder(EMAIL_PROVIDER).build());
416436
}
417437

418438
/**
@@ -458,15 +478,14 @@ public SignInIntentBuilder setTosUrl(@Nullable String tosUrl) {
458478
*/
459479
public SignInIntentBuilder setProviders(@NonNull List<IdpConfig> idpConfigs) {
460480
mProviders.clear();
461-
Set<String> configuredProviders = new HashSet<>();
462-
for (IdpConfig idpConfig : idpConfigs) {
463-
if (configuredProviders.contains(idpConfig.getProviderId())) {
481+
for (IdpConfig config : idpConfigs) {
482+
if (mProviders.contains(config)) {
464483
throw new IllegalArgumentException("Each provider can only be set once. "
465-
+ idpConfig.getProviderId()
484+
+ config.getProviderId()
466485
+ " was set twice.");
486+
} else {
487+
mProviders.add(config);
467488
}
468-
configuredProviders.add(idpConfig.getProviderId());
469-
mProviders.add(idpConfig);
470489
}
471490
return this;
472491
}
@@ -495,6 +514,15 @@ public SignInIntentBuilder setProviders(@NonNull String... providers) {
495514
return this;
496515
}
497516

517+
private boolean isIdpAlreadyConfigured(@NonNull String providerId) {
518+
for (IdpConfig config : mProviders) {
519+
if (config.getProviderId().equals(providerId)) {
520+
return true;
521+
}
522+
}
523+
return false;
524+
}
525+
498526
/**
499527
* Enables or disables the use of Smart Lock for Passwords in the sign in flow.
500528
* <p>
@@ -515,23 +543,18 @@ public SignInIntentBuilder setAllowNewEmailAccounts(boolean enabled) {
515543
return this;
516544
}
517545

518-
private boolean isIdpAlreadyConfigured(@NonNull String providerId) {
519-
for (IdpConfig config : mProviders) {
520-
if (config.getProviderId().equals(providerId)) {
521-
return true;
522-
}
523-
}
524-
return false;
525-
}
526-
527546
public Intent build() {
528547
return KickoffActivity.createIntent(mApp.getApplicationContext(), getFlowParams());
529548
}
530549

531550
@VisibleForTesting()
532551
public FlowParameters getFlowParams() {
552+
if (mProviders.isEmpty()) {
553+
mProviders.add(new IdpConfig.Builder(EMAIL_PROVIDER).build());
554+
}
555+
533556
return new FlowParameters(mApp.getName(),
534-
new ArrayList<>(mProviders),
557+
mProviders,
535558
mTheme,
536559
mLogo,
537560
mTosUrl,

constants.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ project.ext {
1111
buildTools = '25.0.2'
1212

1313
firebaseVersion = '10.2.0'
14-
supportLibraryVersion = '25.1.1'
14+
supportLibraryVersion = '25.2.0'
1515
}

gradle/wrapper/gradle-wrapper.jar

0 Bytes
Binary file not shown.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Wed Jan 04 11:20:17 PST 2017
1+
#Tue Feb 21 17:40:47 PST 2017
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-3.4-all.zip

0 commit comments

Comments
 (0)