Mission: Task Management App
Ordering elements in Firebase Realtime Database
Firebase Realtime Database is a NoSQL style document store. It stores key-value pairs in a tree like structure similar to JSON. A major difference from JSON is that the database cannot represent ordered data structures such as arrays. The reason for this probably has to do with avoiding race conditions when multiple clients are accessing the same data. Although data is not stored in any consistent order, it can be queried in a sorted order. This is easy when data elements need to be sorted by an attribute that does not change (or rarely changes) such as a date or sorting alphabetically. However, this model does little to facilitate user controlled ordering such as assigning priority to a list of tasks. In order to solve this problem I created an order
attribute on any element that could be sorted by the user. The order
attribute is a float which can be positive or negative. Inserting an element involves setting the order
to the midpoint between the previous and next elements. Inserting at the beginning of the list assigns the order
attribute to one minus the order
of the original first element. This model ensures that elements can be sorted to the proper order when being queried.
Material Design Components
In order to properly use Google’s Material Design components I had to ensure that I was using the androidx
libraries. Some of the material design elements were not implemented in the android library (spinners) so I had to recreate them.