public override async void OnCreatePreferences(Bundle savedInstanceState, string rootKey) { AddPreferencesFromResource(Resource.Xml.preferences); allLangs = (await LanguageChoiceManager.GetLanguageChoices()).OrderBy((lang) => lang.Code).ToList(); string[] langIds = allLangs.Select((lang) => lang.Id.ToString()).ToArray(); string[] langNames = allLangs.Select((lang) => lang.Endonym).ToArray(); CultureInfo currentCulture = StringResources.Culture ?? Localise.GetCurrentCultureInfo(); int appCurrentLangVal = allLangs.FindIndex((obj) => obj.Code == currentCulture.TwoLetterISOLanguageName); if (appCurrentLangVal == -1) { appCurrentLangVal = 1; } ListPreference appLangPref = (ListPreference)FindPreference("appLanguagePref"); appLangPref.Title = StringResources.settings_chooseAppLanguage; appLangPref.SetEntries(langNames); appLangPref.SetEntryValues(langIds); appLangPref.SetValueIndex(appCurrentLangVal); appLangPref.PreferenceChange += AppLangPrefChanged; int convoDefaultVal = allLangs.FindIndex((obj) => obj.Id == Session.ActiveUser.Lang); ListPreference convoLangPref = (ListPreference)FindPreference("convoLanguagePref"); convoLangPref.Title = StringResources.settings_chooseConvoLanguage; convoLangPref.SetEntries(langNames); convoLangPref.SetEntryValues(langIds); convoLangPref.SetValueIndex(convoDefaultVal); convoLangPref.PreferenceChange += ConvoLangPrefChanged; Preference logOutPref = FindPreference("logOutPref"); logOutPref.Title = StringResources.settings_logout; logOutPref.PreferenceClick += LogOutPref_PreferenceClick; }
private async void Submit_Click(object sender, System.EventArgs e) { AppCompatEditText fname = FindViewById <AppCompatEditText>(Resource.Id.name); AppCompatEditText email = FindViewById <AppCompatEditText>(Resource.Id.email); AppCompatEditText passw = FindViewById <AppCompatEditText>(Resource.Id.password); AppCompatEditText confPass = FindViewById <AppCompatEditText>(Resource.Id.confirmPassword); if (string.IsNullOrWhiteSpace(fname.Text)) { fname.Error = StringResources.register_ui_fullname_validate_empty; fname.RequestFocus(); } else if (string.IsNullOrWhiteSpace(email.Text)) { email.Error = StringResources.common_ui_forms_email_validate_empty; email.RequestFocus(); } else if (string.IsNullOrWhiteSpace(passw.Text)) { passw.Error = StringResources.common_ui_forms_password_validate_empty; passw.RequestFocus(); } else if (passw.Text != confPass.Text) { confPass.Error = StringResources.common_ui_forms_password_validate_mismatch; confPass.RequestFocus(); } else if (!Android.Util.Patterns.EmailAddress.Matcher(email.Text).Matches()) { email.Error = StringResources.common_ui_forms_email_validate_invalid; email.RequestFocus(); } else if (string.IsNullOrWhiteSpace(selectedLanguage) || selectedLanguage == StringResources.common_ui_forms_language_default) { new Android.Support.V7.App.AlertDialog.Builder(this) .SetMessage(StringResources.common_ui_forms_language_error) .SetPositiveButton(StringResources.common_comms_ok, (a, b) => { }) .Show(); } else { FindViewById <RelativeLayout>(Resource.Id.loadingLayout).Visibility = ViewStates.Visible; FindViewById <AppCompatButton>(Resource.Id.submit).Enabled = false; LanguageChoice chosenLang = languageChoices.FirstOrDefault((arg) => arg.Endonym == selectedLanguage); LOG_EVENT_WITH_ACTION("REGISTER", "ATTEMPT"); CultureInfo currentCulture = StringResources.Culture ?? Localise.GetCurrentCultureInfo(); string currentLang = currentCulture.TwoLetterISOLanguageName; LanguageChoice matchingLanguage = await LanguageChoiceManager.GetLanguageFromCode(currentLang); //default to English at registration if no matching language int langId = (matchingLanguage != null)? matchingLanguage.Id : 1; var response = await RestClient.Register(fname.Text, email.Text.ToLower(), passw.Text, langId); if (response.Meta.Success) { LOG_EVENT_WITH_ACTION("REGISTER", "SUCCESS"); var intent = new Intent(this, typeof(Activities.RegisterVerification)); intent.PutExtra("EMAIL_USED_TO_REGISTER", email.Text); intent.SetFlags(ActivityFlags.ClearTop | ActivityFlags.ClearTask | ActivityFlags.NewTask); StartActivity(intent); Finish(); } else { RunOnUiThread(() => { if (response.Meta.Messages.Count > 0) { LOG_EVENT_WITH_ACTION("REGISTER", "ERROR"); response.Meta.Messages.ForEach(MakeError); } FindViewById <AppCompatButton>(Resource.Id.submit).Enabled = true; FindViewById <RelativeLayout>(Resource.Id.loadingLayout).Visibility = ViewStates.Gone; fname.RequestFocus(); }); } } }