/// <summary> /// Inializes the AwayFromPCDialog. /// </summary> /// <param name="storageHandler">Handles reading and writing from/to the csv files</param> /// <param name="appStateTracker">Tracks the state of the app</param> /// <param name="lastLocked">The time when the machine was locked</param> public AwayFromPCDialog(StorageHandler storageHandler, AppStateTracker appStateTracker, DateTime lastLocked) { InitializeComponent(); FromDate = lastLocked; ToDate = DateTime.Now; StorageHandler = storageHandler; AppStateTracker = appStateTracker; Label.Content = "What were you doing since " + FromDate.ToShortTimeString() + "?"; TimeElapsed.Content = (ToDate - FromDate).ToString().Substring(0, 8); // Load the last acitvities so that they can be displayed in the dropdown menu Activities = StorageHandler.GetLastActivitiesGrouped().Select(rg => new CustomComboBoxItem() { Name = rg.Key, Selectable = true }).ToList(); DefaultName = AppStateTracker.CurrentActivity?.Name ?? Activities.FirstOrDefault()?.Name ?? ""; if (AppStateTracker.CurrentActivity != null && !Activities.Any(a => a.Name.Equals(DefaultName))) { Activities.Insert(0, new CustomComboBoxItem() { Name = DefaultName, Selectable = true }); } // Make only the first 5 options visible. The other should still be loaded so that autocomplete works for (int i = 0; i < Activities.Count(); i++) { Activities[i].Visible = i < 5 ? "Visible" : "Collapsed"; } // Inserst a unselectable template at the top of the list. // This should serve as an example on how to input activities. Activities.Insert(0, new CustomComboBoxItem() { Name = "Activity - Subactivity", Selectable = false }); ComboBox.ItemsSource = Activities; ComboBox.SelectedItem = Activities.Where(a => a.Name.Equals(DefaultName)).FirstOrDefault(); }
/// <summary> /// The activity dialog shown in the bottom right corner asking the users if he is still working on the same acitivity. /// </summary> /// <param name="storageHandler">Handles reading and writing from/to the csv files</param> /// <param name="appStateTracker">Tracks the state of the app</param> /// <param name="focusToast">True, if the dialog should be focused, otherwise False</param> public ActivityDialog(StorageHandler storageHandler, AppStateTracker appStateTracker, bool focusToast) { InitializeComponent(); StorageHandler = storageHandler; AppStateTracker = appStateTracker; ToDate = DateTime.Now; // Move toast to the bottom right Rect DesktopWorkingArea = SystemParameters.WorkArea; Left = DesktopWorkingArea.Right - Width - 15; Top = DesktopWorkingArea.Bottom - Height - 12; // Load the last acitvities so that they can be displayed in the dropdown menu Activities = StorageHandler.GetLastActivitiesGrouped().Select(rg => new CustomComboBoxItem() { Name = rg.Key, Selectable = true }).ToList(); DefaultName = AppStateTracker.CurrentActivity?.Name ?? Activities.FirstOrDefault()?.Name ?? ""; if (AppStateTracker.CurrentActivity != null && !Activities.Any(a => a.Name.Equals(DefaultName))) { Activities.Insert(0, new CustomComboBoxItem() { Name = DefaultName, Selectable = true }); } // Make only the first 5 options visible. The other should still be loaded so that autocomplete works for (int i = 0; i < Activities.Count(); i++) { Activities[i].Visible = i < 5 ? "Visible" : "Collapsed"; } // Inserst a unselectable template at the top of the list. // This should serve as an example on how to input activities. Activities.Insert(0, new CustomComboBoxItem() { Name = "Activity - Subactivity", Selectable = false }); ComboBox.ItemsSource = Activities; ComboBox.SelectedItem = Activities.Where(a => a.Name.Equals(DefaultName)).FirstOrDefault(); TextBlock2.Text = AppStateTracker.CurrentWindow?.Name.Trim() ?? "No window active"; Timeout = Settings.Default.TimeNotificationVisible * 1000; // Convert to ms if (Settings.Default.PlayNotificationSound) { SystemSounds.Hand.Play(); } if (focusToast) { ComboBox.Focus(); } DeletedSuggestion = false; DeletedSuggestionCounter = 0; TextLengthCounter = ComboBox.Text.Length; SetupClose(); }