Ejemplo n.º 1
0
        private static void _OnStoreChanged(object sender, NSNotificationEventArgs e)
        {
            if (_valuesChangedHandlers != null)
            {
                var reason = (NSUbiquitousKeyValueStoreChangeReasonValues)Enum.ToObject(
                    typeof(NSUbiquitousKeyValueStoreChangeReasonValues),
                    Convert.ToInt32(e.userInfo[NSUbiquitousKeyValueStore.ChangeReasonKey]));

                object[]            keys    = e.userInfo[NSUbiquitousKeyValueStore.ChangedKeysKey] as object[];
                iCloudPrefsChange[] changes = new iCloudPrefsChange[keys.Length];

                for (int i = 0; i < keys.Length; i++)
                {
                    string key = keys[i] as string;

                    // get old value
                    object oldValue = _userDefaults.Object(USER_DEFAULTS_PREFIX + key);
                    if ((oldValue is int) || (oldValue is long))
                    {
                        oldValue = Convert.ToInt32(oldValue);
                    }
                    else if ((oldValue is double) || (oldValue is float))
                    {
                        oldValue = (float)Convert.ToDouble(oldValue);
                    }

                    // clean new value, and set it in cache
                    object newValue = store.Object(key);
                    if (newValue == null)
                    {
                        _userDefaults.RemoveObject(USER_DEFAULTS_PREFIX + key);
                    }
                    else if (newValue is string)
                    {
                        _userDefaults.SetObject(newValue, USER_DEFAULTS_PREFIX + key);
                    }
                    else if ((newValue is int) || (newValue is long))
                    {
                        // in case of long, convert it to int first
                        newValue = Convert.ToInt32(newValue);
                        _userDefaults.SetInteger((int)newValue, USER_DEFAULTS_PREFIX + key);
                    }
                    else if ((newValue is double) || (newValue is float))
                    {
                        // in case of double, convert it to float first
                        newValue = (float)Convert.ToDouble(newValue);
                        _userDefaults.SetDouble((float)newValue, USER_DEFAULTS_PREFIX + key);
                    }

                    changes[i] = new iCloudPrefsChange(key, newValue, oldValue);
                }

                _valuesChangedHandlers(null, new iCloudPrefsChangedEventArgs(reason, changes));
            }
        }
Ejemplo n.º 2
0
    /*
     * Restarts tracking
     */
    public void Restart()
    {
        string version = (NSString)NSBundle.MainBundle.InfoDictionary.ObjectForKey(new NSString("CFBundleVersion"));

        NSUserDefaults userDefaults = NSUserDefaults.StandardUserDefaults;

        userDefaults.SetString(version, CURRENT_VERSION);
        userDefaults.SetDouble(DateTime.Now.ToOADate(), FIRST_USE_DATE);
        userDefaults.SetInt(1, USE_COUNT);
        userDefaults.SetInt(0, SIGNIFICANT_EVENT_COUNT);
        userDefaults.SetBool(false, RATED_CURRENT_VERSION);
        userDefaults.SetBool(false, DECLINED_TO_RATE);
        userDefaults.SetDouble(0, REMINDER_REQUEST_DATE);
    }
Ejemplo n.º 3
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            LePreferencias();

            txtNome.ShouldReturn += (textField) => {
                txtNome.ResignFirstResponder();
                return(true);
            };

            btnLer.TouchUpInside += (object sender, EventArgs e) => {
                LePreferencias();
            };

            btnGravar.TouchUpInside += (object sender, EventArgs e) => {
                prefs.SetBool(boolSwitch.On, "habilitado");
                prefs.SetString(txtNome.Text, "user");
                prefs.SetFloat(floatSlider.Value, "slider");
                prefs.SetInt(Convert.ToInt32(lblInt.Text), "int");
                prefs.SetDouble(dtPicker.Date.SecondsSinceReferenceDate, "data");
            };

            intStepper.ValueChanged += (object sender, EventArgs e) => {
                lblInt.Text = intStepper.Value.ToString();
            };
        }
Ejemplo n.º 4
0
        public void SetValue(string key, object anyValue)
        {
            Type valueType = anyValue.GetType();

            if (valueType == typeof(string))
            {
                UserDefaults.SetString((string)anyValue, key);
            }
            else if (valueType == typeof(int))
            {
                UserDefaults.SetInt((int)anyValue, key);
            }
            else if (valueType == typeof(bool))
            {
                UserDefaults.SetBool((bool)anyValue, key);
            }
            else if (valueType == typeof(float))
            {
                UserDefaults.SetFloat((float)anyValue, key);
            }
            else if (valueType == typeof(double))
            {
                UserDefaults.SetDouble((double)anyValue, key);
            }
            else if (valueType == typeof(long))
            {
                UserDefaults.SetValueForKey(new NSNumber((long)anyValue), new NSString(key));
            }
            else
            {
                Log.Error(INCORRECT_VALUE_TYPE_ERROR);
            }
            UserDefaults.Synchronize();
        }
Ejemplo n.º 5
0
        partial void calendarButtonTapped(UIKit.UIButton sender)
        {
            Console.WriteLine("Calendar Tapped");
            var startTime = _startTime;
            var dialog    = new DatePickerDialog();

            dialog.Show("Start date", "Done", "Cancel", UIDatePickerMode.Date, (dt) => {
                _startTime    = dt;
                var endDialog = new DatePickerDialog();
                endDialog.Show("End date", "Done", "Cancel", UIDatePickerMode.Date, (endTime) => {
                    _endTime = endTime;
                    if (_startTime > _endTime)
                    {
                        _endTime = _startTime.AddDays(7);
                    }
                    timeLabel.Text = $"{_startTime.ToShortDateString()}-{_endTime.ToShortDateString()}";
                    _plist.SetDouble(_startTime.GetUnixEpoch(), "startDate");
                    _plist.SetDouble(_endTime.GetUnixEpoch(), "endDate");

                    InitializeDatabase();
                }, _endTime);
            }, startTime);
        }
Ejemplo n.º 6
0
        public bool SetLong(string key, long val)
        {
            try
            {
                // Apple now recommends you *don't* call Synchronize as it will periodically happen
                // https://docs.microsoft.com/en-us/xamarin/ios/app-fundamentals/user-defaults
                _defaults.SetDouble(val, key);
                return(true);
            }
            catch (Exception e)
            {
                Logger.Error($"Error Setting Long UserSetting {key} - {e.Message}", e);
            }

            return(false);
        }
Ejemplo n.º 7
0
    void IncrementSignificantEventCount()
    {
        // get the app's version
        string version = CurrentVersion;

        // get the version number that we've been tracking
        NSUserDefaults userDefaults    = NSUserDefaults.StandardUserDefaults;
        string         trackingVersion = userDefaults.StringForKey(CURRENT_VERSION);

        if (string.IsNullOrEmpty(trackingVersion))
        {
            trackingVersion = version;
            userDefaults.SetString(version, CURRENT_VERSION);
        }

        if (settings.Debug)
        {
            Debug.WriteLine("APPIRATER Tracking version: {0}", trackingVersion);
        }

        if (trackingVersion == version)
        {
            // check if the first use date has been set. if not, set it.
            double timeInterval = userDefaults.DoubleForKey(FIRST_USE_DATE);
            if (timeInterval == 0)
            {
                timeInterval = DateTime.Now.ToOADate();
                userDefaults.SetDouble(timeInterval, FIRST_USE_DATE);
            }

            // increment the significant event count
            int sigEventCount = userDefaults.IntForKey(SIGNIFICANT_EVENT_COUNT);
            sigEventCount++;
            userDefaults.SetInt(sigEventCount, SIGNIFICANT_EVENT_COUNT);
            if (settings.Debug)
            {
                Debug.WriteLine("APPIRATER Significant event count: {0}", sigEventCount);
            }
        }
        else
        {
            Restart();
        }

        userDefaults.Synchronize();
    }
Ejemplo n.º 8
0
 /// <summary>
 /// Sets the user session.
 /// </summary>
 /// <param name="userModel">User model.</param>
 public static void  SetUserSession(User userModel)
 {
     try
     {
         if (userModel != null)
         {
             _user = NSUserDefaults.StandardUserDefaults;
             _user.SetInt(userModel.USER_ID, "USER_ID");
             _user.SetString(userModel.USER_TYPE, "USER_TYPE");
             _user.SetString(userModel.USER_NAME, "USER_NAME");
             _user.SetString(userModel.SURNAME, "SURNAME");
             _user.SetString(userModel.EMAIL, "EMAIL");
             _user.SetString(userModel.MOBILE, "MOBILE");
             _user.SetString(userModel.API_TOKEN, "API_TOKEN");
             _user.SetString(userModel.HELPLINE, "HELPLINE");
             _user.SetDouble(userModel.MIN_PRICE, "MIN_PRICE");
             _user.Synchronize();
         }
     }
     catch (Exception ex)
     {
         Crashes.TrackError(ex);
     }
 }
Ejemplo n.º 9
0
        public override void Clicked(UIAlertView alertview, int buttonIndex)
        {
            NSUserDefaults userDefaults = NSUserDefaults.StandardUserDefaults;

            switch (buttonIndex)
            {
            case 0:
                // they don't want to rate it
                userDefaults.SetBool(true, DECLINED_TO_RATE);
                userDefaults.Synchronize();
                break;

            case 1:
                // they want to rate it
                owner.RateApp();
                break;

            case 2:
                // remind them later
                userDefaults.SetDouble(DateTime.Now.ToOADate(), REMINDER_REQUEST_DATE);
                userDefaults.Synchronize();
                break;
            }
        }
Ejemplo n.º 10
0
 public void SetUserId(double userId)
 {
     userDefaults.SetDouble(userId, UserIdKey);
     userDefaults.Synchronize();
 }
Ejemplo n.º 11
0
 protected void SetDouble(string key, double value)
 {
     defs.SetDouble(value, key);
 }
Ejemplo n.º 12
0
 static public void SaveSetting(string name, double val)
 {
     g_prefs.SetDouble(val, name);
     g_prefs.Synchronize();
 }
        private void SetItem(string key, object value)
        {
            if (value == null)
            {
                if (IsRoaming)
                {
                    _store.Remove(key);
                }
                else
                {
                    _defaults.RemoveObject(key);
                }
            }
            else
            {
                TypeCode code = Type.GetTypeCode(value.GetType());
                switch (code)
                {
                case TypeCode.String:
                    if (IsRoaming)
                    {
                        _store.SetString(key, value.ToString());
                    }
                    else
                    {
                        _defaults.SetString(value.ToString(), key);
                    }
                    break;

                case TypeCode.Int32:
                    if (IsRoaming)
                    {
                        _store.SetLong(key, (long)value);
                    }
                    else
                    {
                        _defaults.SetInt((int)value, key);
                    }
                    break;

                case TypeCode.Double:
                    if (IsRoaming)
                    {
                        _store.SetDouble(key, (double)value);
                    }
                    else
                    {
                        _defaults.SetDouble((double)value, key);
                    }
                    break;

                case TypeCode.Single:
                    if (IsRoaming)
                    {
                        _store.SetDouble(key, (double)value);
                    }
                    else
                    {
                        _defaults.SetFloat((float)value, key);
                    }
                    break;

                case TypeCode.Boolean:
                    if (IsRoaming)
                    {
                        _store.SetBool(key, (bool)value);
                    }
                    else
                    {
                        _defaults.SetBool((bool)value, key);
                    }
                    break;

                default:
                    if (IsRoaming)
                    {
                        _store.SetValueForKey(IOSTypeConverter.ConvertToNSObject(value), new NSString(key));
                    }
                    else
                    {
                        _defaults.SetValueForKey(IOSTypeConverter.ConvertToNSObject(value), new NSString(key));
                    }
                    break;
                }
            }
        }
Ejemplo n.º 14
0
 public void SetDouble(string key, double value)
 {
     _prefs.SetDouble(value, key);
     _prefs.Synchronize();
 }
Ejemplo n.º 15
0
 /// <inheritdoc />
 public void SetDouble(string key, double value)
 {
     _standardDefaults.SetDouble(value, key);
     _standardDefaults.Synchronize();
 }
        private void SetItem(string key, object value)
        {
            if (value == null)
            {
                if (IsRoaming)
                {
                    _store.Remove(key);
                }
                else
                {
                    _defaults.RemoveObject(key);
                }
            }
            else
            {
                TypeCode code = Type.GetTypeCode(value.GetType());
                switch (code)
                {
                case TypeCode.String:
                    if (IsRoaming)
                    {
                        _store.SetString(key, value.ToString());
                    }
                    else
                    {
                        _defaults.SetString(value.ToString(), key);
                    }
                    break;

                case TypeCode.Int64:
                    if (IsRoaming)
                    {
                        _store.SetLong(key, (long)value);
                    }
                    else
                    {
                        _defaults.SetInt((nint)value, key);
                    }
                    break;

                case TypeCode.Int32:
                    if (IsRoaming)
                    {
                        _store.SetLong(key, (long)value);
                    }
                    else
                    {
                        _defaults.SetInt((int)value, key);
                    }
                    break;

                case TypeCode.Double:
                    if (IsRoaming)
                    {
                        _store.SetDouble(key, (double)value);
                    }
                    else
                    {
                        _defaults.SetDouble((double)value, key);
                    }
                    break;

                case TypeCode.Single:
                    if (IsRoaming)
                    {
                        _store.SetDouble(key, (double)value);
                    }
                    else
                    {
                        _defaults.SetFloat((float)value, key);
                    }
                    break;

                case TypeCode.Boolean:
                    if (IsRoaming)
                    {
                        _store.SetBool(key, (bool)value);
                    }
                    else
                    {
                        _defaults.SetBool((bool)value, key);
                    }
                    break;

                default:
                    if (IsRoaming)
                    {
                        _store[new NSString(key)] = IOSTypeConverter.ConvertToNSObject(value);
                    }
                    else
                    {
                        _defaults[key] = IOSTypeConverter.ConvertToNSObject(value);
                    }
                    break;
                }
            }

            if (_locality == ApplicationDataLocality.SharedLocal)
            {
                _defaults.Synchronize();
            }
        }