Beispiel #1
0
        void Set <T>(string key, T value)
        {
            lock (locker)
            {
                switch (value)
                {
                case string s:
                    UserDefaults.SetString(s, key);
                    break;

                case int i:
                    UserDefaults.SetInt(i, key);
                    break;

                case bool b:
                    UserDefaults.SetBool(b, key);
                    break;

                case long l:
                    var valueString = Convert.ToString(value, CultureInfo.InvariantCulture);
                    UserDefaults.SetString(valueString, key);
                    break;

                case double d:
                    UserDefaults.SetDouble(d, key);
                    break;

                case float f:
                    UserDefaults.SetFloat(f, key);
                    break;
                }
            }
        }
        protected void AddToTotals(double?distanceQuantity, DistanceUom?distanceUom, double?timeQuantity, TimeUom?timeUom,
                                   UserDefaults userDefaults, int quantity, bool isRest)
        {
            double?repDistance = null;
            double?repTime     = null;

            if (distanceQuantity.HasValue && distanceUom.HasValue)
            {
                repDistance = UnitConversions.ConvertDistance(distanceQuantity.Value, distanceUom.Value, userDefaults.DistanceUom) * quantity;
            }
            if (timeQuantity.HasValue && timeUom.HasValue)
            {
                repTime = UnitConversions.ConvertTime(timeQuantity.Value, timeUom.Value, userDefaults.TimeUom) * quantity;
            }

            if (repDistance.HasValue && repTime.HasValue)
            {
                TotalDistanceQuantity += repDistance.Value;
                TotalTimeQuantity     += repTime.Value;
            }
            else if (repDistance.HasValue)
            {
                TotalDistanceQuantity += repDistance.Value;
                TotalTimeQuantity     += (userDefaults.IsPaceDistancePerTime ? repDistance.Value / userDefaults.Pace : repDistance.Value * userDefaults.Pace);
            }
            else if (repTime.HasValue && !isRest)
            {
                TotalTimeQuantity     += repTime.Value;
                TotalDistanceQuantity += (userDefaults.IsPaceDistancePerTime ? repTime.Value * userDefaults.Pace : repTime.Value / userDefaults.Pace);
            }
            else
            {
                return; // could not get reliable values from repetition
            }
        }
Beispiel #3
0
        public static void CreateNewProfile(string name)
        {
            // Used internally for generating a temp profile
            if (name is null)
            {
                Profile = new UserDefaults()
                {
                    ProfileName         = defaultProfileName,
                    ImageHeight         = defaultImageHeight,
                    ImageWidth          = defaultWidth,
                    RootPaths           = new List <CategorizedPath>(),
                    Extensions          = new List <string>(),
                    IgnoredPrefixes     = new List <string>(),
                    WorkTraversalDepth  = defaultWorkTraversalDepth,
                    SubdirectoryAction  = SubdirectoryAction.SEPARATE,
                    IgnoredPrefixAction = IgnoredPrefixAction.IGNORE
                };
                return;
            }

            // Display scaling thing
            if (name == defaultProfileName)
            {
                App.ComicsWindow.UpdateDisplayScale();
            }

            if (Profile != null)
            {
                Profile.ProfileName = name;
                Properties.Settings.Default.CurrentProfile = name;
                SaveProfile();
            }
            else
            {
                Profile = new UserDefaults()
                {
                    ProfileName = name,
                    ImageHeight = defaultImageHeight,
                    ImageWidth  = defaultWidth,
                    RootPaths   = new List <CategorizedPath>()
                    {
                        new CategorizedPath()
                        {
                            Category = "Pictures", Path = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures)
                        }
                    },
                    Extensions = new List <string>()
                    {
                        ".jpg", ".jpeg", ".png", ".tiff", ".bmp", ".gif"
                    },
                    IgnoredPrefixes = new List <string>()
                    {
                        "~", "("
                    },
                    WorkTraversalDepth  = defaultWorkTraversalDepth,
                    SubdirectoryAction  = SubdirectoryAction.SEPARATE,
                    IgnoredPrefixAction = IgnoredPrefixAction.IGNORE
                };
            }
        }
Beispiel #4
0
 public CompletedWorkoutVM(CompletedWorkout model, UserDefaults defaults, bool includeReps) : base(model)
 {
     PlannedWorkoutId     = model.PlannedWorkoutId;
     CompletedDateTime    = model.CompletedDateTime.ToString(Constants.DateTimeOffsetFormatString);
     CompletedRepetitions = includeReps ? model.CompletedRepetitions?
                            .Select(x => new CompletedRepetitionVM(x, defaults)).OrderBy(x => x.Order).ToList() : null;
     WorkoutSummary = new CompletedWorkoutSummaryVM(model.CompletedRepetitions, defaults);
 }
 public PlannedWorkoutVM(PlannedWorkout model, UserDefaults defaults, bool includeReps) : base(model)
 {
     TimeOfDay          = model.TimeOfDay;
     ScheduledDate      = model.ScheduledDate.ToString(Constants.DateOnlyFormatString);
     Order              = model.Order;
     PlannedRepetitions = includeReps ? model.PlannedRepetitions?
                          .Select(x => new PlannedRepetitionVM(x, defaults)).OrderBy(x => x.Order).ToList() : null;
     WorkoutSummary = new PlannedWorkoutSummaryVM(model.PlannedRepetitions, defaults);
 }
Beispiel #6
0
 public void Remove(string key)
 {
     UserDefaults.RemoveObject(MakeKey(key));
     if (synchronizeOnUpdate)
     {
         UserDefaults.Synchronize();
     }
     observable.Observers.OnNext(new PreferenceChange(key));
 }
Beispiel #7
0
 void Set(string key, Action setter)
 {
     setter();
     if (synchronizeOnUpdate)
     {
         UserDefaults.Synchronize();
     }
     observable.Observers.OnNext(new PreferenceChange(key));
 }
Beispiel #8
0
 public void Remove(string key)
 {
     lock (locker)
     {
         if (UserDefaults[key] != null)
         {
             UserDefaults.RemoveObject(key);
         }
     }
 }
Beispiel #9
0
 private object GetRomListSearchDirectories(string key)
 {
     if (_romListSearchDirectories == null)
     {
         var userDefaults = UserDefaults.StringArrayForKey(key);
         _romListSearchDirectories = new INTV.Shared.Model.SearchDirectories(userDefaults);
         _romListSearchDirectories.CollectionChanged += HandleSearchDirectoriesChanged;
     }
     return(_romListSearchDirectories);
 }
Beispiel #10
0
 protected override void AddToTotals(CompletedRepetition repetition, UserDefaults userDefaults, bool isRest)
 {
     if (isRest)
     {
         AddToTotals(repetition.RestDistanceQuantity, repetition.RestDistanceUom, repetition.RestTimeQuantity, repetition.RestTimeUom, userDefaults, 1, isRest);
     }
     else
     {
         AddToTotals(repetition.DistanceQuantity, repetition.DistanceUom, repetition.TimeQuantity, repetition.TimeUom, userDefaults, 1, isRest);
     }
 }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            const string prefix = "com.toggl.timer";

            source.OnStartStop += (sender, e) => {
                if (WidgetDisabled)
                {
                    return;
                }
                WidgetDisabled = true;
                UIApplication.SharedApplication.OpenUrl(new NSUrl(prefix + "://" + TodayUrlPrefix + "/" + StartEntryUrlPrefix));
            };

            source.OnContinue += (sender, e) => {
                if (WidgetDisabled)
                {
                    return;
                }
                WidgetDisabled = true;
                var id = string.IsNullOrEmpty(source.SelectedCellId) ? new Guid().ToString() : source.SelectedCellId;
                UserDefaults.SetString(id, StartedEntryKey);
                UIApplication.SharedApplication.OpenUrl(new NSUrl(prefix + "://" + TodayUrlPrefix + "/" + ContinueEntryUrlPrefix));
            };

            source.Controller = this;
            tableView.Source  = source;
            tableView.RegisterClassForCellReuse(typeof(WidgetCell), WidgetCell.WidgetProjectCellId);
            tableView.Delegate = new TableViewDelegate();

            openAppBtn.TouchUpInside += (sender, e) => {
                if (WidgetDisabled)
                {
                    return;
                }
                WidgetDisabled      = true;
                openAppBtn.IsActive = false;
                UIApplication.SharedApplication.OpenUrl(new NSUrl(prefix + "://" + TodayUrlPrefix + "/"));
            };

            UpdateContent();

            UpdateTimeValue();

            if (isRunning)
            {
                // Start to check time
                Timer.Elapsed += (sender, e) => InvokeOnMainThread(UpdateTimeValue);
                Timer.Start();
            }
        }
Beispiel #12
0
        T Get <T>(string key, T defaultValue)
        {
            object value = null;

            lock (locker)
            {
                if (UserDefaults[key] == null)
                {
                    return(defaultValue);
                }

                switch (defaultValue)
                {
                case int i:
                    value = (int)(nint)UserDefaults.IntForKey(key);
                    break;

                case bool b:
                    value = UserDefaults.BoolForKey(key);
                    break;

                case long l:
                    var savedLong = UserDefaults.StringForKey(key);
                    value = Convert.ToInt64(savedLong, CultureInfo.InvariantCulture);
                    break;

                case double d:
                    value = UserDefaults.DoubleForKey(key);
                    break;

                case float f:
                    value = UserDefaults.FloatForKey(key);
                    break;

                case string s:
                    // the case when the string is not null
                    value = UserDefaults.StringForKey(key);
                    break;

                default:
                    // the case when the string is null
                    if (typeof(T) == typeof(string))
                    {
                        value = UserDefaults.StringForKey(key);
                    }
                    break;
                }
            }

            return((T)value);
        }
 public AbstractRepetitionVM(AbstractRepetition model, UserDefaults defaults = null)
 {
     Id = model.Id;
     DistanceQuantity     = model.DistanceQuantity;
     DistanceUom          = model.DistanceUom;
     TimeQuantity         = model.TimeQuantity;
     TimeUom              = model.TimeUom;
     Notes                = model.Notes;
     RestDistanceQuantity = model.RestDistanceQuantity;
     RestDistanceUom      = model.RestDistanceUom;
     RestTimeQuantity     = model.RestTimeQuantity;
     RestTimeUom          = model.RestTimeUom;
     Order                = model.Order;
     if (defaults is { })
        private void UpdateTimeValue()
        {
            // Periodically update content from UserDefaults
            var timeValue = UserDefaults.StringForKey(MillisecondsKey);

            if (!string.IsNullOrEmpty(timeValue))
            {
                var cell = (WidgetCell)tableView.CellAt(NSIndexPath.FromRowSection(0, 0));
                if (cell != null)
                {
                    cell.TimeValue = isAppOnBackground ? string.Empty : UserDefaults.StringForKey(MillisecondsKey);
                }
            }
        }
        private void UpdateContent()
        {
            // Check if user is logged
            if (!isUserLogged || !isAppActive)
            {
                tableView.Hidden   = true;
                openAppView.Hidden = false;
                return;
            }

            isRunning      = false;
            WidgetDisabled = false;

            // Get saved entries
            var timeEntryJson = UserDefaults.StringForKey(TimeEntriesKey);

            if (timeEntryJson != string.Empty)
            {
                entries.Clear();
                entries.AddRange(Newtonsoft.Json.JsonConvert.DeserializeObject <List <WidgetEntryData> > (timeEntryJson));
            }

            if (entries.Count > 0)
            {
                // Check running state
                foreach (var item in entries)
                {
                    isRunning = isRunning || item.IsRunning;
                }

                if (!isRunning)
                {
                    // Add empty cell at top
                    var emptyEntry = new WidgetEntryData {
                        IsEmpty = true
                    };
                    entries.Insert(0, emptyEntry);
                    entries.RemoveAt(entries.Count - 1);
                }
            }
            else
            {
                entries.Add(new WidgetEntryData {
                    IsEmpty = true
                });
            }

            tableView.ReloadData();
        }
Beispiel #16
0
        public void Clear()
        {
            lock (locker)
            {
                var items = UserDefaults.ToDictionary();

                foreach (var item in items.Keys)
                {
                    if (item is NSString nsString)
                    {
                        UserDefaults.RemoveObject(nsString);
                    }
                }
            }
        }
Beispiel #17
0
        public void RemoveAll()
        {
            var toNotify = Keys;

            foreach (var key in toNotify)
            {
                UserDefaults.RemoveObject(key);
            }

            if (synchronizeOnUpdate)
            {
                UserDefaults.Synchronize();
            }

            foreach (var key in toNotify)
            {
                observable.Observers.OnNext(new PreferenceChange(key));
            }
        }
        public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
        {
            // Override point for customization after application launch.
            // If not required for your application you can safely delete this method
            Container = new UnityContainer( );

            UserDefaults.SetIsAuthenticated(true);
            UserDefaults.SetInstanceUrl("http://192.168.108.219:57204/");
            KeyChainHelper.StoreTokenKeyChain(new Guid("476F624F-2238-4041-AC31-C78F4E1DE869"));

            string instanceUrl = UserDefaults.IsAuthenticated ? UserDefaults.InstanceUrl : "todo";
            string consumerKey = CoreConfig.TestConsumerKey.ToString( );

            Container.RegisterInstance(RestService.For <IApi>(ApiHelper.GetHttpClient(instanceUrl, consumerKey)));
            Container.RegisterType <IContactsDataSource, ContactsApiDataSource>("ContactsApiDataSource");
            Container.RegisterType <IGetContactsCallback, ContactsViewCallback>( );
            Container.RegisterType <IContactsDataSource, ContactsRepository>(new InjectionConstructor(new ResolvedParameter <IContactsDataSource>("ContactsApiDataSource")));

            return(true);
        }
        public AbstractSummaryVM(List <T> modelReps, UserDefaults userDefaults)
        {
            if (modelReps is null || modelReps.Count == 0)
            {
                return;
            }

            TotalDistanceUom = userDefaults.DistanceUom;
            TotalTimeUom     = userDefaults.TimeUom;

            modelReps.ForEach(x =>
            {
                AddToTotals(x, userDefaults, false);
                AddToTotals(x, userDefaults, true);
            });

            RepetitionIds  = modelReps.Select(x => x.Id).ToList();
            AveragePace    = UnitConversions.GetPaceAsString(TotalDistanceQuantity, TotalDistanceUom, TotalTimeQuantity, TotalTimeUom, userDefaults);
            AveragePaceUom = userDefaults.IsPaceDistancePerTime
                ? $"{userDefaults.DistanceUom}/{userDefaults.TimeUom}" : $"{userDefaults.TimeUom}/{userDefaults.DistanceUom}";
        }
Beispiel #20
0
 public void Set(string key, string value)
 => Set(key, () => UserDefaults.SetString(value, MakeKey(key)));
 public CompletedRepetitionVM(CompletedRepetition model, UserDefaults defaults = null) : base(model, defaults)
 {
     PlannedRepetitionId = model.PlannedRepetitionId;
 }
Beispiel #22
0
 public string GetString(string key, string defaultValue = null)
 => UserDefaults [key = MakeKey(key)] == null ? defaultValue : UserDefaults.StringForKey(key);
Beispiel #23
0
 public string [] GetStringArray(string key, string [] defaultValue = null)
 => UserDefaults [key = MakeKey(key)] == null
         ? defaultValue
         : UserDefaults.StringArrayForKey(key);
Beispiel #24
0
 public double GetDouble(string key, double defaultValue = 0.0)
 => UserDefaults [key = MakeKey(key)] == null ? defaultValue : UserDefaults.DoubleForKey(key);
Beispiel #25
0
 public long GetInt64(string key, long defaultValue = 0)
 => UserDefaults [key = MakeKey(key)] == null ? defaultValue : UserDefaults.IntForKey(key);
Beispiel #26
0
 public bool GetBoolean(string key, bool defaultValue = false)
 => UserDefaults [key = MakeKey(key)] == null ? defaultValue : UserDefaults.BoolForKey(key);
 protected abstract void AddToTotals(T repetition, UserDefaults userDefaults, bool isRest);
Beispiel #28
0
 public void Set(string key, double value)
 => Set(key, () => UserDefaults.SetDouble(value, MakeKey(key)));
Beispiel #29
0
 public void Set(string key, long value)
 => Set(key, () => UserDefaults.SetInt((nint)value, MakeKey(key)));
Beispiel #30
0
 public void Set(string key, bool value)
 => Set(key, () => UserDefaults.SetBool(value, MakeKey(key)));