Closed BenCherif closed 7 years ago
Hi BenCherif,
What version do you use ? RxJava2 or rxjava1 ?
For rxjava2 implementation => From the example in the code here, you can change the call to getAll() to something like :
public void loadPosts() {
Disposable d = postService.getAll(null /*or Filter*/, new SortingMode("id", SortType.DESCENDING))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribeWith(new DisposableSubscriber<Optional<List<Post>>>(){
@Override
public void onNext(Optional<List<Post>> items) {
mainView.updatePosts(items.get());
}
@Override
public void onError(Throwable e) {
e.printStackTrace();
}
@Override
public void onComplete() {
}
});
disposable.add(d);
}
The SortingMode object take 2 params, the first is the key on which you want to sort, and the second the order (DESCENDING or ASCENDING). Default is Ascending.
Thank you for using/testing the lib :)
Hi @tspoke ,
Thanks for your kind response , i'm using RxJava2 .
now i want to sort list by more then one field like this :
.findAllSorted("Linked", Sort.DESCENDING, "username", Sort.ASCENDING).sort("Activate", Sort.DESCENDING)
i hope your library support this function .
Kind regards
@BenCherif I'm afraid this is only supported by Filter for now...I can make an update to support SortingMode[] in requests. I didn't support them in the first time because it's more rare to use arrays of SortingMode than Filters. But that's an interesting feedback and I will take it into account for the next update.
Sorry ! I'll keep you updated about this feature !
Thanks , i'm waiting for it .
@BenCherif As soon the PR will be merged, you will be able to use arrays of SortingMode.
Btw, you need to implements this logic on your server side. I mean, locally realm will handle the sort/filtering easily but if you plug a distant API in a service, you have to use the filter and the sort too.
Ok thanks bro, i did the sorting on my server side but when there is no connection .i need to get data from realm so i need to sort them. anyway thanks for your help .Kind regards
I just release a new version : 3.0.2
You can get it :) Keep me informed if you have any problems with it ! Don't hesitate to give me feedback on the library in a general manner too. I would like to know if it fits your need :)
How i can add use "sortingMode" in getAll() method . i need an example .Thanks