protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.MedicationDosageView); var toolbar = FindViewById <Toolbar>(Resource.Id.toolbar); //Toolbar will now take on default actionbar characteristics SetSupportActionBar(toolbar); SupportActionBar.Title = AppResources.MedicationDosageViewModel_Title; nameText = FindViewById <EditText>(Resource.Id.NameEditText); dosageText = FindViewById <EditText>(Resource.Id.DosageEditText); takePicutre = FindViewById <LinearLayout>(Resource.Id.take_photo); picture = FindViewById <ImageView>(Resource.Id.photo); daysOfWeek = FindViewById <TextView>(Resource.Id.label_medication_days_of_week); deleteBtn = FindViewById <Button>(Resource.Id.deleteBtn); hoursList = FindViewById <MedicationDosageTimeLayout>(Resource.Id.notificationHours); timePicker = FindViewById <Button>(Resource.Id.time_picker); everyday = FindViewById <RadioButton>(Resource.Id.everyday); custom = FindViewById <RadioButton>(Resource.Id.custom); hoursList.ItemTemplateId = Resource.Layout.time_item; barScan = FindViewById <FloatingActionButton>(Resource.Id.barScan); MobileBarcodeScanner.Initialize(Application); barScan.Click += async(sender, e) => { // Initialize the scanner first so it can track the current context var scanner = new MobileBarcodeScanner(); var result = await scanner.Scan(); if (result != null) { nameText.SetText(result.ToString(), TextView.BufferType.Editable); } }; //obsluga usuwania - jedna z kilku mozliwosci //wcisniecie przyscisku delete spowoduje wywolanie na adapterze komendy z usuwana godzina (implementacja w MedicationDosageTimeListAdapter var hourAdapter = (MedicationDosageTimeListAdapter)hoursList.Adapter;//dialog tworzymy i pokazujemy z kodu hourAdapter.DeleteRequested.Subscribe(time => this.ViewModel.DosageHours.Remove(time)); //aby ui sie odswiezyl, lista godzin powinna być jakimś typem NotifyCollectionChanged (np. ReactiveList) //w samym UI można użyć MvxLinearLayout, który działa podobnie do listy,ale nie spowoduje scrolla w scrollu //wtedy właściwość Times bindujemy to tego komponentu timePicker.Click += (o, e) => { TimePickerDialog timePickerFragment = new TimePickerDialog( this, (s, args) => { // handler jest wołany dwukrotnie: raz bo wybrana została godzina, drugi bo picker został zamknięty - ten musimy zignorować if (((TimePicker)s).IsShown) { this.ViewModel.DosageHours.Add(new TimeSpan(args.HourOfDay, args.Minute, 0)); } }, 12, 00, true ); timePickerFragment.Show(); }; SecondBottomSheet secondDialog = new SecondBottomSheet(this); DeleteDialog deleteDialog = new DeleteDialog(this); View deleteView = LayoutInflater.Inflate(Resource.Layout.delete_dialog, null); deleteDialog.SetContentView(deleteView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent)); custom.Click += (o, e) => { secondDialog.Show(ViewModel.Monday, ViewModel.Tuesday, ViewModel.Wednesday, ViewModel.Thursday, ViewModel.Friday, ViewModel.Saturday, ViewModel.Sunday); }; secondDialog.Accept.Subscribe(x => { this.ViewModel.Monday = x[0]; this.ViewModel.Tuesday = x[1]; this.ViewModel.Wednesday = x[2]; this.ViewModel.Thursday = x[3]; this.ViewModel.Friday = x[4]; this.ViewModel.Saturday = x[5]; this.ViewModel.Sunday = x[6]; secondDialog.Hide(); }); secondDialog.Cancel.Subscribe(x => { secondDialog.Dismiss(); }); deleteDialog.Create(); deleteBtn.Click += (o, e) => deleteDialog.Show(); deleteDialog.Accept.Subscribe(x => { if (((ICommand)ViewModel.Delete).CanExecute(null)) { ViewModel.Delete.Execute().Subscribe(); } }); deleteDialog.Cancel.Subscribe(x => deleteDialog.Dismiss()); SetBinding(); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.MedicationDosageView); var toolbar = FindViewById <Toolbar>(Resource.Id.toolbar); //Toolbar will now take on default actionbar characteristics SetSupportActionBar(toolbar); SupportActionBar.Title = AppResources.MedicationDosageViewModel_Title; nameText = FindViewById <EditText>(Resource.Id.NameEditText); fromDate = FindViewById <TextView>(Resource.Id.odKiedy); toDate = FindViewById <TextView>(Resource.Id.doKiedy); clearFrom = FindViewById <ImageButton>(Resource.Id.clearFrom); clearTo = FindViewById <ImageButton>(Resource.Id.clearTo); dosageText = FindViewById <EditText>(Resource.Id.DosageEditText); takePicutre = FindViewById <LinearLayout>(Resource.Id.take_photo); picture = FindViewById <ImageView>(Resource.Id.photo); deleteBtn = FindViewById <TextView>(Resource.Id.deleteBtn); timeSelector = FindViewById <TextView>(Resource.Id.timeSelector); daysSelector = FindViewById <TextView>(Resource.Id.daySelector); var timeSelectorDialog = new OrdinationTimesSheet(this, this.ViewModel); timeSelector.Click += (o, e) => timeSelectorDialog.Show(); barScan = FindViewById <FloatingActionButton>(Resource.Id.barScan); MobileBarcodeScanner.Initialize(Application); barScan.Click += async(sender, e) => { // Initialize the scanner first so it can track the current context var scanner = new MobileBarcodeScanner(); var result = await scanner.Scan(); if (result != null) { ViewModel.SetMedicinesName(result.Text); } }; OrdiniationSchemeDialog ordinationSchemeDialog = new OrdiniationSchemeDialog(this, this.ViewModel); daysSelector.Click += (o, e) => ordinationSchemeDialog.Show(); DeleteDialog deleteDialog = new DeleteDialog(this); View deleteView = LayoutInflater.Inflate(Resource.Layout.delete_dialog, null); deleteDialog.SetContentView(deleteView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent)); fromDate.Click += (o, e) => { DatePickerFragment frag = DatePickerFragment.NewInstance(delegate(DateTime time) { fromDate.Text = time.ToShortDateString(); }); frag.minDate = DateTime.Now.Date; frag.Show(FragmentManager, DatePickerFragment.TAG); }; toDate.Click += (o, e) => { DatePickerFragment frag = DatePickerFragment.NewInstance(delegate(DateTime time) { toDate.Text = time.ToShortDateString(); }); if (!string.IsNullOrEmpty(fromDate.Text)) { frag.minDate = DateTime.Parse(fromDate.Text); } else { frag.minDate = DateTime.Now.Date; } frag.Show(FragmentManager, DatePickerFragment.TAG); }; clearFrom.Click += (o, e) => { fromDate.Text = ""; }; clearTo.Click += (o, e) => { toDate.Text = ""; }; fromDate.TextChanged += (o, e) => { if (string.IsNullOrEmpty(fromDate.Text)) { clearFrom.Visibility = ViewStates.Invisible; } else { clearFrom.Visibility = ViewStates.Visible; } }; toDate.TextChanged += (o, e) => { if (string.IsNullOrEmpty(toDate.Text)) { clearTo.Visibility = ViewStates.Invisible; } else { clearTo.Visibility = ViewStates.Visible; } }; //deleteDialog.Create(); deleteBtn.Click += (o, e) => deleteDialog.Show(); deleteDialog.Accept.Subscribe(x => { if (((ICommand)ViewModel.Delete).CanExecute(null)) { ViewModel.Delete.Execute().Subscribe(); } }); deleteDialog.Cancel.Subscribe(x => deleteDialog.Dismiss()); SetBinding(); }