Skip to content

Commit 87fd3bc

Browse files
SUPERCILEXsamtstern
authored andcommitted
Cleanup (#1038)
1 parent 5d3483b commit 87fd3bc

21 files changed

+250
-229
lines changed

auth/src/main/java/com/firebase/ui/auth/data/client/CountryListLoadTask.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ public interface Listener {
3636

3737
private static final int MAX_COUNTRIES = 291;
3838

39-
private final Listener listener;
39+
private final Listener mListener;
4040

4141
public CountryListLoadTask(Listener listener) {
42-
this.listener = listener;
42+
mListener = listener;
4343
}
4444

4545
@Override
@@ -297,8 +297,8 @@ protected List<CountryInfo> doInBackground(Void... params) {
297297

298298
@Override
299299
public void onPostExecute(List<CountryInfo> result) {
300-
if (listener != null) {
301-
listener.onLoadComplete(result);
300+
if (mListener != null) {
301+
mListener.onLoadComplete(result);
302302
}
303303
}
304304
}

auth/src/main/java/com/firebase/ui/auth/data/model/CountryInfo.java

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,15 @@
2222
import java.util.Locale;
2323

2424
public final class CountryInfo implements Comparable<CountryInfo> {
25-
private final Collator collator;
26-
public final Locale locale;
27-
public final int countryCode;
25+
private final Collator mCollator;
26+
private final Locale mLocale;
27+
private final int mCountryCode;
2828

2929
public CountryInfo(Locale locale, int countryCode) {
30-
collator = Collator.getInstance(Locale.getDefault());
31-
collator.setStrength(Collator.PRIMARY);
32-
33-
this.locale = locale;
34-
this.countryCode = countryCode;
30+
mCollator = Collator.getInstance(Locale.getDefault());
31+
mCollator.setStrength(Collator.PRIMARY);
32+
mLocale = locale;
33+
mCountryCode = countryCode;
3534
}
3635

3736
public static String localeToEmoji(Locale locale) {
@@ -48,31 +47,39 @@ public static String localeToEmoji(Locale locale) {
4847
(secondLetter));
4948
}
5049

50+
public Locale getLocale() {
51+
return mLocale;
52+
}
53+
54+
public int getCountryCode() {
55+
return mCountryCode;
56+
}
57+
5158
@Override
5259
public boolean equals(Object o) {
5360
if (this == o) return true;
5461
if (o == null || getClass() != o.getClass()) return false;
5562

5663
final CountryInfo that = (CountryInfo) o;
5764

58-
return countryCode == that.countryCode
59-
&& (locale != null ? locale.equals(that.locale) : that.locale == null);
65+
return mCountryCode == that.mCountryCode
66+
&& (mLocale != null ? mLocale.equals(that.mLocale) : that.mLocale == null);
6067
}
6168

6269
@Override
6370
public int hashCode() {
64-
int result = locale != null ? locale.hashCode() : 0;
65-
result = 31 * result + countryCode;
71+
int result = mLocale != null ? mLocale.hashCode() : 0;
72+
result = 31 * result + mCountryCode;
6673
return result;
6774
}
6875

6976
@Override
7077
public String toString() {
71-
return localeToEmoji(locale) + " " + locale.getDisplayCountry() + " +" + countryCode;
78+
return localeToEmoji(mLocale) + " " + mLocale.getDisplayCountry() + " +" + mCountryCode;
7279
}
7380

7481
@Override
7582
public int compareTo(CountryInfo info) {
76-
return collator.compare(locale.getDisplayCountry(), info.locale.getDisplayCountry());
83+
return mCollator.compare(mLocale.getDisplayCountry(), info.mLocale.getDisplayCountry());
7784
}
7885
}

auth/src/main/java/com/firebase/ui/auth/data/model/PhoneNumber.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222
public final class PhoneNumber {
2323
private static final PhoneNumber EMPTY_PHONE_NUMBER = new PhoneNumber("", "", "");
2424

25-
private final String phoneNumber;
26-
private final String countryIso;
27-
private final String countryCode;
25+
private final String mPhoneNumber;
26+
private final String mCountryIso;
27+
private final String mCountryCode;
2828

2929
public PhoneNumber(String phoneNumber, String countryIso, String countryCode) {
30-
this.phoneNumber = phoneNumber;
31-
this.countryIso = countryIso;
32-
this.countryCode = countryCode;
30+
mPhoneNumber = phoneNumber;
31+
mCountryIso = countryIso;
32+
mCountryCode = countryCode;
3333
}
3434

3535
/**
@@ -58,20 +58,20 @@ public static boolean isCountryValid(PhoneNumber phoneNumber) {
5858
* Returns country code
5959
*/
6060
public String getCountryCode() {
61-
return countryCode;
61+
return mCountryCode;
6262
}
6363

6464
/**
6565
* Returns phone number without country code
6666
*/
6767
public String getPhoneNumber() {
68-
return phoneNumber;
68+
return mPhoneNumber;
6969
}
7070

7171
/**
7272
* Returns 2 char country ISO
7373
*/
7474
public String getCountryIso() {
75-
return countryIso;
75+
return mCountryIso;
7676
}
7777
}

auth/src/main/java/com/firebase/ui/auth/data/model/User.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ public boolean equals(Object o) {
8888

8989
return mProviderId.equals(user.mProviderId)
9090
&& (mEmail == null ? user.mEmail == null : mEmail.equals(user.mEmail))
91+
&& (mPhoneNumber == null ? user.mPhoneNumber == null : mPhoneNumber.equals(user.mPhoneNumber))
9192
&& (mName == null ? user.mName == null : mName.equals(user.mName))
9293
&& (mPhotoUri == null ? user.mPhotoUri == null : mPhotoUri.equals(user.mPhotoUri));
9394
}
@@ -96,6 +97,7 @@ public boolean equals(Object o) {
9697
public int hashCode() {
9798
int result = mProviderId.hashCode();
9899
result = 31 * result + (mEmail == null ? 0 : mEmail.hashCode());
100+
result = 31 * result + (mPhoneNumber == null ? 0 : mPhoneNumber.hashCode());
99101
result = 31 * result + (mName == null ? 0 : mName.hashCode());
100102
result = 31 * result + (mPhotoUri == null ? 0 : mPhotoUri.hashCode());
101103
return result;
@@ -106,6 +108,7 @@ public String toString() {
106108
return "User{" +
107109
"mProviderId='" + mProviderId + '\'' +
108110
", mEmail='" + mEmail + '\'' +
111+
", mPhoneNumber='" + mPhoneNumber + '\'' +
109112
", mName='" + mName + '\'' +
110113
", mPhotoUri=" + mPhotoUri +
111114
'}';

auth/src/main/java/com/firebase/ui/auth/data/remote/ProfileMerger.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
public class ProfileMerger implements Continuation<AuthResult, Task<AuthResult>> {
2323
private static final String TAG = "ProfileMerger";
2424

25-
private final IdpResponse mIdpResponse;
25+
private final IdpResponse mResponse;
2626

2727
public ProfileMerger(IdpResponse response) {
28-
mIdpResponse = response;
28+
mResponse = response;
2929
}
3030

3131
@Override
@@ -39,7 +39,7 @@ public Task<AuthResult> then(@NonNull Task<AuthResult> task) {
3939
return Tasks.forResult(authResult);
4040
}
4141

42-
User user = mIdpResponse.getUser();
42+
User user = mResponse.getUser();
4343
if (TextUtils.isEmpty(name)) { name = user.getName(); }
4444
if (photoUri == null) { photoUri = user.getPhotoUri(); }
4545

auth/src/main/java/com/firebase/ui/auth/ui/email/RegisterEmailFragment.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,10 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
170170

171171
mActivity = (HelperActivityBase) getActivity();
172172
mSaveSmartLock = getAuthHelper().getSaveSmartLockInstance(mActivity);
173-
new PreambleHandler(getContext(), getFlowParams(), R.string.fui_button_text_save)
174-
.setPreamble(mAgreementText);
173+
PreambleHandler.setup(getContext(),
174+
getFlowParams(),
175+
R.string.fui_button_text_save,
176+
mAgreementText);
175177
}
176178

177179
@Override

auth/src/main/java/com/firebase/ui/auth/ui/phone/CountryListAdapter.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,15 @@ public void setData(List<CountryInfo> countries) {
4747
// Create index and add entries to adapter
4848
int index = 0;
4949
for (CountryInfo countryInfo : countries) {
50-
final String key = countryInfo.locale.getDisplayCountry().substring(0, 1).toUpperCase
51-
(Locale.getDefault());
50+
final String key = countryInfo.getLocale()
51+
.getDisplayCountry()
52+
.substring(0, 1)
53+
.toUpperCase(Locale.getDefault());
5254

5355
if (!alphaIndex.containsKey(key)) {
5456
alphaIndex.put(key, index);
5557
}
56-
countryPosition.put(countryInfo.locale.getDisplayCountry(), index);
58+
countryPosition.put(countryInfo.getLocale().getDisplayCountry(), index);
5759

5860
index++;
5961
add(countryInfo);

auth/src/main/java/com/firebase/ui/auth/ui/phone/CountryListSpinner.java

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@
3737

3838
public final class CountryListSpinner extends AppCompatEditText implements
3939
View.OnClickListener, CountryListLoadTask.Listener {
40-
private String textFormat;
41-
private DialogPopup dialogPopup;
42-
private CountryListAdapter countryListAdapter;
43-
private OnClickListener listener;
44-
private String selectedCountryName;
40+
private final String mTextFormat;
41+
private final DialogPopup mDialogPopup;
42+
private final CountryListAdapter mCountryListAdapter;
43+
private OnClickListener mListener;
44+
private String mSelectedCountryName;
4545

4646
public CountryListSpinner(Context context) {
4747
this(context, null, android.R.attr.spinnerStyle);
@@ -53,8 +53,14 @@ public CountryListSpinner(Context context, AttributeSet attrs) {
5353

5454
public CountryListSpinner(Context context, AttributeSet attrs, int defStyle) {
5555
super(context, attrs, defStyle);
56+
super.setOnClickListener(this);
5657

57-
init();
58+
mCountryListAdapter = new CountryListAdapter(getContext());
59+
mDialogPopup = new DialogPopup(mCountryListAdapter);
60+
mTextFormat = "%1$s +%2$d";
61+
mSelectedCountryName = "";
62+
CountryInfo countryInfo = PhoneNumberUtils.getCurrentCountryInfo(getContext());
63+
setSpinnerText(countryInfo.getCountryCode(), countryInfo.getLocale());
5864
}
5965

6066
private static void hideKeyboard(Context context, View view) {
@@ -64,26 +70,15 @@ private static void hideKeyboard(Context context, View view) {
6470
}
6571
}
6672

67-
private void init() {
68-
super.setOnClickListener(this);
69-
70-
countryListAdapter = new CountryListAdapter(getContext());
71-
dialogPopup = new DialogPopup(countryListAdapter);
72-
textFormat = "%1$s +%2$d";
73-
selectedCountryName = "";
74-
final CountryInfo countryInfo = PhoneNumberUtils.getCurrentCountryInfo(getContext());
75-
setSpinnerText(countryInfo.countryCode, countryInfo.locale);
76-
}
77-
7873
private void setSpinnerText(int countryCode, Locale locale) {
79-
setText(String.format(textFormat, CountryInfo.localeToEmoji(locale), countryCode));
74+
setText(String.format(mTextFormat, CountryInfo.localeToEmoji(locale), countryCode));
8075
setTag(new CountryInfo(locale, countryCode));
8176
}
8277

8378
public void setSelectedForCountry(final Locale locale, String countryCode) {
8479
final String countryName = locale.getDisplayName();
8580
if (!TextUtils.isEmpty(countryName) && !TextUtils.isEmpty(countryCode)) {
86-
selectedCountryName = countryName;
81+
mSelectedCountryName = countryName;
8782
setSpinnerText(Integer.parseInt(countryCode), locale);
8883
}
8984
}
@@ -92,24 +87,24 @@ public void setSelectedForCountry(final Locale locale, String countryCode) {
9287
protected void onDetachedFromWindow() {
9388
super.onDetachedFromWindow();
9489

95-
if (dialogPopup.isShowing()) {
96-
dialogPopup.dismiss();
90+
if (mDialogPopup.isShowing()) {
91+
mDialogPopup.dismiss();
9792
}
9893
}
9994

10095
@Override
10196
public void setOnClickListener(OnClickListener l) {
102-
listener = l;
97+
mListener = l;
10398
}
10499

105100
@Override
106101
public void onClick(View view) {
107-
if (countryListAdapter.getCount() == 0) {
102+
if (mCountryListAdapter.getCount() == 0) {
108103
loadCountryList();
109104
} else {
110-
dialogPopup.show(countryListAdapter.getPositionForCountry(selectedCountryName));
105+
mDialogPopup.show(mCountryListAdapter.getPositionForCountry(mSelectedCountryName));
111106
}
112-
hideKeyboard(getContext(), CountryListSpinner.this);
107+
hideKeyboard(getContext(), this);
113108
executeUserClickListener(view);
114109
}
115110

@@ -118,15 +113,15 @@ private void loadCountryList() {
118113
}
119114

120115
private void executeUserClickListener(View view) {
121-
if (listener != null) {
122-
listener.onClick(view);
116+
if (mListener != null) {
117+
mListener.onClick(view);
123118
}
124119
}
125120

126121
@Override
127122
public void onLoadComplete(List<CountryInfo> result) {
128-
countryListAdapter.setData(result);
129-
dialogPopup.show(countryListAdapter.getPositionForCountry(selectedCountryName));
123+
mCountryListAdapter.setData(result);
124+
mDialogPopup.show(mCountryListAdapter.getPositionForCountry(mSelectedCountryName));
130125
}
131126

132127
public class DialogPopup implements DialogInterface.OnClickListener {
@@ -173,8 +168,8 @@ public void run() {
173168
@Override
174169
public void onClick(DialogInterface dialog, int which) {
175170
final CountryInfo countryInfo = listAdapter.getItem(which);
176-
selectedCountryName = countryInfo.locale.getDisplayCountry();
177-
setSpinnerText(countryInfo.countryCode, countryInfo.locale);
171+
mSelectedCountryName = countryInfo.getLocale().getDisplayCountry();
172+
setSpinnerText(countryInfo.getCountryCode(), countryInfo.getLocale());
178173
dismiss();
179174
}
180175
}

0 commit comments

Comments
 (0)