Exemple #1
0
 public static void ViewNull <T>(this IReadonlyProperty <T?> me, Lifetime lifetime, Action <Lifetime> handler) where T : struct
 {
     me.View(lifetime, (lf, v) =>
     {
         if (v == null)
         {
             handler(lf);
         }
     });
 }
Exemple #2
0
 public static void ViewNotNull <T>(this IReadonlyProperty <T> me, Lifetime lifetime, Action <Lifetime, T> handler) where T : class
 {
     me.View(lifetime, (lf, v) =>
     {
         if (v != null)
         {
             handler(lf, v);
         }
     });
 }
        public MainWindowViewModel(
            [NotNull] IAppSettings appSettings
            )
        {
            Working      = new FieldProperty <bool>();
            OnlySave     = new FieldProperty <bool>();
            SavePlusMess = new FieldProperty <bool>(true);
            OnlyMess     = new FieldProperty <bool>();

            PopupBoxText  = new FieldProperty <string>(appSettings.PopupMessage);
            MessagesCount = new FieldProperty <int>(1);

            CurrentApk  = new FieldProperty <string>();
            CurrentSave = new FieldProperty <string>();

            BackupType = new DelegatedProperty <BackupType>(
                valueResolver: () => appSettings.BackupType,
                valueApplier: value => appSettings.BackupType = value
                ).DependsOn(appSettings, nameof(IAppSettings.BackupType));

            AppTheme = new DelegatedProperty <string>(
                valueResolver: () => appSettings.Theme,
                valueApplier: value => appSettings.Theme = value
                ).DependsOn(appSettings, nameof(IAppSettings.Theme));

            AlternativeSigning = new DelegatedProperty <bool>(
                valueResolver: () => appSettings.AlternativeSigning,
                valueApplier: value => appSettings.AlternativeSigning = value
                ).DependsOn(appSettings, nameof(IAppSettings.AlternativeSigning));

            NotificationsEnabled = new DelegatedProperty <bool>(
                valueResolver: () => appSettings.Notifications,
                valueApplier: value => appSettings.Notifications = value
                ).DependsOn(appSettings, nameof(IAppSettings.Notifications));

            Title = new DelegatedProperty <string>(
                valueResolver: FormatTitle,
                valueApplier: null
                ).DependsOn(CurrentApk).AsReadonly();

            EnIsChecked = new DelegatedProperty <bool>(
                valueResolver: () => Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName.ToLower() == "en",
                valueApplier: null
                ).AsReadonly();

            RuIsChecked = new DelegatedProperty <bool>(
                valueResolver: () => !EnIsChecked.Value,
                valueApplier: null
                ).DependsOn(EnIsChecked).AsReadonly();
        }
Exemple #4
0
        public static void View <T>(this IReadonlyProperty <T> me, Lifetime lifetime, Action <Lifetime, T> handler)
        {
            if (!lifetime.IsAlive)
            {
                return;
            }

            // nested lifetime is needed due to exception that could be thrown
            // while viewing a property change right at the moment of <param>lifetime</param>'s termination
            // but before <param>handler</param> gets removed
            var lf  = lifetime == Lifetime.Eternal ? lifetime : Lifetime.Define(lifetime).Lifetime;
            var seq = new SequentialLifetimes(lf);

            me.Advise(lf, v => handler(seq.Next(), v));
        }
Exemple #5
0
 public static void Compose <T1, T2>(this IReadonlyProperty <T1> first, Lifetime lifetime, IReadonlyProperty <T2> second, Action <T1, T2> composer)
 {
     first.Advise(lifetime, v =>
     {
         if (second.HasValue())
         {
             composer(v, second.Value);
         }
     });
     second.Advise(lifetime, v =>
     {
         if (first.HasValue())
         {
             composer(first.Value, v);
         }
     });
 }
Exemple #6
0
        public static void WhenFalse([NotNull] this IReadonlyProperty <bool> property, Lifetime lifetime, [NotNull] Action <Lifetime> handler)
        {
            if (property == null)
            {
                throw new ArgumentNullException(nameof(property));
            }

            if (handler == null)
            {
                throw new ArgumentNullException(nameof(handler));
            }

            property.View(lifetime, (lf, value) =>
            {
                if (!value)
                {
                    handler(lf);
                }
            });
        }
Exemple #7
0
        public static IReadonlyProperty <T> Compose <T1, T2, T>(this IReadonlyProperty <T1> first, Lifetime lifetime, IReadonlyProperty <T2> second, Func <T1, T2, T> composer)
        {
            var res = new ViewableProperty <T>();

            first.Advise(lifetime, v =>
            {
                if (second.HasValue())
                {
                    res.Value = composer(v, second.Value);
                }
            });
            second.Advise(lifetime, v =>
            {
                if (first.HasValue())
                {
                    res.Value = composer(first.Value, v);
                }
            });
            return(res);
        }
Exemple #8
0
 protected RdExtBase()
 {
     Connected = myExtWire.Connected;
 }
Exemple #9
0
 private static byte[] GetBytes(IReadonlyProperty <BitmapSource> property) => property.Value.ToBitmap().ToByteArray();
Exemple #10
0
 public new IActionCommand BindCanExecute <T>(IReadonlyProperty <T> property)
 {
     base.BindCanExecute(property);
     return(this);
 }
Exemple #11
0
 public static bool HasTrueValue(this IReadonlyProperty <bool> me)
 {
     return(me.Maybe.HasValue && me.Maybe.Value);
 }
Exemple #12
0
 public static bool HasValue <T>(this IReadonlyProperty <T> me)
 {
     return(me.Maybe.HasValue);
 }
Exemple #13
0
 public static IActionCommand <T> BindCanExecute <T, TProp>([NotNull] this IActionCommand <T> actionCommand, [NotNull] IReadonlyProperty <TProp> observable)
 {
     observable.PropertyChanged += (sender, args) => actionCommand.RaiseCanExecuteChanged();
     return(actionCommand);
 }
Exemple #14
0
 public IActionCommand <TParameter> BindCanExecute <T>(IReadonlyProperty <T> property)
 {
     property.PropertyChanged += BoundPropertyChanged;
     return(this);
 }