|
| 1 | +using Files.Enums; |
| 2 | +using Files.EventArguments; |
| 3 | +using Files.Models.JsonSettings; |
| 4 | +using Microsoft.AppCenter.Analytics; |
| 5 | +using System; |
| 6 | + |
| 7 | +namespace Files.Services.Implementation |
| 8 | +{ |
| 9 | + public class PaneSettingsService : BaseObservableJsonSettingsModel, IPaneSettingsService |
| 10 | + { |
| 11 | + public const string ContentKey = "PaneContent"; |
| 12 | + public const string HorizontalSizePxKey = "PaneHorizontalSizePx"; |
| 13 | + public const string VerticalSizePxKey = "PaneVerticalSizePx"; |
| 14 | + public const string MediaVolumeKey = "PaneMediaVolume"; |
| 15 | + public const string ShowPreviewOnlyKey = "ShowPreviewOnly"; |
| 16 | + |
| 17 | + public PaneContents Content |
| 18 | + { |
| 19 | + get => Get(PaneContents.None); |
| 20 | + set => Set(value); |
| 21 | + } |
| 22 | + |
| 23 | + public double HorizontalSizePx |
| 24 | + { |
| 25 | + get => Math.Max(100d, Get(300d)); |
| 26 | + set => Set(Math.Max(100d, value)); |
| 27 | + } |
| 28 | + public double VerticalSizePx |
| 29 | + { |
| 30 | + get => Math.Max(100d, Get(250d)); |
| 31 | + set => Set(Math.Max(100d, value)); |
| 32 | + } |
| 33 | + |
| 34 | + public double MediaVolume |
| 35 | + { |
| 36 | + get => Math.Min(Math.Max(Get(1d), 0d), 1d); |
| 37 | + set => Set(Math.Max(0d, Math.Min(value, 1d))); |
| 38 | + } |
| 39 | + |
| 40 | + public bool ShowPreviewOnly |
| 41 | + { |
| 42 | + get => Get(false); |
| 43 | + set => Set(value); |
| 44 | + } |
| 45 | + |
| 46 | + public PaneSettingsService(ISettingsSharingContext settingsSharingContext) |
| 47 | + => RegisterSettingsContext(settingsSharingContext); |
| 48 | + |
| 49 | + public void ReportToAppCenter() |
| 50 | + => Analytics.TrackEvent($"{nameof(ShowPreviewOnly)}, {ShowPreviewOnly}"); |
| 51 | + |
| 52 | + public override void RaiseOnSettingChangedEvent(object sender, SettingChangedEventArgs e) |
| 53 | + { |
| 54 | + if (e.settingName is nameof(ShowPreviewOnly)) |
| 55 | + { |
| 56 | + Analytics.TrackEvent($"{e.settingName} {e.newValue}"); |
| 57 | + } |
| 58 | + base.RaiseOnSettingChangedEvent(sender, e); |
| 59 | + } |
| 60 | + |
| 61 | + private void RaiseOnSettingChangedEvent(string propertyName, object newValue) |
| 62 | + { |
| 63 | + string settingName = propertyName switch |
| 64 | + { |
| 65 | + nameof(Content) => ContentKey, |
| 66 | + nameof(HorizontalSizePx) => HorizontalSizePxKey, |
| 67 | + nameof(VerticalSizePxKey) => VerticalSizePxKey, |
| 68 | + nameof(MediaVolume) => MediaVolumeKey, |
| 69 | + nameof(ShowPreviewOnly) => ShowPreviewOnlyKey, |
| 70 | + _ => throw new InvalidOperationException(), |
| 71 | + }; |
| 72 | + base.RaiseOnSettingChangedEvent(this, new SettingChangedEventArgs(settingName, newValue)); |
| 73 | + } |
| 74 | + } |
| 75 | +} |
0 commit comments