private async void buttonCreateGroup_Click(object sender, RoutedEventArgs e) { string name = textName.Text; string description = textDescription.Text; string password = textPassword.Password; float color = ColorParser.parseColorToFloat(comboBoxColors.SelectedItem.ToString()); string user = ApplicationData.Current.LocalSettings.Values["Email"].ToString(); if (String.IsNullOrWhiteSpace(name) || String.IsNullOrWhiteSpace(description)) { var dialog = new MessageDialog("Brak nazwy lub opisu."); dialog.Title = "Błąd"; dialog.Commands.Add(new UICommand { Label = "OK", Id = 0 }); var res = await dialog.ShowAsync(); return; } HttpClient httpClient = new HttpClient(); string url = string.Format("http://www.friendszone.cba.pl/api/add_group.php?name={0}&description={1}&password={2}&user={3}&color={4}", name, description, password, user, color ); string ResponseString = await httpClient.GetStringAsync(new Uri(url)); processResponse(ResponseString); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Create your application here SetContentView(Resource.Layout.CreateGroup); spinnerColors = FindViewById <Spinner>(Resource.Id.spinnerColors); buttonCreateGroup = FindViewById <Button>(Resource.Id.buttonCreateGroup); var adapter = ArrayAdapter.CreateFromResource( this, Resource.Array.colors_array, Android.Resource.Layout.SimpleSpinnerItem); adapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem); spinnerColors.Adapter = adapter; buttonCreateGroup.Click += delegate { string name = FindViewById <EditText>(Resource.Id.textName).Text; string description = FindViewById <EditText>(Resource.Id.textDescription).Text; string password = FindViewById <EditText>(Resource.Id.textPassword).Text; float color = ColorParser.parseColorToFloat(FindViewById <Spinner>(Resource.Id.spinnerColors).SelectedItem.ToString()); string user = this.GetSharedPreferences("User.data", FileCreationMode.Private).GetString("Email", ""); if (String.IsNullOrWhiteSpace(name) || String.IsNullOrWhiteSpace(description)) { Toast.MakeText( this, "Brak nazwy lub opisu", ToastLength.Long).Show(); return; } string url = string.Format("http://www.friendszone.cba.pl/api/add_group.php?name={0}&description={1}&password={2}&user={3}&color={4}", name, description, password, user, color ); HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest; request.Method = "GET"; HttpWebResponse response = request.GetResponse() as HttpWebResponse; StreamReader reader = new StreamReader(response.GetResponseStream(), UTF8Encoding.UTF8); String json = reader.ReadToEnd(); processResponse(json); }; }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Create your application here SetContentView(Resource.Layout.GroupDetailsMember); string groupJson = Intent.GetStringExtra("GROUP_JSON"); group = JsonConvert.DeserializeObject <Group>(groupJson); isOwner = setIsOwner(); buttonSave = FindViewById <Button>(Resource.Id.buttonSave); buttonSpots = FindViewById <Button>(Resource.Id.buttonSpotList); buttonMembers = FindViewById <Button>(Resource.Id.buttonMemberList); buttonLeaveGroup = FindViewById <Button>(Resource.Id.buttonLeaveGroup); if (isOwner) { textName = FindViewById <EditText>(Resource.Id.textGroupName); textDescription = FindViewById <EditText>(Resource.Id.textGroupDescription); textPassword = FindViewById <EditText>(Resource.Id.textPassword); textName.Visibility = ViewStates.Visible; textDescription.Visibility = ViewStates.Visible; textPassword.Visibility = ViewStates.Visible; baseName = group.Name; baseDescription = group.Description; basePassword = group.Password; textName.Text = baseName; textDescription.Text = baseDescription; textPassword.Text = basePassword; textName.AfterTextChanged += delegate { checkChanges(); }; textDescription.AfterTextChanged += delegate { checkChanges(); }; textPassword.AfterTextChanged += delegate { checkChanges(); }; buttonLeaveGroup.Text = "Usuñ grupê"; } else { labelName = FindViewById <TextView>(Resource.Id.labelGroupName); labelDescription = FindViewById <TextView>(Resource.Id.labelGroupDescription); labelName.Visibility = ViewStates.Visible; labelDescription.Visibility = ViewStates.Visible; } spinnerColors = FindViewById <Spinner>(Resource.Id.spinnerColors); baseColor = setColor(); var adapter = ArrayAdapter.CreateFromResource( this, Resource.Array.colors_array, Android.Resource.Layout.SimpleSpinnerItem); adapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem); spinnerColors.Adapter = adapter; spinnerColors.SetSelection(adapter.GetPosition(baseColor)); spinnerColors.ItemSelected += delegate { checkChanges(); }; buttonSave.Click += delegate { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.SetTitle("Uwaga!"); builder.SetMessage("Czy na pewno chcesz zapisaæ dane?"); builder.SetCancelable(false); builder.SetPositiveButton("OK", delegate { bool colorEditSuccess = true; bool groupEditSuccess = true; if (spinnerColors.SelectedItem.ToString() != baseColor) { string url = string.Format("http://friendszone.cba.pl/api/edit_group_member.php?gid={0}&uid={1}&color={2}", group.Id, this.GetSharedPreferences("User.data", FileCreationMode.Private).GetString("Email", ""), ColorParser.parseColorToFloat(spinnerColors.SelectedItem.ToString())); HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest; request.Method = "GET"; HttpWebResponse response = request.GetResponse() as HttpWebResponse; StreamReader reader = new StreamReader(response.GetResponseStream(), UTF8Encoding.UTF8); String json = reader.ReadToEnd(); if (JsonConvert.DeserializeObject <Helpers.JsonMsg>(json).msg != "success") { colorEditSuccess = false; } } if (isOwner && (textName.Text != baseName || textDescription.Text != baseDescription || textPassword.Text != basePassword)) { string url = string.Format("http://friendszone.cba.pl/api/edit_group.php?gid={0}&name={1}&des={2}&pass={3}", group.Id, textName.Text, textDescription.Text, textPassword.Text); HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest; request.Method = "GET"; HttpWebResponse response = request.GetResponse() as HttpWebResponse; StreamReader reader = new StreamReader(response.GetResponseStream(), UTF8Encoding.UTF8); String json = reader.ReadToEnd(); if (JsonConvert.DeserializeObject <Helpers.JsonMsg>(json).msg != "success") { groupEditSuccess = false; } } if (colorEditSuccess && groupEditSuccess) { Toast.MakeText( this, "Pomyœlnie edytowano grupê", ToastLength.Long).Show(); Finish(); } else { Toast.MakeText( this, "Wyst¹pi³ b³¹d w trakcie edycji", ToastLength.Long).Show(); } }); builder.SetNegativeButton("Anuluj", delegate { return; }); builder.Show(); }; buttonMembers.Click += delegate { Intent memberListIntent = new Intent(this, typeof(GroupMemberListActivity)); memberListIntent.PutExtra("GROUP_ID", group.Id); StartActivity(memberListIntent); }; buttonSpots.Click += delegate { Intent spotsListIntent = new Intent(this, typeof(GroupSpotsListActivity)); spotsListIntent.PutExtra("GROUP_ID", group.Id); StartActivity(spotsListIntent); }; buttonLeaveGroup.Click += delegate { if (isOwner) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.SetTitle("Uwaga!"); builder.SetMessage("Usuniêcie grupy jest nieodwracalne."); builder.SetCancelable(false); builder.SetPositiveButton("OK", delegate { string url = string.Format("http://friendszone.cba.pl/api/delete_group.php?gid={0}", group.Id); HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest; request.Method = "GET"; HttpWebResponse response = request.GetResponse() as HttpWebResponse; StreamReader reader = new StreamReader(response.GetResponseStream(), UTF8Encoding.UTF8); String json = reader.ReadToEnd(); processLeaveResponse(json); // success, error-server }); builder.SetNegativeButton("Anuluj", delegate { return; }); builder.Show(); } else { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.SetTitle("Uwaga!"); builder.SetMessage("Czy na pewno chcesz opuœciæ grupê?"); builder.SetCancelable(false); builder.SetPositiveButton("OK", delegate { string url = string.Format("http://friendszone.cba.pl/api/leave_group.php?gid={0}&uid={1}", group.Id, this.GetSharedPreferences("User.data", FileCreationMode.Private).GetString("Email", "")); HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest; request.Method = "GET"; HttpWebResponse response = request.GetResponse() as HttpWebResponse; StreamReader reader = new StreamReader(response.GetResponseStream(), UTF8Encoding.UTF8); String json = reader.ReadToEnd(); processLeaveResponse(json); // success, error-server }); builder.SetNegativeButton("Anuluj", delegate { return; }); builder.Show(); } }; }
private async void buttonSave_Click(object sender, RoutedEventArgs e) { var dialog = new MessageDialog("Czy na pewno chcesz zapisać dane?"); dialog.Title = "Uwaga"; dialog.Commands.Add(new UICommand { Label = "Zapisz", Id = 0 }); dialog.Commands.Add(new UICommand { Label = "Anuluj", Id = 1 }); var res = await dialog.ShowAsync(); if ((int)res.Id == 0) { bool colorEditSuccess = true; bool groupEditSuccess = true; HttpClient httpClient; string ResponseString; if (comboBoxColors.SelectedItem.ToString() != baseColor) { httpClient = new HttpClient(); string url = string.Format("http://friendszone.cba.pl/api/edit_group_member.php?gid={0}&uid={1}&color={2}", group.Id, ApplicationData.Current.LocalSettings.Values["Email"], ColorParser.parseColorToFloat(comboBoxColors.SelectedItem.ToString())); ResponseString = await httpClient.GetStringAsync(new Uri(url)); if (JsonConvert.DeserializeObject <Helpers.JsonMsg>(ResponseString).msg != "success") { colorEditSuccess = false; } } if (isOwner && (textGroupName.Text != baseName || textGroupDescription.Text != baseDescription || passwordBox.Password != basePassword)) { httpClient = new HttpClient(); string url = string.Format("http://friendszone.cba.pl/api/edit_group.php?gid={0}&name={1}&des={2}&pass={3}", group.Id, textGroupName.Text, textGroupDescription.Text, passwordBox.Password); ResponseString = await httpClient.GetStringAsync(new Uri(url)); if (JsonConvert.DeserializeObject <Helpers.JsonMsg>(ResponseString).msg != "success") { groupEditSuccess = false; } } if (colorEditSuccess && groupEditSuccess) { dialog = new MessageDialog("Pomyślnie zedytowano dane."); dialog.Title = "Yay!"; dialog.Commands.Add(new UICommand { Label = "OK", Id = 0 }); res = await dialog.ShowAsync(); } else { dialog = new MessageDialog("Wystąpił błąd w czasie edycji."); dialog.Title = "Uwaga"; dialog.Commands.Add(new UICommand { Label = "OK", Id = 0 }); res = await dialog.ShowAsync(); } } }