public void RefreshListViewSource() { Core MainCore = Core.GetCore(); Scheduler MainScheduler = MainCore.GetScheduler(); System.Collections.ObjectModel.ObservableCollection <AppTask> oTasksList = new System.Collections.ObjectModel.ObservableCollection <AppTask>(MainScheduler.GetTasks(false)); listView.ItemTemplate = new DataTemplate(typeof(ListItemCell)); listView.ItemsSource = oTasksList; }
protected override void OnAppearing() { // This callback gets trigger everytime the user comes to this screen. base.OnAppearing(); AppConfig appConfig = Core.GetCore().GetConfig(); RefreshListViewSource(); Style = appConfig.GeneratePageStyle(); AddTask.Style = appConfig.GenerateButtonStyle(); ConfigButton.Style = appConfig.GenerateButtonStyle(); }
public ListItemCell() { var moreAction = new MenuItem { Text = "More" }; moreAction.SetBinding(MenuItem.CommandParameterProperty, new Binding(".")); moreAction.Clicked += (sender, e) => { var mi = ((MenuItem)sender); var item = (AppTask)mi.CommandParameter; }; var deleteAction = new MenuItem { Text = "Delete", IsDestructive = true }; deleteAction.SetBinding(MenuItem.CommandParameterProperty, new Binding(".")); deleteAction.Clicked += async(sender, e) => { var mi = ((MenuItem)sender); var item = (AppTask)mi.CommandParameter; bool willDelete = await App.Current.MainPage.DisplayAlert("Delete Confirmation", "Are you sure you want to remove this task?", "Yes", "No"); if (willDelete) { Core.GetCore().GetScheduler().RemoveTask(item.TaskID); ((Main)((Xamarin.Forms.NavigationPage)App.Current.MainPage).CurrentPage).OnAppearing(); } }; ContextActions.Add(moreAction); ContextActions.Add(deleteAction); Label titleLabel = new Label { Text = "Task Name" }; titleLabel.SetBinding(Label.TextProperty, "TaskName"); StackLayout viewLayoutItem = new StackLayout() { HorizontalOptions = LayoutOptions.StartAndExpand, Orientation = StackOrientation.Vertical, Children = { titleLabel } }; View = viewLayoutItem; }
public Main() { Title = "Scheduler App 2016"; Core MainCore = Core.GetCore(); Scheduler MainScheduler = MainCore.GetScheduler(); listView = new ListView(); listView.ItemSelected += (sender, e) => { AppTask x = (AppTask)e.SelectedItem; if (x is AppTask) { Navigation.PushAsync(new pageTask(Core.GetCore().GetScheduler().FindTaskById(x.TaskID))); ((ListView)sender).SelectedItem = null; } }; AddTask = new Button { Text = "Add Task", Style = MainCore.GetConfig().GenerateButtonStyle() }; AddTask.Clicked += (sender, e) => { var pAddTask = new pageTask(); this.Navigation.PushAsync(pAddTask); }; ConfigButton = new Button { Text = "Configuration", Style = MainCore.GetConfig().GenerateButtonStyle() }; ConfigButton.Clicked += (sender, e) => { var pAppSettings = new pageAppConfig(); this.Navigation.PushAsync(pAppSettings); }; Content = new StackLayout { VerticalOptions = LayoutOptions.Center, Children = { listView, AddTask, ConfigButton } }; }
public pageTask(AppTask existingTask = null) { AppConfig config = Core.GetCore().GetConfig(); Title = "Add Task"; var nameLabel = new Label { Text = "Task Name", Style = config.GenerateLabelStyle() }; Entry nameEntry = new Entry { Placeholder = "New Task Name" }; nameEntry.Style = config.GenerateEntryStyle(); var noteLabel = new Label { Text = "Task Note", Style = config.GenerateLabelStyle() }; Entry noteEntry = new Entry { Placeholder = "New Task Notes" }; noteEntry.Style = config.GenerateEntryStyle(); var doneLabel = new Label { Text = "Done", Style = config.GenerateLabelStyle() }; var donePicker = new Picker { Style = config.GeneratePickerStyle() }; donePicker.Items.Add("False"); donePicker.Items.Add("True"); donePicker.SelectedIndex = 0; var reminderBeginDateLabel = new Label { Text = "Set Begin Date", Style = config.GenerateLabelStyle() }; var reminderBeginDatePicker = new DatePicker { Format = "D", Style = config.GeneratePickerStyle() }; var reminderEndDateLabel = new Label { Text = "Set End Date", Style = config.GenerateLabelStyle() }; var reminderEndDatePicker = new DatePicker { Format = "D", Style = config.GeneratePickerStyle() }; Button ringTonePickerBtn = new Button { Text = "Select RingTone", }; ringTonePickerBtn.Clicked += (sender, args) => { DependencyService.Get <iRingTones>().GetRingTonePicker(existingTask); }; var frequencyLabel = new Label { Text = "Select Frequency", Style = config.GenerateLabelStyle() }; var frequencyPicker = new Picker { Style = config.GeneratePickerStyle() }; for (int i = 1; i <= 10; i++) { frequencyPicker.Items.Add(i.ToString()); } var frequencyUnitLabel = new Label { Text = "Select Unit", Style = config.GenerateLabelStyle() }; var frequencyUnitPicker = new Picker { Style = config.GeneratePickerStyle() }; frequencyUnitPicker.Items.Add("Minutes"); frequencyUnitPicker.Items.Add("Hours"); frequencyUnitPicker.Items.Add("Days"); frequencyUnitPicker.Items.Add("Weeks"); Button deleteButton = new Button { Text = "Delete", Style = config.GenerateButtonStyle() }; deleteButton.IsVisible = false; deleteButton.Clicked += async(sender, e) => { bool willDelete = await DisplayAlert("Delete Confirmation", "Are you sure you want to remove this task?", "Yes", "No"); if (willDelete) { Core.GetCore().GetScheduler().RemoveTask(existingTask.TaskID); await Navigation.PopAsync(); } }; if (existingTask == null) { frequencyPicker.SelectedIndex = 5; frequencyUnitPicker.SelectedIndex = 2; } else { nameEntry.Text = existingTask.TaskName; noteEntry.Text = existingTask.TaskNotes; if (existingTask.Done) { donePicker.SelectedIndex = 1; } else { donePicker.SelectedIndex = 0; } reminderBeginDatePicker.Date = existingTask.ReminderBegin; reminderEndDatePicker.Date = existingTask.ReminderEnd; for (int i = 0; i < frequencyPicker.Items.Count; i++) { if (existingTask.Frequency.ToString() == frequencyPicker.Items[i]) { frequencyPicker.SelectedIndex = i; break; } } for (int i = 0; i < frequencyUnitPicker.Items.Count; i++) { if (existingTask.FrequencyUnit == frequencyUnitPicker.Items[i]) { frequencyUnitPicker.SelectedIndex = i; break; } } deleteButton.IsVisible = true; } var SaveButton = new Button { Text = "Save!", Style = config.GenerateButtonStyle() }; SaveButton.Clicked += (sender, e) => { string tTaskName; string tTaskNotes; DateTime tReminderBeginDate; DateTime tReminderEndDate; bool tDone; int tFrequency; string tFrequencyUnit; string tNotificationSound; if (nameEntry.Text != null && noteEntry.Text != null) { tTaskName = nameEntry.Text.ToString(); tTaskNotes = noteEntry.Text.ToString(); tReminderBeginDate = reminderBeginDatePicker.Date; tReminderEndDate = reminderEndDatePicker.Date; tDone = Convert.ToBoolean(donePicker.Items [donePicker.SelectedIndex]); tFrequency = Convert.ToInt32(frequencyPicker.Items[frequencyPicker.SelectedIndex]); tFrequencyUnit = frequencyUnitPicker.Items[frequencyUnitPicker.SelectedIndex]; tNotificationSound = DependencyService.Get <iRingTones>().GetSelectedRingTone(); if (existingTask == null) { Core.GetCore().GetScheduler().AddTaskWithInfo( tTaskName, tTaskNotes, tReminderBeginDate, tReminderEndDate, tNotificationSound, tFrequency, tFrequencyUnit); } else { Core.GetCore().GetScheduler().UpdateTaskWithInfo( existingTask.TaskID, tTaskName, tTaskNotes, tReminderBeginDate, tReminderEndDate, tNotificationSound, tFrequency, tFrequencyUnit); } Navigation.PopAsync(); } else { DisplayAlert("But wait!", "Please write a little about your Task name and task notes.", "Ok"); }; }; ScrollView scrollView = new ScrollView { VerticalOptions = LayoutOptions.FillAndExpand, Content = new StackLayout { VerticalOptions = LayoutOptions.CenterAndExpand, Padding = new Thickness(20), Children = { nameLabel, nameEntry, noteLabel, noteEntry, doneLabel, donePicker, ringTonePickerBtn, reminderBeginDateLabel, reminderBeginDatePicker, frequencyLabel, frequencyPicker, frequencyUnitLabel, frequencyUnitPicker, reminderEndDateLabel, reminderEndDatePicker, SaveButton, deleteButton } } }; this.Content = scrollView; }
protected override void OnAppearing() { base.OnAppearing(); Style = Core.GetCore().GetConfig().GeneratePageStyle(); }
public pageAppConfig() { Core core = Core.GetCore(); AppConfig config = core.GetConfig(); bool ringtonePickerOpened = false; Title = "Application Configuration"; var defaultNotificationLabel = new Label { Text = "Default Notification Sound" }; var defaultNotificationLabelDesc = new Label { Text = "Represents the default ring tone to assign for new tasks." }; Button ringTonePickerBtn = new Button { Text = "Select RingTone", }; ringTonePickerBtn.Clicked += (sender, args) => { if (!ringtonePickerOpened) { DependencyService.Get <iRingTones>().SetSelectedRingTone(config.DefaultNotificationSound); ringtonePickerOpened = true; } DependencyService.Get <iRingTones>().GetRingTonePicker(); }; var fontLabel = new Label { Text = "Font" }; var fontPicker = new Picker(); fontPicker.Items.Add("Arial"); fontPicker.Items.Add("Courier"); fontPicker.Items.Add("Helvetica"); fontPicker.Items.Add("Times New Roman"); fontPicker.SetBinding(Entry.TextProperty, "Font"); fontPicker.Title = "Font"; fontPicker.SelectedIndex = 0; for (int i = 0; i < fontPicker.Items.Count; i++) { if (config.Theme.font == fontPicker.Items[i]) { fontPicker.SelectedIndex = i; break; } } var fontSizeLabel = new Label { Text = "Font Size" }; var fontSizePicker = new Picker(); fontSizePicker.Items.Add("Default"); fontSizePicker.Items.Add("Micro"); fontSizePicker.Items.Add("Small"); fontSizePicker.Items.Add("Medium"); fontSizePicker.Items.Add("Large"); fontSizePicker.SetBinding(Entry.TextProperty, "Font Size"); fontSizePicker.SelectedIndex = 0; string sizeToFind = config.sizeToName[config.Theme.fontSize]; var sizeArray = config.nameToSize.ToArray(); for (int i = 0; i < fontSizePicker.Items.Count; i++) { if (sizeToFind == fontSizePicker.Items[i]) { fontSizePicker.SelectedIndex = i; break; } } var fontColourLabel = new Label { Text = "Font Colour" }; var fontColourPicker = new Picker(); var colourArray = config.nameToColour.ToArray(); for (int i = 0; i < colourArray.Length; i++) { fontColourPicker.Items.Add(colourArray[i].Key); } fontColourPicker.SetBinding(Entry.TextProperty, "Font Colour"); fontColourPicker.Title = "Font Colour"; fontColourPicker.SelectedIndex = 0; string colourToFind = config.colourToName[config.Theme.fontColour]; for (int i = 0; i < colourArray.Length; i++) { if (colourToFind == colourArray[i].Key) { fontColourPicker.SelectedIndex = i; break; } } BoxView fontColourBoxView = new BoxView { WidthRequest = 20, HeightRequest = 20, HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.CenterAndExpand }; fontColourBoxView.Color = config.nameToColour[colourToFind]; fontColourPicker.SelectedIndexChanged += (sender, args) => { if (fontColourPicker.SelectedIndex == -1) { fontColourBoxView.Color = Color.Default; } else { string colourName = fontColourPicker.Items[fontColourPicker.SelectedIndex]; fontColourBoxView.Color = config.nameToColour[colourName]; } }; var backgroundColourLabel = new Label { Text = "Background Colour" }; var backgroundColourPicker = new Picker(); for (int i = 0; i < colourArray.Length; i++) { backgroundColourPicker.Items.Add(colourArray[i].Key); } backgroundColourPicker.SetBinding(Entry.TextProperty, "Background Colour"); backgroundColourPicker.Title = "Background Colour"; backgroundColourPicker.SelectedIndex = 0; colourToFind = config.colourToName[config.Theme.backgroundColour]; for (int i = 0; i < colourArray.Length; i++) { if (colourToFind == colourArray[i].Key) { backgroundColourPicker.SelectedIndex = i; break; } } BoxView backgroundColourBoxView = new BoxView { WidthRequest = 20, HeightRequest = 20, HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.CenterAndExpand }; backgroundColourBoxView.Color = config.nameToColour[colourToFind]; backgroundColourPicker.SelectedIndexChanged += (sender, args) => { if (backgroundColourPicker.SelectedIndex == -1) { backgroundColourBoxView.Color = Color.Default; } else { string colorName = backgroundColourPicker.Items[backgroundColourPicker.SelectedIndex]; backgroundColourBoxView.Color = config.nameToColour[colorName]; } }; var SaveButton = new Button { Text = "Save Configuration" }; SaveButton.Clicked += (sender, e) => { ThemeStruct themeStruct = config.Theme; if (backgroundColourPicker.Items[backgroundColourPicker.SelectedIndex] == fontColourPicker.Items[fontColourPicker.SelectedIndex]) { DisplayAlert("Error", "You cannot select the same background and foreground colour. Please correct your selection and try again.", "Ok"); } else { config.DefaultNotificationSound = DependencyService.Get <iRingTones>().GetSelectedRingTone(); themeStruct.backgroundColour = config.nameToColour[backgroundColourPicker.Items[backgroundColourPicker.SelectedIndex]]; themeStruct.font = fontPicker.Items[fontPicker.SelectedIndex]; themeStruct.fontColour = config.nameToColour[fontColourPicker.Items[fontColourPicker.SelectedIndex]]; themeStruct.fontSize = config.nameToSize[fontSizePicker.Items[fontSizePicker.SelectedIndex]]; config.Theme = themeStruct; } config.Write(core.SCHEDULEAPP_CONFIG_FILE); Navigation.PopToRootAsync(); }; ScrollView scrollView = new ScrollView { VerticalOptions = LayoutOptions.FillAndExpand, Content = new StackLayout { VerticalOptions = LayoutOptions.CenterAndExpand, Padding = new Thickness(20), Children = { defaultNotificationLabel, ringTonePickerBtn, fontLabel, fontPicker, fontSizeLabel, fontSizePicker, fontColourLabel, fontColourPicker, fontColourBoxView, backgroundColourLabel, backgroundColourPicker, backgroundColourBoxView, SaveButton } } }; this.Content = scrollView; }