android - Offline sort of FirebaseRecyclerAdapter -
i'm using firebaserecycleradapter retrieve data firebase database, , i've pretty worked out how retrieve data in order desire.
to avoid duplication , ease database maintenance, i'd add key database entry allows me return queries based on key. storing data twice. once see, , once if user had joined group (under groupname).
to return query based on group, original search follows:
databasereference.child(groupname).child("exerciseid"+mexerciseid).orderbychild(sortorder).limittofirst(100);
but believe duplication can avoided adding key "group" post. (it make maintenance easier users switch groups).
the "group" database query has become:
databasereference.child("exerciseid"+mexerciseid).orderbychild("group").equalto(groupname);
all good, except data no longer sorted per "sortorder". firebase not allow multiple sort criteria, believe solution lies in offline sorting.
so, how 1 sort adapter offline?
my adapter pretty standard:
madapter = new firebaserecycleradapter<post, postviewholder>(post.class, r.layout.item_post, postviewholder.class, dataquery) { @override protected void populateviewholder(final postviewholder viewholder, final post model, final int position) { final databasereference postref = getref(position); // bind post viewholder, setting onclicklistener star button viewholder.bindtopost(model, position, postref.getkey(), null); } mrecycler.setadapter(madapter); }
i've implemented comparable in post, problem data stored can pass collections.sort() in sort of way:
private list<post> mposts = new arraylist<>(); mposts.add(model); collections.sort(mposts, post.comparators.alltime);
the adapters in firebaseui library display data in order returned underlying firebasedatabase
reference or query
.
you file feature request on github repo (since i'm not sure covered in this one yet). alternatively fork library , roll own implementation of functionality.
Comments
Post a Comment