private void TrySetNotification() { var(hasData, dateAndTime) = localTodo.GetCombinedDateTime(true); if (hasData && localTodo.HasNotification) { var truncatedBody = $"{localTodo.Body.Truncate(Config.ST.NotificationBodyLength)}..."; var notificationId = RandomUtilities.GetRandomInt(1, Config.ST.NotificationMaxRandom); var exactDateAndTime = dateAndTime.date + dateAndTime.time; CrossLocalNotifications.Current.Show(localTodo.Title, truncatedBody, notificationId, exactDateAndTime); localTodo.NotificationId = notificationId; } else if (!localTodo.HasNotification) { CrossLocalNotifications.Current.Cancel(localTodo.NotificationId); } }
public TodoItemCreateEditPage(ObservableCollection <TodoItem> todoCollection, TodoItem editingItem, CreateEditPageType pageType, string pageTitlePrefix) { InitializeComponent(); this.mainTodoCollection = todoCollection; originalEntryTitlePlaceHolderText = entryTitle.Placeholder; // Because xamarin editor does not have a placeholder horizontal alignment property, attempt to center the text manually by using the device's width. StringBuilder editorPlaceHolderBuilder = new StringBuilder(); int amountOfWhiteSpace = (int)(DeviceDisplay.MainDisplayInfo.Width / 100) + 3; for (int i = 0; i < amountOfWhiteSpace; i++) { editorPlaceHolderBuilder.Append(' '); } editorPlaceHolderBuilder.Append("Body"); originalEditorBodyPlaceHolderText = editorPlaceHolderBuilder.ToString(); editorBody.Placeholder = originalEditorBodyPlaceHolderText; titleLabel.Text = $"{pageTitlePrefix} To-Do"; this.pageType = pageType; if (this.pageType == CreateEditPageType.Edit) { localTodo = editingItem; entryTitle.Text = localTodo.Title; editorBody.Text = localTodo.Body; chooseImageLabel.Text = localTodo.ImageName; var toggled = localTodo.HasNotification; notificationSwitch.IsToggled = toggled; var(hasData, dateAndTime) = localTodo.GetCombinedDateTime(false); if (localTodo.HasNotification && hasData) { datePicker.Date = dateAndTime.date; timePicker.Time = dateAndTime.time; } } else { localTodo = new TodoItem() { Date = DateTime.Now.ToString() }; } }