I'm transitioning from SQLite to Firebase and in doing so, I have a lot of pre-existing data that I need to set into different views.
Initial view: An alphabetical list (no duplicates), showing letters for only those resources that exist below it (meaning if there is no resource that starts with X, X should not show up at all).
Secondary view: Once you tap on a letter, it expands accordion style to reveal resources (no duplicates) that start with that letter.
My Firebase query is right in that I'm getting the correct data, but how do I use it? Ideally what I'd like to do is get all the topics, drop them in a TreeSet to eliminate duplicates and sort them automatically, then do the same thing but just getting the first letter. I cant modify a set, or an array, or a list from an inner class, but I can't access the same if I instantiate from inside either (and it doesn't matter because it gets called fresh for every single object so it's always a new set).
Is there a best practice I'm missing?
mDatabase = FirebaseDatabase.getInstance();
mRootRef = mDatabase.getReference();
mQuoteRef = mRootRef.child("quotes");
Query topicQuery = mQuoteRef.orderByChild("Topic");
topicQuery.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
TreeSet<String> topicList = new TreeSet<>(); <--obv not right
TreeSet<String> firstLetterList = new TreeSet<>();
GetQuoteInfo quote = dataSnapshot.getValue(GetQuoteInfo.class);
if (quote.getTopic() != null) {
topicList.add(quote.getTopic());
firstLetterList.add(quote.getTopic().substring(0, 1));
}
}
}
magicalListThatContainsAllOfMyFirebaseDataThatICanNowManipulate;