public Code(Service service, TabbedPage tabs) { _service = service; _label = new Label(); _label.Font = Font.SystemFontOfSize(18); _label.XAlign = TextAlignment.Center; _label2 = new Label(); _label2.Font = Font.SystemFontOfSize(18); _label2.XAlign = TextAlignment.Center; _label2.TextColor = Color.Red; CodeSent = CodeSent; // set the labels _code = new Entry(); _code.Placeholder = Localize.GetString("TelegramCode"); _submit = new Button(); _submit.Text = Localize.GetString("TelegramSubmit"); _submit.TextColor = Color.White; _submit.BackgroundColor = Color.FromHex("77D065"); _submit.Clicked += async(sender, e) => { Func <Task> invalidCode = () => { return(DisplayAlert(Localize.GetString("TelegramCodeInvalidTitle"), Localize.GetString("TelegramCodeInvalidMessage"), Localize.GetString("TelegramOkay"))); }; if (String.IsNullOrWhiteSpace(_code.Text)) { await invalidCode(); return; } var code = new string(_code.Text.Where(Char.IsDigit).ToArray()); if (String.IsNullOrWhiteSpace(code)) { await invalidCode(); return; } _progressBar.IsVisible = true; _error.IsVisible = false; DependencyService.Get <IPluginPageControls>().BackPressEnabled = false; _code.IsEnabled = false; _submit.IsEnabled = false; tabs.IsEnabled = false; var result = await Register(code); DependencyService.Get <IPluginPageControls>().BackPressEnabled = true; _code.IsEnabled = true; _submit.IsEnabled = true; tabs.IsEnabled = true; _progressBar.IsVisible = false; if (!result.Success) { _error.IsVisible = true; _error.Text = result.ErrorMessage; return; } Save(service, result.AccountId, GetSettingsTelegramSettings()); DependencyService.Get <IPluginPageControls>().Finish(); }; _progressBar = new ActivityIndicator(); _progressBar.VerticalOptions = LayoutOptions.EndAndExpand; _progressBar.IsRunning = true; _progressBar.IsVisible = false; _error = new Label(); _error.VerticalOptions = LayoutOptions.EndAndExpand; _error.IsVisible = false; _error.Font = Font.SystemFontOfSize(18); _error.XAlign = TextAlignment.Center; _error.TextColor = Color.Red; var stackLayout = new StackLayout(); stackLayout.Spacing = 20; stackLayout.Padding = 25; stackLayout.VerticalOptions = LayoutOptions.Start; var children = stackLayout.Children; children.Add(_label); children.Add(_label2); children.Add(_code); children.Add(_submit); children.Add(_progressBar); children.Add(_error); Content = new ScrollView { Content = stackLayout }; Title = Localize.GetString("TelegramCodeTitle"); }
private Task <ActivationResult> Register(string code) { return(Task <ActivationResult> .Factory.StartNew(() => { var result = Telegram.RegisterCode(_service, GetSettingsTelegramSettings(), CountryCode + NationalNumber, GetSettingsCodeHash(), code, FirstName, LastName, GetSettingsRegistered()); if (result == null) { return new ActivationResult { Success = false, ErrorMessage = Localize.GetString("TelegramCodeError") }; } if (result.Response != Telegram.CodeRegister.Type.Success) { string errorMessage = null; switch (result.Response) { case Telegram.CodeRegister.Type.NumberInvalid: errorMessage = Localize.GetString("TelegramCodeNumberInvalid"); break; case Telegram.CodeRegister.Type.CodeEmpty: errorMessage = Localize.GetString("TelegramCodeInvalidMessage"); break; case Telegram.CodeRegister.Type.CodeExpired: errorMessage = Localize.GetString("TelegramCodeCodeExpired"); break; case Telegram.CodeRegister.Type.CodeInvalid: errorMessage = Localize.GetString("TelegramCodeCodeInvalid"); break; case Telegram.CodeRegister.Type.FirstNameInvalid: errorMessage = Localize.GetString("TelegramCodeFirstNameInvalid"); break; case Telegram.CodeRegister.Type.LastNameInvalid: errorMessage = Localize.GetString("TelegramCodeLastNameInvalid"); break; default: errorMessage = Localize.GetString("TelegramCodeError"); break; } return new ActivationResult { Success = false, ErrorMessage = errorMessage }; } return new ActivationResult { Success = true, AccountId = result.AccountId, }; })); }
private Task <ActivationResult> DoVerify(VerificationOption option) { return(Task <ActivationResult> .Factory.StartNew(() => { var settings = GetSettingsTelegramSettings(); var response = Telegram.RequestCode(_service, CountryCode + NationalNumber, GetSettingsCodeHash(), GetSettingsTelegramSettings(), option == VerificationOption.Voice); if (response.Response == Telegram.CodeRequest.Type.Migrate) { TelegramSettings newSettings; using (var migratedClient = Telegram.GetNewClient(response.MigrateId, GetSettingsTelegramSettings(), out newSettings)) { TelegramUtils.RunSynchronously(migratedClient.Connect()); response = Telegram.RequestCode(_service, CountryCode + NationalNumber, GetSettingsCodeHash(), newSettings, option == VerificationOption.Voice); Utils.DebugPrint(">>>>> Response from the server " + ObjectDumper.Dump(response)); if (option == VerificationOption.Sms) { SetSettingsSettings(newSettings, false); SetSettingsCodeHash(response.CodeHash, false); SetSettingsRegistered(response.Registered, false); } return new ActivationResult { Success = true, }; } } if (response == null || response.Response != Telegram.CodeRequest.Type.Success) { var message = Localize.GetString("TelegramVerifyError"); if (response != null) { if (response.Response == Telegram.CodeRequest.Type.NumberInvalid) { message = Localize.GetString("TelegramVerifyInvalidNumber"); } } return new ActivationResult { Success = false, ErrorMessage = message, }; } if (option == VerificationOption.Sms) { SetSettingsCodeHash(response.CodeHash, true); SetSettingsRegistered(response.Registered, true); } return new ActivationResult { Success = true }; })); }
public Verify(Service service, TabbedPage tabs, Code code) { _service = service; _info = new Label(); _info.Text = Localize.GetString("TelegramVerifyQuestion"); _info.Font = Font.SystemFontOfSize(18); _info.XAlign = TextAlignment.Center; Action <bool, Action> doVerify = async(viaSms, postAction) => { _error.IsVisible = false; _progressBar.IsVisible = true; DependencyService.Get <IPluginPageControls>().BackPressEnabled = false; _verifyPhone.IsEnabled = false; _verifySms.IsEnabled = false; _haveCode.IsEnabled = false; tabs.IsEnabled = false; var result = await DoVerify(viaSms? VerificationOption.Sms : VerificationOption.Voice); DependencyService.Get <IPluginPageControls>().BackPressEnabled = true; _verifyPhone.IsEnabled = true; _verifySms.IsEnabled = true; _haveCode.IsEnabled = true; tabs.IsEnabled = true; _progressBar.IsVisible = false; if (postAction != null) { postAction(); } if (!result.Success) { _error.IsVisible = true; _error.Text = result.ErrorMessage; return; } code.CountryCode = CountryCode; code.NationalNumber = NationalNumber; code.FirstName = FirstName; code.LastName = LastName; code.ViaSms = viaSms; code.CodeSent = true; tabs.Children.Add(code); tabs.CurrentPage = code; }; _verifySms = new Button(); _verifySms.Text = Localize.GetString("TelegramVerifyViaSms"); _verifySms.TextColor = Color.White; _verifySms.BackgroundColor = Color.FromHex("77D065"); _verifySms.Clicked += (sender, e) => { doVerify(true, SetVerifyPhoneState); }; _verifyPhone = new Button(); _verifyPhone.Text = Localize.GetString("TelegramVerifyViaPhone"); _verifyPhone.TextColor = Color.White; _verifyPhone.Clicked += (sender, e) => { doVerify(false, null); }; _progressBar = new ActivityIndicator(); _progressBar.VerticalOptions = LayoutOptions.CenterAndExpand; _progressBar.IsRunning = true; _progressBar.IsVisible = false; _error = new Label(); _error.VerticalOptions = LayoutOptions.CenterAndExpand; _error.IsVisible = false; _error.Font = Font.SystemFontOfSize(18); _error.XAlign = TextAlignment.Center; _error.TextColor = Color.Red; _haveCode = new Button(); _haveCode.VerticalOptions = LayoutOptions.EndAndExpand; _haveCode.Text = Localize.GetString("TelegramVerifyHaveCode"); _haveCode.TextColor = Color.White; _haveCode.BackgroundColor = Color.FromHex("c50923"); _haveCode.Clicked += (sender, e) => { code.CountryCode = CountryCode; code.NationalNumber = NationalNumber; code.FirstName = FirstName; code.LastName = LastName; code.ViaSms = true; code.CodeSent = false; tabs.Children.Add(code); tabs.CurrentPage = code; }; var stackLayout = new StackLayout(); stackLayout.Spacing = 20; stackLayout.Padding = 25; stackLayout.VerticalOptions = LayoutOptions.FillAndExpand; var children = stackLayout.Children; children.Add(_info); children.Add(_verifySms); children.Add(_verifyPhone); children.Add(_progressBar); children.Add(_error); children.Add(_haveCode); Content = new ScrollView { Content = stackLayout }; Title = Localize.GetString("TelegramVerificationTitle"); }
public Info(Service service, TabbedPage tabs, Verify verify) { _phoneNumberContainer = new StackLayout(); _phoneNumberContainer.Orientation = StackOrientation.Horizontal; _phoneNumberContainer.HorizontalOptions = LayoutOptions.FillAndExpand; _phoneNumber = new PhoneEntry(); _phoneNumber.Placeholder = Localize.GetString("TelegramPhoneNumber"); _phoneNumber.HorizontalOptions = LayoutOptions.FillAndExpand; _phoneNumberContainer.Children.Add(_phoneNumber); var programmaticChange = false; _firstName = new Entry(); _firstName.Placeholder = Localize.GetString("TelegramFirstName"); _lastName = new Entry(); _lastName.Placeholder = Localize.GetString("TelegramLastName"); _loadConversationsLayout = new StackLayout(); _loadConversationsLayout.Orientation = StackOrientation.Horizontal; _loadConversationsLayout.HorizontalOptions = LayoutOptions.End; _loadConversationsLayout.Padding = new Thickness(15, 0); _loadConversationsLayout.Spacing = 10; _loadConversationsTitle = new Label(); _loadConversationsTitle.Text = Localize.GetString("TelegramLoadConversations"); _loadConversationsSwitch = new Switch(); _loadConversationsSwitch.Toggled += (sender, e) => { (service as Telegram).LoadConversations = e.Value; }; _loadConversationsSwitch.IsToggled = true; _loadConversationsLayout.Children.Add(_loadConversationsTitle); _loadConversationsLayout.Children.Add(_loadConversationsSwitch); _next = new Button(); _next.HorizontalOptions = LayoutOptions.FillAndExpand; _next.Text = Localize.GetString("TelegramNext"); _next.TextColor = Color.White; _next.BackgroundColor = Color.FromHex("77D065"); _next.Clicked += async(sender, e) => { if (String.IsNullOrWhiteSpace(_firstName.Text)) { await DisplayAlert(Localize.GetString("TelegramInvalidFirstNameTitle"), Localize.GetString("TelegramInvalidFirstNameMessage"), Localize.GetString("TelegramOkay")); return; } if (String.IsNullOrWhiteSpace(_lastName.Text)) { await DisplayAlert(Localize.GetString("TelegramInvalidLastNameTitle"), Localize.GetString("TelegramInvalidLastNameMessage"), Localize.GetString("TelegramOkay")); return; } Func <Task> invalidNumber = () => { return(DisplayAlert(Localize.GetString("TelegramInvalidNumberTitle"), Localize.GetString("TelegramInvalidNumberMessage"), Localize.GetString("TelegramOkay"))); }; if (!PhoneBook.IsPossibleNumber(_phoneNumber.Text)) { await invalidNumber(); return; } var number = PhoneBook.TryGetPhoneNumberLegible(_phoneNumber.Text); var formattedNumber = PhoneBook.FormatPhoneNumber(number); if (formattedNumber == null) { await invalidNumber(); return; } var nationalNumber = new string(formattedNumber.Item2.Where(Char.IsDigit).ToArray()); if (!await DisplayAlert(Localize.GetString("TelegramConfirmNumberTitle"), Localize.GetString("TelegramConfirmNumberMessage").Replace("[number]", number), Localize.GetString("TelegramYes"), Localize.GetString("TelegramNo"))) { return; } _progressBar.IsVisible = true; _next.IsEnabled = false; _firstName.IsEnabled = false; _lastName.IsEnabled = false; _phoneNumber.IsEnabled = false; DependencyService.Get <IPluginPageControls>().BackPressEnabled = false; TelegramSettings settings = null; var skipSave = false; var state = _settings.States.FirstOrDefault(x => x.NationalNumber == nationalNumber); if (state != null && state.Settings != null) { skipSave = true; settings = state.Settings; } else { settings = await Task <TelegramSettings> .Factory.StartNew(() => { return(Telegram.GenerateAuthentication(service)); }); } var firstName = _firstName.Text.Trim(); var lastName = _lastName.Text.Trim(); DependencyService.Get <IPluginPageControls>().BackPressEnabled = true; _firstName.IsEnabled = true; _lastName.IsEnabled = true; _phoneNumber.IsEnabled = true; _next.IsEnabled = true; _progressBar.IsVisible = false; if (settings == null) { await DisplayAlert(Localize.GetString("TelegramAuthGenerationFailedTitle"), Localize.GetString("TelegramAuthGenerationFailedMessage"), Localize.GetString("TelegramOkay")); return; } if (!skipSave) { _settings.States.Add(new Setup.TelegramSetupSettings.State { Settings = settings, NationalNumber = nationalNumber }); SaveSettings(); } verify.CountryCode = formattedNumber.Item1; verify.NationalNumber = nationalNumber; verify.FirstName = firstName; verify.LastName = lastName; tabs.Children.Add(verify); tabs.CurrentPage = verify; }; _image = new Image(); _image.Source = ImageSource.FromUri( new Uri("https://lh4.ggpht.com/fuvTtxbZ1-dkEmzUMfKcgMJwW8PyY4fhJJ_NKT-NpIQJukszEY2GfCkJUF5ch6Co3w=w300")); _image.WidthRequest = 100; _image.HeightRequest = 100; _progressBar = new ActivityIndicator(); _progressBar.VerticalOptions = LayoutOptions.EndAndExpand; _progressBar.IsRunning = true; _progressBar.IsVisible = false; var stackLayout = new StackLayout(); stackLayout.Spacing = 20; stackLayout.Padding = 25; stackLayout.VerticalOptions = LayoutOptions.Start; var children = stackLayout.Children; children.Add(_image); children.Add(_firstName); children.Add(_lastName); children.Add(_phoneNumberContainer); children.Add(_loadConversationsLayout); var nextLayout = new StackLayout(); nextLayout.Spacing = 20; nextLayout.Orientation = StackOrientation.Horizontal; nextLayout.Children.Add(_next); nextLayout.Children.Add(_progressBar); children.Add(nextLayout); Content = new ScrollView { Content = stackLayout }; Title = Localize.GetString("TelegramInformationTitle"); }
public Main(Service service) { var running = ServiceManager.IsRunning(service); var internetConnected = Platform.HasInternetConnection(); _status = new Label(); if (running) { _status.Text = Localize.GetString("TelegramRunning"); _status.TextColor = Color.Green; } else { _status.Text = Localize.GetString("TelegramNotRunning"); _status.TextColor = Color.Red; } _status.Font = Font.SystemFontOfSize(20); _status.XAlign = TextAlignment.Center; _info = new Label(); if (running) { _info.Text = Localize.GetString("TelegramAllGood"); } else { if (internetConnected) { _info.Text = Localize.GetString("TelegramPleaseStart"); } else { _info.Text = Localize.GetString("TelegramPleaseStartNoInternet"); } } _info.Font = Font.SystemFontOfSize(16); _info.XAlign = TextAlignment.Center; _toolsLayout = new StackLayout(); _toolsLayout.Orientation = StackOrientation.Vertical; _toolsLayout.VerticalOptions = LayoutOptions.EndAndExpand; _toolsLayout.Spacing = 10; _setupWizard = new Button(); _setupWizard.Text = Localize.GetString("TelegramSetupWizard"); _setupWizard.TextColor = Color.White; _setupWizard.BackgroundColor = Color.FromHex("c50923"); _setupWizard.Clicked += async(sender, e) => { await Navigation.PushAsync(Setup.Fetch(service)); }; if (running) { _profileSettings = new Button(); _profileSettings.Text = Localize.GetString("TelegramProfileSettings"); _profileSettings.TextColor = Color.White; _profileSettings.BackgroundColor = Color.FromHex("77D065"); _profileSettings.Clicked += async(sender, e) => { //await Navigation.PushAsync(new ProfileSettings(service)); }; _toolsLayout.Children.Add(_profileSettings); } _toolsLayout.Children.Add(_setupWizard); var stackLayout = new StackLayout(); stackLayout.Spacing = 10; stackLayout.Padding = 25; stackLayout.VerticalOptions = LayoutOptions.FillAndExpand; var children = stackLayout.Children; children.Add(_status); children.Add(_info); children.Add(_toolsLayout); Content = new ScrollView { Content = stackLayout }; Title = Localize.GetString("TelegramSettingsTitle"); }