Skip to content

switch to libphonenumber for country list and prefixes #61

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Signal-Windows/ViewModels/AddContactPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ internal async void PickButton_Click(object sender, RoutedEventArgs e)
if (originalNumber[0] != '+')
{
// need a better way of determining the "default" country code here
var formattedPhoneNumber = PhoneNumberFormatter.formatE164("1", originalNumber);
var formattedPhoneNumber = PhoneNumberFormatter.FormatE164("1", originalNumber);
if (string.IsNullOrEmpty(formattedPhoneNumber))
{
ContactNumber = originalNumber;
Expand Down
33 changes: 27 additions & 6 deletions Signal-Windows/ViewModels/RegisterPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
using Windows.UI.Core;
using libsignalservice.util;
using Windows.UI.Popups;
using PhoneNumbers;

namespace Signal_Windows.ViewModels
{
public class RegisterPageViewModel : ViewModelBase
{
public CancellationTokenSource CancelSource = new CancellationTokenSource();
public IEnumerable<string> CountriesList { get; set; } = CountryArrays.Names;
public List<string> CountriesList { get; set; } = new List<string>(250);
private List<int> CountriesPrefixList { get; set; } = new List<int>(250);
public RegisterPage View { get; set; }
public string FinalNumber { get; set; }
private string _PhonePrefix { get; set; }
Expand All @@ -35,12 +37,29 @@ public string PhonePrefix
}
}

public RegisterPageViewModel()
{
HashSet<string> set = PhoneNumberUtil.GetInstance().GetSupportedRegions();
var phoneUtil = PhoneNumberUtil.GetInstance();
foreach (var region in set)
{
if(region != "AC" && region != "SX" && region != "CW" && region != "BQ" && region != "TA" && region != "SS")
{
string s = new Locale("en", region).GetDisplayCountry("en");
int prefix = phoneUtil.GetCountryCodeForRegion(region);
CountriesList.Add(s);
CountriesPrefixList.Add(prefix);
}
}
}

internal void RegisterPage_Loaded()
{
var c = Windows.System.UserProfile.GlobalizationPreferences.HomeGeographicRegion;
for (int i = 0; i < CountryArrays.Abbreviations.Length; i++)
for (int i=0;i<CountriesPrefixList.Count;i++)
{
if (CountryArrays.Abbreviations[i] == c)
int prefix = CountriesPrefixList[i];
if (prefix == PhoneNumberUtil.GetInstance().GetCountryCodeForRegion(c))
{
View.SetCountry(i);
}
Expand All @@ -65,7 +84,7 @@ public void RegisterButton_Click()
{
try
{
string number = PhoneNumberFormatter.formatE164(PhonePrefix, PhoneSuffix);
string number = PhoneNumberFormatter.FormatE164(PhonePrefix, PhoneSuffix);
if(number != null && number.Length > 0 && number[0] == '+')
{
FinalNumber = number;
Expand Down Expand Up @@ -104,8 +123,10 @@ private void BackButton_Click(object sender, BackRequestedEventArgs e)

public void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
int index = (sender as ComboBox).SelectedIndex;
PhonePrefix = Utils.GetCountryCode(CountryArrays.Abbreviations[index]);
ComboBox dropdown = (ComboBox)sender;
string region = (string)dropdown.SelectedItem;
int prefix = CountriesPrefixList[dropdown.SelectedIndex];
PhonePrefix = "+" + prefix;
}
}
}
2 changes: 1 addition & 1 deletion Signal-Windows/project.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"dependencies": {
"libsignal-service-dotnet": "1.5.6",
"libsignal-service-dotnet": "1.5.6.1",
"Microsoft.EntityFrameworkCore": "1.1.2",
"Microsoft.EntityFrameworkCore.Design": "1.1.2",
"Microsoft.EntityFrameworkCore.Sqlite": "1.1.2",
Expand Down