Skip to content

Include/exclude countries from the country selector list in phone authentication #1315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
May 30, 2018

Conversation

lsirac
Copy link
Contributor

@lsirac lsirac commented May 24, 2018

No description provided.

@lsirac lsirac requested review from samtstern and SUPERCILEX May 24, 2018 23:46
@lsirac lsirac changed the base branch from master to version-4.1.0-dev May 24, 2018 23:46
}

@Override
protected List<CountryInfo> doInBackground(Void... params) {
final List<CountryInfo> countryInfoList = new ArrayList<>(MAX_COUNTRIES);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SUPERCILEX I rememeber last time you touched this code you had a reason to keep this list separate from the map in PhoneNumberUtils. Is it not exactly inverted?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lsirac btw holding my approval on this discussion.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I went through and actually just printed out the map in each case. And there is no diff in the map information:
http://www.mergely.com/MhLwmZdA/

Collections.sort(countryInfoList);
return countryInfoList;
}

public List<CountryInfo> getAvailableCountryCodes() {
Map<String, Integer> countryInfoMap = PhoneNumberUtils.getImmutableCountryCodeMap();
if (whitelistedCountryCodes == null && blacklistedCountryCodes == null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if you want this to be the default you should do this in the constructor and then let every other method in the class assume that the whitelist and blacklist are setup properly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might also want to throw an IllegalStateException in the constructor if they're both non-null.

Copy link
Contributor Author

@lsirac lsirac May 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if I agree with adding an IllegalStateException. I moved that bit to the constructor though.

if (whitelistedCountryCodes == null) {
excludedCountries.addAll(blacklistedCountryCodes);
} else {
excludedCountries.addAll(countryInfoMap.keySet());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add some comments here, as the assumptions took me a minute to wrap my head around (I think you're saying that at this point you know only one of whitelist or blacklist will be non-null so you're just handling the two cases for whitelist and assuming the opposite about blacklist)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Collections.sort(countryInfoList);
return countryInfoList;
}

public List<CountryInfo> getAvailableCountryCodes() {
Map<String, Integer> countryInfoMap = PhoneNumberUtils.getImmutableCountryCodeMap();
if (whitelistedCountryCodes == null && blacklistedCountryCodes == null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might also want to throw an IllegalStateException in the constructor if they're both non-null.

@@ -134,6 +135,8 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
// It is assumed that the phone number that are being wired in via Credential Selector
// are e164 since we store it.
Bundle params = getArguments().getBundle(ExtraConstants.PARAMS);
List<String> whitelistedCountryCodes = null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these two variables are not used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed them in my last commit.

Bundle params = getArguments().getBundle(ExtraConstants.PARAMS);
if (params != null) {
mCountryListSpinner.setWhitelistedCountryCodes(
params.getStringArrayList(ExtraConstants.WHITELISTED_COUNTRY_CODES));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the default for getStringArrayList, is it null?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it returns null if the key isn't present.

@samtstern
Copy link
Contributor

@lsirac as we talked about in chat, let's use Isos in the method names and remove PhoneAuth from them since that's implied by the PhoneBuilder bit.

@samtstern samtstern modified the milestones: 4.0.1, 4.1.0 May 29, 2018
@samtstern
Copy link
Contributor

I just took a look and, amazingly, it doesn't look like this will create any conflicts with #1253

mListener = listener;
countryInfoMap = PhoneNumberUtils.getImmutableCountryIsoMap();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lsirac would it mess you up if this work was moved to doInBackground? I think originally there was a concern that the construction of this map was expensive enough to be done in the background (motivates the whole existence of this class).

If you can move it to there, then I am confident this is a safe change.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking around, I think that just means you will want to lazy-initialize the big static members of PhoneNumberUtils and expose getters for them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@samtstern samtstern merged commit fd99883 into version-4.1.0-dev May 30, 2018
@lsirac lsirac deleted the country-codes branch May 30, 2018 00:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants