Ejemplo n.º 1
0
        private void AddReminderbutton_Click(object sender, EventArgs e)
        {
            try
            {
                ReminderModel data = new ReminderModel()
                {
                    AdditionalInfo = View.FindViewById<EditText>(Resource.Id.phoneText).Text,
                    DateOfIssue = View.FindViewById<DatePicker>(Resource.Id.datePicker).DateTime,
                    PhoneNumber = View.FindViewById<EditText>(Resource.Id.phoneText).Text,
                    Id = Guid.NewGuid(),
                    CallDone = false
                };

                var path = Path.GetFullPath(string.Format("{0}\\{1}", AppDomain.CurrentDomain.BaseDirectory, "Assets\\Settings.xml"));

                if (!string.IsNullOrWhiteSpace(path) && File.Exists(path))
                {
                    SettingsManager<ReminderModel> manager = new SettingsManager<ReminderModel>(path);
                    List<ReminderModel> items = manager.Deserialize();
                    items.Add(data);
                    string xml = string.Empty;
                    bool result = manager.Serialize(items, ref xml);

                    Activity.RunOnUiThread(() =>
                    {
                        Toast.MakeText(Activity, "Dodano przypomnienie", ToastLength.Long).Show();
                    });

                }
                else
                {
                    Activity.RunOnUiThread(() =>
                    {
                        Toast.MakeText(Activity, "Nie odnaleziono pliku ustawień", ToastLength.Long).Show();
                    });
                }
            }
            catch (Exception ex)
            {
                Activity.RunOnUiThread(() =>
                {
                    Toast.MakeText(Activity, "Podczas dodawania przypomnienia wystąpił błąd: " + ex.Message, ToastLength.Long).Show();
                });
            }
        }