Using Adapter Pattern for Viewing Multiple Tasks
In a previous post, we talked about our end customer tracking experience. HyperTrack’s Android and iOS Consumer SDKs enable developers to implement a smooth real-time location tracking experience in their consumer apps. Until now the SDKs were designed to view only one task at a time on the map. And then developers at echo plans requested a feature to view multiple tasks simultaneously on the same map view. echo plans is an app for groups of friends to plan meetups. Check out their blog post to learn more about echo plans and how they implemented location tracking with HyperTrack.
We redesigned the Consumer SDK to enable the feature for echo plans. In this post, we elaborate on the design pattern we followed. UI elements on the Consumer SDK — map markers, info layouts — can be customized to fit into the theme of the host app. Our goal was to make the new code design extensible and comprehensible, and thus make the Consumer SDK integration easy for the developers.
The crude approach for multiple task tracking would have been to maintain a list of tasks and a corresponding list of UI elements. This implementation would have required a delegate method to customize every UI element for every task. That seemed cumbersome, yikes!
We thought of a few ways to implement this and felt that the Adapter Design Pattern is what the doctor ordered. This pattern has been aptly implemented in RecyclerView & RecyclerView.Adapter classes. How RecyclerView implements this pattern is by passing a list of Data Model on to the RecyclerView.Adapter and the adapter is the one responsible for displaying this data as per application’s business logic. The biggest advantage of leveraging this design pattern is that most developers are quite familiar with the RecyclerView and RecyclerView.Adapter in Android and UITableView in iOS.
An Adapter object acts as a bridge between an AdapterView and the underlying data for that view. The Adapter provides access to the data items. The Adapter is also responsible for making a View for each item in the data set.
For our Consumer SDK, HTMapFragment is the Map View where user can view multiple tasks simultaneously and HTConsumerClient is the data source containing the list of tasks being currently tracked by the user. HTMapAdapter provides the developer the necessary bridge to better communicate with HTMapFragment.
- HTMapAdapter provides access to the data items corresponding to a task including Markers on the Map, Driver & Address information views, Default strings etc.
- It also provides the freedom to customise any view for a task based on host application’s business logic.
- On top of these customizations, the changes reflect on runtime just by a call to HTMapAdapter’s method called notifyDataSetChanged() which is the way RecyclerView and RecyclerView.Adapter have been designed.
Migrating to the Adapter Pattern for tracking tasks helped us achieve the objective of tracking multiple tasks simultaneously on the map view while making it effortless to integrate and customise HTMapFragment views.
For more info, please refer to the SDK documentation here.
Now that we had serviced a cool feature request that first came from echo plans, we looked for ways to dog-food this feature within our demo app SendETA, just like all other features in our SDKs and APIs. Turns out, there was a pretty direct need for this. The HyperTrack team sends their live tracking link on Slack when they are on their way to work every day. This helps us touch and feel our technology on a daily basis and build a richer data set for our data models. When multiple colleagues are on their way to the same destination (work), it only makes sense that I view all live trips on the same map view. We decided to give this a shot. After all, it was just a day of integration!
This also means that SendETA users worldwide can now enjoy this feature. When your friends send you a tracking link to visit you, just tap on the links as you always do. When multiple trips are headed your way at the same time, the app will auto-magically show them to you on the same map. Tapping on each vehicle will zoom into the single tracking view that you know and love. Tapping out of it will get you back to multiple trips.
Do you have a location tracking feature that you would like to implement in your product? Sign up for HyperTrack and start building it right away.
Originally published at blog.hypertrack.io on September 16, 2016.