protected override void OnNavigatedTo(NavigationEventArgs e) { Window.Current.CoreWindow.KeyDown += CoreWindow_KeyPressEvent; stillOnThePage = true; segment = e.Parameter as WorkoutSegment; nameBox.PlaceholderText = segment.Name; nameBox.Text = segment.Name; nameBox.SelectionStart = nameBox.MaxLength - 1; nameBox.SelectionLength = 0; reps = segment.Reps; seconds = segment.Seconds; doubleSidedToggle.IsChecked = segment.DoubleSided; UpdatePicture(); UpdateRepsLabel(); UpdateSecondsLabel(); var currentView = SystemNavigationManager.GetForCurrentView(); currentView.AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible; currentView.BackRequested += CurrentView_BackRequested; }
protected override void OnNavigatedTo(NavigationEventArgs e) { if (!loaded) { if (e.Parameter != null && e.Parameter is Workout) { workout = e.Parameter as Workout; nameBox.Text = workout.Name; } else { workout = new Workout(); WorkoutManager.Workouts.Add(workout); #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed WorkoutManager.SaveWorkout(workout); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed ((App)Application.Current).WasThatComplicatedNavigationalMessFromANewWorkout = true; } workoutDefaultName = $"Workout {WorkoutManager.Workouts.IndexOf(workout)+1}"; listView.ItemsSource = workout.Segments; if (workout.Name == null) { nameBox.Text = workoutDefaultName; workout.Name = workoutDefaultName; } nameBox.PlaceholderText = workoutDefaultName; nameBox.SelectionStart = nameBox.MaxLength - 1; nameBox.SelectionLength = 0; loaded = true; } else if (PendingDeletion != null) { workout.Segments.Remove(PendingDeletion); PendingDeletion = null; } Window.Current.CoreWindow.KeyDown += CoreWindow_KeyPressEvent; var currentView = SystemNavigationManager.GetForCurrentView(); currentView.AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible; currentView.BackRequested += CurrentView_BackRequested; }
private async static Task <Workout> GetWorkoutFromData(string data) { var lines = data.Split('\n'); if (lines.Length < 1) { return(null); } Workout workout = new Workout(); workout.Name = lines[0]; var finishedDates = false; var startIndex = 1; while (!finishedDates) { if (lines[startIndex] == "END DATES") { finishedDates = true; } else { if (long.TryParse(lines[startIndex], out long result)) { try { workout.Dates.Add(new DateTime(result)); } catch { #if DEBUG throw new Exception("Import or cached date processing exception - did the value of result overflow DateTime?"); #endif } } } startIndex += 1; } for (int i = startIndex; i < lines.Length; i += 5) { var segment = new WorkoutSegment(); try { segment.Name = lines[i]; segment.Reps = int.Parse(lines[i + 1]); segment.Seconds = int.Parse(lines[i + 2]); segment.DoubleSided = bool.Parse(lines[i + 3]); var line5 = lines[i + 4]; if (!string.IsNullOrEmpty(line5)) { var bitmap = await GetBitmapFromBase64(line5); if (bitmap != null) { segment.SetImage(bitmap); } } } catch { continue; } workout.Segments.Add(segment); } return(workout); }