protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.MyFriendMessages); preferences = PreferenceManager.GetDefaultSharedPreferences(ApplicationContext); mMyFriendMessagesTitle = FindViewById<TextView>(Resource.Id.MyFriendMessagesTitleTextView); mMyFriendMessages = FindViewById<ListView>(Resource.Id.myFriendMessagesListView); friend = JsonConvert.DeserializeObject<Traveler>(Intent.GetStringExtra("Friend")); if (friend.Id != 0) { mItems = new List<Information>(); GetMyFriendMessages(friend.Id); mMyFriendMessagesTitle.Text = string.Format(GetString(Resource.String.MyFriendMessagesTitle) + " {0} {1}", friend.Name, friend.Surname); } else Toast.MakeText(this, GetString(Resource.String.LoadingMessageNotOkInfo), ToastLength.Long).Show(); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.Register); mRegEmail = FindViewById<EditText>(Resource.Id.regEMailEditText); mRegPw = FindViewById<EditText>(Resource.Id.regPwEditText); mRegPwConfirm = FindViewById<EditText>(Resource.Id.regPwConfirmEditText); mRegName = FindViewById<EditText>(Resource.Id.regNameEditText); mRegSurname = FindViewById<EditText>(Resource.Id.regSurnameEditText); mRegDoB = FindViewById<TextView>(Resource.Id.regDoBTextView); mRegButton = FindViewById<Button>(Resource.Id.regButton); mDateOfBirth = new DateTime(1970, 1, 1); mRegDoB.Click += (object sender, EventArgs e) => { var datePickerFragment = new DatePickerDialogFragment(this, mDateOfBirth.AddMonths(-1), this); datePickerFragment.Cancelable = false; datePickerFragment.Show(FragmentManager, null); }; mRegButton.Click += async (object sender, EventArgs e) => { if (AreFieldsFilled()) if (Regex.Match(mRegEmail.Text, @"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$").Success) if (IsPasswordMatchingPolicy()) if (mRegPw.Text.Equals(mRegPwConfirm.Text)) { mEmail = mRegEmail.Text; mPw = mRegPw.Text; mPwConfirm = mRegPwConfirm.Text; mName = mRegName.Text; mSurname = mRegSurname.Text; //ProgressDialog var loadingMessage = ProgressDialog.Show(this, GetString(Resource.String.SendingUserRegisterTitle ), GetString(Resource.String.SendingUserRegisterContent), true, false); //nowy u¿ytkownik newUser = new UserRegisterBinding { Email = mEmail, Password = mPw, ConfirmPassword = mPwConfirm }; var connectivityManager = (ConnectivityManager) GetSystemService(ConnectivityService); var activeNetworkInfo = connectivityManager.ActiveNetworkInfo; if (activeNetworkInfo == null || !activeNetworkInfo.IsConnected) { loadingMessage.Dismiss(); Toast.MakeText(this, GetString(Resource.String.NoConnectionInfo), ToastLength.Long) .Show(); return; } var responseMessage = await RegisterUser(newUser); if (responseMessage.IsSuccessStatusCode) { var responseMessageContent = await responseMessage.Content.ReadAsStringAsync(); var userId = JsonConvert.DeserializeObject<string>(responseMessageContent); //nowy podró¿uj¹cy newTraveler = new Traveler { Name = mName, Surname = mSurname, DateOfBirth = mDateOfBirth, UserId = userId }; responseMessage = await AddTraveler(newTraveler); if (!responseMessage.IsSuccessStatusCode) return; loadingMessage.Dismiss(); SetResult(Result.Ok); Finish(); } else { loadingMessage.Dismiss(); Toast.MakeText(this, GetString(Resource.String.RegisterUserModelNotOkInfo), ToastLength.Long).Show(); } } else Toast.MakeText(this, GetString(Resource.String.RegisterUserPwsNotEqualInfo), ToastLength.Long).Show(); else { for (var i = 0; i < 2; i++) Toast.MakeText(this, GetString(Resource.String.RegisterUserPwNotMatchingPolicyInfo), ToastLength.Long).Show(); } else Toast.MakeText(this, GetString(Resource.String.RegisterUserEmailNotCorrectInfo), ToastLength.Long).Show(); else Toast.MakeText(this, GetString(Resource.String.RegisterUserNoDataInfo), ToastLength.Long).Show(); }; }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.Register); mRegEmail = FindViewById <EditText>(Resource.Id.regEMailEditText); mRegPw = FindViewById <EditText>(Resource.Id.regPwEditText); mRegPwConfirm = FindViewById <EditText>(Resource.Id.regPwConfirmEditText); mRegName = FindViewById <EditText>(Resource.Id.regNameEditText); mRegSurname = FindViewById <EditText>(Resource.Id.regSurnameEditText); mRegDoB = FindViewById <TextView>(Resource.Id.regDoBTextView); mRegButton = FindViewById <Button>(Resource.Id.regButton); mDateOfBirth = new DateTime(1970, 1, 1); mRegDoB.Click += (object sender, EventArgs e) => { var datePickerFragment = new DatePickerDialogFragment(this, mDateOfBirth.AddMonths(-1), this); datePickerFragment.Cancelable = false; datePickerFragment.Show(FragmentManager, null); }; mRegButton.Click += async(object sender, EventArgs e) => { if (AreFieldsFilled()) { if (Regex.Match(mRegEmail.Text, @"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$").Success) { if (IsPasswordMatchingPolicy()) { if (mRegPw.Text.Equals(mRegPwConfirm.Text)) { mEmail = mRegEmail.Text; mPw = mRegPw.Text; mPwConfirm = mRegPwConfirm.Text; mName = mRegName.Text; mSurname = mRegSurname.Text; //ProgressDialog var loadingMessage = ProgressDialog.Show(this, GetString(Resource.String.SendingUserRegisterTitle ), GetString(Resource.String.SendingUserRegisterContent), true, false); //nowy u¿ytkownik newUser = new UserRegisterBinding { Email = mEmail, Password = mPw, ConfirmPassword = mPwConfirm }; var connectivityManager = (ConnectivityManager)GetSystemService(ConnectivityService); var activeNetworkInfo = connectivityManager.ActiveNetworkInfo; if (activeNetworkInfo == null || !activeNetworkInfo.IsConnected) { loadingMessage.Dismiss(); Toast.MakeText(this, GetString(Resource.String.NoConnectionInfo), ToastLength.Long) .Show(); return; } var responseMessage = await RegisterUser(newUser); if (responseMessage.IsSuccessStatusCode) { var responseMessageContent = await responseMessage.Content.ReadAsStringAsync(); var userId = JsonConvert.DeserializeObject <string>(responseMessageContent); //nowy podró¿uj¹cy newTraveler = new Traveler { Name = mName, Surname = mSurname, DateOfBirth = mDateOfBirth, UserId = userId }; responseMessage = await AddTraveler(newTraveler); if (!responseMessage.IsSuccessStatusCode) { return; } loadingMessage.Dismiss(); SetResult(Result.Ok); Finish(); } else { loadingMessage.Dismiss(); Toast.MakeText(this, GetString(Resource.String.RegisterUserModelNotOkInfo), ToastLength.Long).Show(); } } else { Toast.MakeText(this, GetString(Resource.String.RegisterUserPwsNotEqualInfo), ToastLength.Long).Show(); } } else { for (var i = 0; i < 2; i++) { Toast.MakeText(this, GetString(Resource.String.RegisterUserPwNotMatchingPolicyInfo), ToastLength.Long).Show(); } } } else { Toast.MakeText(this, GetString(Resource.String.RegisterUserEmailNotCorrectInfo), ToastLength.Long).Show(); } } else { Toast.MakeText(this, GetString(Resource.String.RegisterUserNoDataInfo), ToastLength.Long).Show(); } }; }
private async Task<HttpResponseMessage> AddTraveler(Traveler newTraveler) { var url = GetString(Resource.String.ApiLink) + "/api/traveler/posttraveler"; client = new HttpClient(); var json = JsonConvert.SerializeObject(newTraveler); var content = new StringContent(json, Encoding.UTF8, "application/json"); var response = await client.PostAsync(new Uri(url), content); return response; }