Some how is it possible to get data from realm partially, a major part of android screen's can't afford to show more than 10-20 items so it's unnecessary to loadup 1000 rows when the user will see just 10-20. So I found a solution to how to fetch data partially like so:
FetchDocumentsCommand = new MvxCommand(
() =>
{
if (//Here I need to find a way to get data for example if I had it as pages from page 1/2/3)
{
//The load would execute for some specific page and add it to an ObservableCollection
//So it becomes less laggy
FetchDocumentTask = MvxNotifyTask.Create(LoadDocuments);
RaisePropertyChanged(() => FetchDocumentTask);
}
});
The problem comes when I try to fetch data from Realm for me it looks like this
private async Task LoadDocuments()
{
var docs = _documentService.GetRealmDocuments();
Documents.AddRange(docs);
}
public IEnumerable<Document> GetRealmDocuments()
{
return RealmService.Realm.All<Document>();
}
My question here can I some how make it less paginated as I get it from realm?
Realm objects are lazily loaded so there is essentially no difference between loading 10 objects or 1000. From the documentation
Since queries in Realm are lazy, performing this sort of paginating behavior isn’t necessary at all, as Realm will only load objects from the results of the query once they are explicitly accessed.
If you do want pagination for some UI feature it's just a matter of populating a results object and then only accesssing the quantity of data you need. Conceptually it would look something like this
// load the dogs and only display the first 5
let dogs = realm.objects(Dog.self)
for i in 0..<5 {
let dog = dogs[i]
// display dog
}
Something to keep in mind though - Realm results objects do not guarantee ordering so you should add some kind of ordering when reading objects in
let dogs = realm.objects(Dog.self).sorted(by: "dog_name")
that will keep your ordering in place as dogs are added, modified or removed.