8 private readonly TaskCompletionSource<ISO_3166_Country?> result =
new();
9 private CancellationTokenSource? cancellationTokenSource;
10 private bool isDisposed;
15 public Task<ISO_3166_Country?>
Result => this.result.Task;
24 this.InitializeComponent();
25 this.BindingContext =
this;
27 this.InnerSearchBar.Text =
string.Empty;
30 private void SearchBar_TextChanged(
object sender, TextChangedEventArgs e)
32 if (e.NewTextValue.Length == 0)
34 this.InnerListView.ItemsSource =
Countries;
38 if (this.cancellationTokenSource is not
null)
40 this.cancellationTokenSource.Cancel();
41 this.cancellationTokenSource =
null;
44 this.cancellationTokenSource =
new();
45 CancellationToken Token = this.cancellationTokenSource.Token;
49 IEnumerable<ISO_3166_Country> CountriesFiltered =
Countries.Where(el =>
51 bool Result = el.Name.Contains(e.NewTextValue, StringComparison.OrdinalIgnoreCase) ||
52 string.Equals(el.Alpha2, e.NewTextValue, StringComparison.OrdinalIgnoreCase) ||
53 string.Equals(el.Alpha3, e.NewTextValue, StringComparison.OrdinalIgnoreCase) ||
54 el.DialCode.Contains(e.NewTextValue, StringComparison.OrdinalIgnoreCase);
59 this.Dispatcher.Dispatch(() =>
61 if (!Token.IsCancellationRequested)
62 this.InnerListView.ItemsSource = CountriesFiltered;
67 private async
void InnerListView_SelectionChanged(
object sender, SelectionChangedEventArgs e)
70 await MopupService.Instance.PopAsync();
73 protected override void OnDisappearing()
75 this.result.TrySetResult(
null);
76 base.OnDisappearing();
79 protected virtual void Dispose(
bool disposing)
85 this.cancellationTokenSource?.Dispose();
86 this.cancellationTokenSource =
null;
89 this.isDisposed =
true;
100 GC.SuppressFinalize(
this);
Conversion between Country Names and ISO-3166-1 country codes.
static ISO_3166_Country[] Countries
This collection built from Wikipedia entry on ISO3166-1 on 9th Feb 2016
class ISO_3166_Country(string Name, string Alpha2, string Alpha3, int NumericCode, string DialCode, EmojiInfo? EmojiInfo=null)
Representation of an ISO3166-1 Country