-
Notifications
You must be signed in to change notification settings - Fork 82
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
Conversation
|
||
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<>(); |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
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:
After:
References
See SDK-2546
Testing
Manually tested, as seen on the gif.