Пример #1
0
		public override void onStart()
		{
			base.onStart();
			// Create Realm instance for the UI thread
			realm = Realm.DefaultInstance;
			allSortedDots = realm.@where(typeof(Dot)).between("x", 25, 75).between("y", 0, 50).findAllSortedAsync("x", RealmResults.SORT_ORDER_ASCENDING, "y", RealmResults.SORT_ORDER_DESCENDING);
			dotAdapter.updateList(allSortedDots);
			allSortedDots.addChangeListener(this);
		}
Пример #2
0
		public override void onStop()
		{
			base.onStop();
			// Remember to close the Realm instance when done with it.
			cancelAsyncTransaction();
			allSortedDots.removeChangeListener(this);
			allSortedDots = null;
			realm.close();
		}
        private void basicLinkQuery(Realm realm)
        {
            showStatus("\nPerforming basic Link Query operation...");
            showStatus("Number of persons: " + realm.allObjects(typeof(Person)).size());

            RealmResults <Person> results = realm.@where(typeof(Person)).equalTo("cats.name", "Tiger").findAll();

            showStatus("Size of result set: " + results.size());
        }
Пример #4
0
        public virtual void updateCities()
        {
            // Pull all the cities from the realm
            RealmResults <City> cities = realm.@where(typeof(City)).findAll();

            // Put these items in the Adapter
            mAdapter.Data = cities;
            mAdapter.notifyDataSetChanged();
            mGridView.invalidate();
        }
Пример #5
0
        public void ResultsShouldSendNotifications()
        {
            var query = _realm.All <Person>();

            RealmResults <Person> .ChangeSet            changes = null;
            RealmResults <Person> .NotificationCallback cb      = (s, c, e) => changes = c;

            using (query.SubscribeForNotifications(cb))
            {
                _realm.Write(() => _realm.CreateObject <Person>());

                TestHelpers.RunEventLoop(TimeSpan.FromMilliseconds(100));
                Assert.That(changes?.InsertedIndices, Is.EquivalentTo(new int[] { 0 }));
            }
        }
        private string complexQuery()
        {
            string status = "\n\nPerforming complex Query operation...";

            Realm realm = Realm.getInstance(this);

            status += "\nNumber of persons: " + realm.allObjects(typeof(Person)).size();

            // Find all persons where age between 7 and 9 and name begins with "Person".
            RealmResults <Person> results = realm.@where(typeof(Person)).between("age", 7, 9).beginsWith("name", "Person").findAll();            // Notice implicit "and" operation

            status += "\nSize of result set: " + results.size();

            realm.close();
            return(status);
        }
Пример #7
0
        protected internal override void onCreate(Bundle savedInstanceState)
        {
            base.onCreate(savedInstanceState);
            ContentView = R.layout.activity_my;

            RealmConfiguration realmConfig = (new RealmConfiguration.Builder(this)).build();

            Realm.deleteRealm(realmConfig);
            realm = Realm.getInstance(realmConfig);

            RealmResults <TimeStamp> timeStamps = realm.@where(typeof(TimeStamp)).findAll();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final MyAdapter adapter = new MyAdapter(this, R.id.listView, timeStamps, true);
            MyAdapter adapter  = new MyAdapter(this, R.id.listView, timeStamps, true);
            ListView  listView = (ListView)findViewById(R.id.listView);

            listView.Adapter = adapter;
            listView.OnItemLongClickListener = new OnItemLongClickListenerAnonymousInnerClassHelper(this, adapter);
        }
Пример #8
0
 public MyAdapter(Context context, int resId, RealmResults <TimeStamp> realmResults, bool automaticUpdate) : base(context, realmResults, automaticUpdate)
 {
 }
Пример #9
0
 private void RealmObjectChanged(RealmResults <Models.OrderItem> sender, RealmResults <Models.OrderItem> .ChangeSet changes, Exception error)
 {
     this.Items = sender.Where(x => x.Hidden == true);
 }
Пример #10
0
			internal virtual void updateList(RealmResults<Dot> dots)
			{
				this.dots = dots;
				notifyDataSetChanged();
			}
        private string complexReadWrite()
        {
            string status = "\nPerforming complex Read/Write operation...";

            // Open the default realm. All threads must use it's own reference to the realm.
            // Those can not be transferred across threads.
            Realm realm = Realm.getInstance(this);

            // Add ten persons in one transaction
            realm.beginTransaction();
            Dog fido = realm.createObject(typeof(Dog));

            fido.Name = "fido";
            for (int i = 0; i < 10; i++)
            {
                Person person = realm.createObject(typeof(Person));
                person.Id   = i;
                person.Name = "Person no. " + i;
                person.Age  = i;
                person.Dog  = fido;

                // The field tempReference is annotated with @Ignore.
                // This means setTempReference sets the Person tempReference
                // field directly. The tempReference is NOT saved as part of
                // the RealmObject:
                person.TempReference = 42;

                for (int j = 0; j < i; j++)
                {
                    Cat cat = realm.createObject(typeof(Cat));
                    cat.Name = "Cat_" + j;
                    person.Cats.add(cat);
                }
            }
            realm.commitTransaction();

            // Implicit read transactions allow you to access your objects
            status += "\nNumber of persons: " + realm.allObjects(typeof(Person)).size();

            // Iterate over all objects
            foreach (Person pers in realm.allObjects(typeof(Person)))
            {
                string dogName;
                if (pers.Dog == null)
                {
                    dogName = "None";
                }
                else
                {
                    dogName = pers.Dog.Name;
                }
                status += "\n" + pers.Name + ":" + pers.Age + " : " + dogName + " : " + pers.Cats.size();

                // The field tempReference is annotated with @Ignore
                // Though we initially set its value to 42, it has
                // not been saved as part of the Person RealmObject:
                assert(pers.TempReference == 0);
            }

            // Sorting
            RealmResults <Person> sortedPersons = realm.allObjects(typeof(Person));

            sortedPersons.sort("age", false);
            assert(realm.allObjects(typeof(Person)).last().Name == sortedPersons.first().Name);
            status += "\nSorting " + sortedPersons.last().Name + " == " + realm.allObjects(typeof(Person)).first().Name;

            realm.close();
            return(status);
        }
Пример #12
0
 public virtual void Subscribe(RealmResults <T> .NotificationCallback callback)
 {
     RealmInstance.All <T>().SubscribeForNotifications(callback);
 }
Пример #13
0
 public virtual void RemoveRange(RealmResults <T> range)
 {
     RealmInstance.RemoveRange(range);
 }