Exemple #1
0
        public override int Update(Android.Net.Uri uri, ContentValues values, string selection, string[] selectionArgs)
        {
            PrefModel model = GetPrefModelByUri(uri);

            if (model == null)
            {
                throw new InvalidOperationException("update prefModel is null");
            }
            switch (sUriMatcher.Match(uri))
            {
            case PREF_BOOLEAN:
                PersistBoolean(model.Name, values);
                break;

            case PREF_LONG:
                PersistLong(model.Name, values);
                break;

            case PREF_STRING:
                PersistString(model.Name, values);
                break;

            case PREF_INT:
                PersistInt(model.Name, values);
                break;

            case PREF_DATETIME:
                PersistDateTime(model.Name, values);
                break;

            default:
                throw new InvalidOperationException("update unsupported uri : " + uri);
            }
            return(0);
        }
Exemple #2
0
        public override ICursor Query(Android.Net.Uri uri, string[] projection, string selection, string[] selectionArgs, string sortOrder)
        {
            MatrixCursor cursor = null;
            PrefModel    model  = GetPrefModelByUri(uri);

            try
            {
                switch (sUriMatcher.Match(uri))
                {
                case PREF_BOOLEAN:
                    if (GetDPreference(model.Name).HasKey(model.Key))
                    {
                        cursor = PreferenceToCursor(new Java.Lang.Boolean((GetDPreference(model.Name).GetPrefBoolean(model.Key, false))));
                    }
                    break;

                case PREF_STRING:
                    if (GetDPreference(model.Name).HasKey(model.Key))
                    {
                        cursor = PreferenceToCursor(new Java.Lang.String((GetDPreference(model.Name).GetPrefString(model.Key, ""))));
                    }
                    break;

                case PREF_INT:
                    if (GetDPreference(model.Name).HasKey(model.Key))
                    {
                        cursor = PreferenceToCursor((Java.Lang.Integer)(GetDPreference(model.Name).GetPrefInt(model.Key, -1)));
                    }
                    break;

                case PREF_LONG:
                    if (GetDPreference(model.Name).HasKey(model.Key))
                    {
                        cursor = PreferenceToCursor((Java.Lang.Long)(GetDPreference(model.Name).GetPrefLong(model.Key, -1)));
                    }
                    break;

                case PREF_DATETIME:
                    if (GetDPreference(model.Name).HasKey(model.Key))
                    {
                        cursor = PreferenceToCursor((Java.Lang.Long)(GetDPreference(model.Name).GetPrefLong(model.Key, -1)));
                    }
                    break;
                }
                return(cursor);
            }
            catch (Exception exQuery)
            {
                for (int i = 0; i < 10; i++)
                {
                    Debug.WriteLine($"PreferenceProvider Query Exception: {exQuery.Message} ON pref: {sUriMatcher.Match(uri)}\nKey: {model.Key}");
                }
                throw exQuery;
            }
        }
Exemple #3
0
        public override int Delete(Android.Net.Uri uri, string selection, string[] selectionArgs)
        {
            switch (sUriMatcher.Match(uri))
            {
            case PREF_BOOLEAN:
            case PREF_LONG:
            case PREF_STRING:
            case PREF_INT:
            case PREF_DATETIME:
                PrefModel model = GetPrefModelByUri(uri);
                if (model != null)
                {
                    GetDPreference(model.Name).RemovePreference(model.Key);
                }
                break;

            default:
                throw new InvalidOperationException(" unsupported uri : " + uri);
            }
            return(0);
        }