Skip to content

Fix filtering by Country name [SDK-2546] #623

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 2 commits into from
May 4, 2021
Merged

Fix filtering by Country name [SDK-2546] #623

merged 2 commits into from
May 4, 2021

Conversation

lbalmaceda
Copy link
Contributor

Changes

The filter was broken leading to an empty list of countries. This PR fixes the filter and makes the list display all the countries at first and then update as the search box changes.

Before:

Green Chicken

After:

Blue Sailfish

References

See SDK-2546

Testing

Manually tested, as seen on the gif.

@lbalmaceda lbalmaceda added CH: Fixed medium Medium review labels May 4, 2021
@lbalmaceda lbalmaceda added this to the Major - v3 milestone May 4, 2021
@lbalmaceda lbalmaceda requested a review from a team as a code owner May 4, 2021 11:46

private static final String TAG = LoadCountriesTask.class.getName();
public static final String COUNTRIES_JSON_FILE = "com_auth0_lock_passwordless_countries.json";

private final ThreadLocal<Context> context = new ThreadLocal<>();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this reference changed at some point, making the task not to execute at all. I'm passing this as a "task param" rather than via the constructor

codes = new Gson().fromJson(reader, mapType);
Log.d(TAG, String.format("Loaded %d countries", codes.size()));
} catch (IOException e) {
Log.e(TAG, "Failed to load the countries list from the JSON file", e);
}
return codes;
final ArrayList<String> names = new ArrayList<>(codes.keySet());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

including the sorting logic in the background task, returning a list of countries instead of a map of strings..

if (results.count > 0) {
notifyDataSetChanged();
} else {
notifyDataSetInvalidated();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

docs about this method say that once called, the adapter is no longer valid. https://developer.android.com/reference/android/widget/BaseAdapter#notifyDataSetInvalidated()

return;
}

final ArrayList<String> names = new ArrayList<>(result.keySet());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved into the task's responsibilities

@@ -133,7 +133,7 @@ In case you are not currently calling it, make sure to update your code adding t
```kotlin
class MyActivity : AppCompatActivity() {

private var lock: Lock? = null
private lateinit var lock: Lock
Copy link
Contributor Author

Choose a reason for hiding this comment

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

A simpler syntax for Android apps. "lateinit" means that the variable will be initialized later (e.g. in the on create method). Prevents us from asserting the null scenarios.

@lbalmaceda lbalmaceda merged commit 1ac4e4e into v3 May 4, 2021
@lbalmaceda lbalmaceda deleted the fix-country-list branch May 4, 2021 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CH: Fixed medium Medium review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants