Categories
Uncategorized

Week 10: Strong Foundations

Hey everyone!

Remember last week when I was all abuzz about introducing ViewModel into our project for better dependency injection and unit testing? Well, guess what? This week, I got to see it in action! And, oh boy, it was a blast—even more so because I got to pass the baton to one of my teammates and watch them take it across the finish line with a little coaching from me.

We had this pesky little bug that kept us scratching our heads: whenever you sorted a list of items and selected one, the sort order vanished like a ghost once you navigated back. Turns out, the navigation process was the sneaky culprit, causing our Fragment to vanish into thin air, taking our carefully sorted list with it. But no more!

Our hero, ViewModel, entered the scene. Picture this: I had prepped a ViewModel blueprint in a cosy little branch of its own, and my teammate branched out from there. They grabbed the template and plunged into the challenge. We had our list swooping in asynchronously through the API into a MutableLiveData haven, with the sort preference snug in another MutableLiveData. Then, along came MediatorLiveData, keeping an eye on both, ready to spring into action. It scheduled a computation thread rendezvous, whirled the sorting magic, and voilà—out came the sorted list.

We didn’t just stop at fixing the bug; we made sure it stayed fixed. The ViewModel was summoned from the Activity, and the Fragment—like a loyal companion—retrieved this ViewModel. It watched the sorted list like a hawk and gave the RecyclerView the updates. And since ViewModel pledges allegiance to the Activity’s lifecycle, our sorted list stays bravely sorted through every navigation twist and turn.

But wait, there’s more! I rallied the troops (a.k.a. my team) for a meeting to share the tale of our triumph with ViewModel, ensuring that we’re all ready to wield this newfound power in future tasks. We’ve nailed it this time, and I’m thrilled to see how we can apply it again.

As I march on, I’m diving deep into best practices and devising migration strategies to polish my capstone project to a shine before graduation. The anticipation of what’s to come is sky-high—I can hardly wait to see where we go from here. Thanks a ton for sharing in my journey. Stay tuned!

By Robert Sale

I am a father as well as a software developer. I love my family and love my work. I like to think that my work will some day benefit society.

Leave a Reply

Your email address will not be published. Required fields are marked *