private void OnBleStatusChanged(char[] obj) { if (obj.Length > 0) { AirpodsInfo airpodsInfo = _airpodsBleParser.Parse(obj); AirpodsInfo = new AirpodsInfoModel(airpodsInfo); _changeTrayIcon[AirpodsInfo.BatteryStatus].Invoke(); if (isFirstTime && AirpodsInfo.IsCaseOpen) { isFirstTime = false; NormalizeAction(); } if (!AirpodsInfo.IsCaseOpen) { isFirstTime = true; } } else { isFirstTime = true; AirpodsInfo = new AirpodsInfoModel(); TrayIconDefault.Invoke(); } }
public MainViewModel(AirpodsBleParser airpodsBleParser) { _airpodsBleParser = airpodsBleParser; _changeTrayIcon = new ConcurrentDictionary <BatteryPercentStatus, Action>(); _changeTrayIcon.TryAdd(BatteryPercentStatus.BatteryUndetermined, () => TrayIconDefault.Invoke()); _changeTrayIcon.TryAdd(BatteryPercentStatus.Battery100Percent, () => TrayIcon100Percent()); _changeTrayIcon.TryAdd(BatteryPercentStatus.Battery75Percent, () => TrayIcon75Percent()); _changeTrayIcon.TryAdd(BatteryPercentStatus.Battery50Percent, () => TrayIcon50Percent()); _changeTrayIcon.TryAdd(BatteryPercentStatus.Battery30Percent, () => TrayIcon30Percent()); _changeTrayIcon.TryAdd(BatteryPercentStatus.Battery15Percent, () => TrayIcon15Percent()); _bleScannerJob = new BleScannerJob(new Action <char[]>(OnBleStatusChanged)); OpenClickCommand = new RelayCommand <object>(e => OpenClick(), p => true); SettingsClickCommand = new RelayCommand <object>(e => { }, p => true); ExitClickCommand = new RelayCommand <object>(e => ExitClick(), p => true); TrayIconClickCommand = new RelayCommand <WindowState>(e => ToggleNormalizeMinimize(e), p => true); TrayIconDoubleClickCommand = new RelayCommand <WindowState>(e => ToggleNormalizeMinimize(e), p => true); AirpodsInfo = new AirpodsInfoModel(); }