I'm looking for a way to get my data sorted into a RecyclerView. At this moment I'm using the priority method for this, but I know that it is better to apply a orderByChild
or orderByValue
method to achieve this. I just cannot find how to do this properly.
My (relevant) data structure is the following (bolt format):
path /events/{event}/GeneralInfo is GeneralInfo{}
path /events/{event}/instances/{instance} is Instance{}
type GeneralInfo {
owner : KeyString,
name : ShortNameString | Null,
color : Number | Null,
description : NoteString | Null,
shared : Boolean | Null,
startDate : DateString,
endDate : DateString,
instances: Map<KeyString, Boolean>,
logoAvailable : Boolean | Null
}
type Instance {
eventKey : KeyString,
startDateTime : DateString,
endDateTime : DateString,
note : String | Null,
}
type KeyString extends String {
validate() { this.length > 0 && this.length <= 255 }
}
type DateString extends String {
validate() { this.length == 12 }
}
type ShortNameString extends String {
validate() { this.length >= 0 && this.length <= 32 }
}
The FirebaseRecyclerAdapter is currently initialized as follows:
Query q = getGeneralInfo( eventKey ).child( "instances" ).orderByPriority();
mAdapter = new FirebaseRecyclerAdapter<Boolean, InstanceViewHolder>(Boolean.class, R.layout.instance_card, InstanceViewHolder.class, q) {
@Override
protected void populateViewHolder(final InstanceViewHolder viewHolder, Boolean model, final int position) {
getInstanceByKey(mEventKey, refKey).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Instance i = dataSnapshot.getValue(Instance.class);
....
Note that I use an index key field (the field with the Boolean) to retrieve the actual data. The index field is currently sorted (using priorities).
I would like to sort directly on the instances (to make things less complicated and be able to remove the use of priorities).
p.s. Although it may seem that the data is not normalized, this is the case: the /events/{event} path is never used to retrieve data. This is only done to keep some overview.