As a beginner in Android and Firebase I mostly need an opinion and not code. Let me describe the situation and then I have 2 questions.
I am creating an application to store information about "paintings" and I want the user to be able to perform a search for a painting based on some colours they choose.
My database has a couple of nodes and the ones in question are:
Colours: where all the colours are stored. Every entry is in the form of UID->"Name":"Blue"
ColoursToPaintings: where every colour-UID has under it, a Painting object.
Paintings: where all the Paintings are stored. Each painting has a name, photourl(that leads to firebase storage), array with all the colours and other information.
They way I do it is(flow):
The application starts and the user can select colours that are loaded in the app from Firebase colours node (about 1000 colours). They search for eg. 5 colours.
I perform a for loop to create dynamically references to ColoursToPaintings so I can fetch all the Painting UIDs under these nodes (2000) paintings.
Then I perform another loop in these 2000 Painting UIDs to create references to the Paintings node so I can fetch the actual Paintings with all the information.
All these paintings are shown in a recyclerView list and photos (the photos are loaded with Glide to achieve lazy loading).
Question 1: Is the above approach the right one? Is there another way I should design the database / app?
So far, though the above approach seems to be working as expected, if I select many colours that produce many results, I get the issue of "skipped 40 frames maybe there is too much work on the main thread". Which leads in the Question 2.
Question 2: It is supposed that everything done with Firebase, is done in a separate thread(is it true?). Shouldn't all the work I do to be considered as a "background" task? I even tried to create separate AsyncTasks but still I get skipped frames.
Regarding the Question 2. Could the skipped frames be caused because every time a Painting is fetched by from the database, I add it to an ArrayList and then I περφορμ notifyDataSetChanged() on the adapter. Could notifyDataSetChanged() be expensive and cause the issue?
Thanks in advance.