private void ButtonAction_Click(object sender, RoutedEventArgs e) { BareSnackbar snackbar = (sender as FrameworkElement).DataContext as BareSnackbar; Manager.Close(snackbar); snackbar.ButtonCallback(); }
private void SnackbarManager_OnShow(object sender, BareSnackbar snackbar) { try { var nativeSnackbar = Snackbar.Make(_coordinatorLayout, snackbar.Message, snackbar.Duration); var anchorView = _presenter.GetSnackbarAnchorView(); if (anchorView != null) { nativeSnackbar.SetAnchorView(anchorView); } if (snackbar.ButtonText != null) { nativeSnackbar.SetAction(snackbar.ButtonText, delegate { try { snackbar.ButtonCallback(); } catch { } }); } snackbar.NativeSnackbar = nativeSnackbar; nativeSnackbar.Show(); } catch { } }
private void SnackbarManager_OnClose(object sender, BareSnackbar snackbar) { try { (snackbar.NativeSnackbar as Snackbar).Dismiss(); } catch { } }
private void Snackbar_Tapped(object sender, TappedRoutedEventArgs e) { BareSnackbar snackbar = (sender as FrameworkElement).DataContext as BareSnackbar; Manager.Close(snackbar); }
public async void Save() { // First we block user interaction on checking if full version, since don't want to dismiss the UI // before prompting that they need the full version (otherwise they'd lose data) await TryHandleUserInteractionAsync("SaveCheckingIfAllowed", async (cancellationToken) => { Guid identifierToIgnore = _editingGrade == null ? Guid.Empty : _editingGrade.Identifier; // For free version, block assigning grade if number of graded items exceeds 5 if (SelectedWeightCategory != null && (_editingGrade == null || _editingGrade.GradeReceived == PowerPlannerSending.Grade.UNGRADED) && SelectedWeightCategory.Class.WeightCategories.SelectMany(i => i.Grades).Where(i => i.Identifier != identifierToIgnore && i.GradeReceived != PowerPlannerSending.Grade.UNGRADED).Count() >= 5 && !await PowerPlannerApp.Current.IsFullVersionAsync()) { cancellationToken.ThrowIfCancellationRequested(); PowerPlannerApp.Current.PromptPurchase(PowerPlannerResources.GetString("MessageFreeGradesLimitReached")); return; } // And then we perform the data operation which doesn't need any UI interaction blocks TryStartDataOperationAndThenNavigate(async delegate { string name = Name; if (name.Length == 0) { new PortableMessageDialog(PowerPlannerResources.GetString("String_NoNameMessageBody"), PowerPlannerResources.GetString("String_NoNameMessageHeader")).Show(); return; } ViewItemWeightCategory weightCategory = SelectedWeightCategory; if (weightCategory == null) { new PortableMessageDialog(PowerPlannerResources.GetString("EditGradePage_MessageNoWeightCategoryBody"), PowerPlannerResources.GetString("EditGradePage_MessageNoWeightCategoryHeader")).Show(); return; } //// What If mode if (State == OperationState.AddingWhatIf || State == OperationState.EditingWhatIf) { BaseViewItemMegaItem whatIfGrade; // New if (_editingGrade == null) { whatIfGrade = new ViewItemGrade(null) { DateCreated = DateTime.UtcNow, Updated = DateTime.UtcNow } } ; // Existing else { whatIfGrade = _editingGrade; whatIfGrade.Updated = DateTime.UtcNow; } whatIfGrade.Name = name; whatIfGrade.Details = Details; whatIfGrade.Date = DateTime.SpecifyKind(Date, DateTimeKind.Utc).Date.Add(_originalDateOffset); whatIfGrade.GradeReceived = GradeReceived; whatIfGrade.GradeTotal = GradeTotal; if (UsesIsDropped) { whatIfGrade.IsDropped = IsDropped; } whatIfGrade.WasChanged = true; whatIfGrade.CanBeUsedForAchievingDesiredGrade = whatIfGrade.GradeReceived == PowerPlannerSending.Grade.UNGRADED; if (whatIfGrade.WeightCategory != null) { whatIfGrade.WeightCategory.Remove(whatIfGrade); } weightCategory.Add(whatIfGrade); weightCategory.Class.ResetDream(); } else { BaseDataItemHomeworkExamGrade g; if (State == OperationState.Adding) { g = new DataItemGrade() { Identifier = Guid.NewGuid() } } ; else { g = _editingGrade.CreateBlankDataItem(); } g.Name = name; if (g is DataItemGrade) { g.UpperIdentifier = weightCategory.Identifier; } else if (g is DataItemMegaItem) { (g as DataItemMegaItem).WeightCategoryIdentifier = weightCategory.Identifier; } g.Details = Details; g.Date = DateTime.SpecifyKind(Date, DateTimeKind.Utc).Date.Add(_originalDateOffset); g.GradeReceived = GradeReceived; g.GradeTotal = GradeTotal; if (UsesIsDropped) { g.IsDropped = IsDropped; } DataChanges changes = new DataChanges(); changes.Add(g); await PowerPlannerApp.Current.SaveChanges(changes); // We don't cancel here since we need the following to occur, and removing the view model is fine regardless } NavigationManager.SetPreviousAddItemDate(Date); NavigationManager.SelectedWeightCategoryIdentifier = weightCategory.Identifier; }, delegate { _onSaved?.Invoke(); this.RemoveViewModel(); if (_showViewGradeSnackbarAfterSaving) { try { BareSnackbar.Make(PowerPlannerResources.GetString("String_GradeAdded"), PowerPlannerResources.GetString("String_ViewGrades"), delegate { try { TelemetryExtension.Current?.TrackEvent("ClickedSnackbarViewGrades"); MainScreenViewModel.ViewClass(SelectedWeightCategory.Class, ClassViewModel.ClassPages.Grades); } catch (Exception ex) { TelemetryExtension.Current?.TrackException(ex); } }).Show(); } catch (Exception ex) { TelemetryExtension.Current?.TrackException(ex); } } }); });
private void ShowSnackbar(BareSnackbar snackbar) { UIView snackbarContainer = new UIView() { TranslatesAutoresizingMaskIntoConstraints = false, BackgroundColor = UIColor.Black, Alpha = 0 }; snackbarContainer.Layer.CornerRadius = 5; this.AddSubview(snackbarContainer); snackbarContainer.StretchWidth(this, left: 12, right: 12); snackbarContainer.PinToBottom(this, bottom: 12 + (int)BottomOffset); UILabel label = new UILabel() { TranslatesAutoresizingMaskIntoConstraints = false, Text = snackbar.Message, Font = UIFont.PreferredCaption1, TextColor = UIColor.White }; snackbarContainer.AddSubview(label); label.StretchHeight(snackbarContainer, top: 12, bottom: 12); if (snackbar.ButtonText == null) { label.StretchWidth(snackbarContainer, left: 12, right: 12); } else { UIButton button = new UIButton() { TranslatesAutoresizingMaskIntoConstraints = false, Font = UIFont.PreferredCaption1.Bold() }; button.SetTitle(snackbar.ButtonText, UIControlState.Normal); button.SetTitleColor(ButtonTextColor, UIControlState.Normal); snackbarContainer.AddSubview(button); button.StretchHeight(snackbarContainer, top: 12, bottom: 12); button.TouchUpInside += delegate { try { SnackbarManager.Close(snackbar); // Make sure to remove it snackbar.ButtonCallback(); } catch { } }; snackbarContainer.AddConstraints(NSLayoutConstraint.FromVisualFormat("H:|-12-[message]->=12-[button]-12-|", NSLayoutFormatOptions.SpacingEdgeToEdge, null, new NSDictionary( "message", label, "button", button))); } _currentSnackbar = snackbarContainer; UIView.Animate(duration: 0.5, delegate { snackbarContainer.Alpha = 1; }); }