ProAndroidDev

The latest posts from Android Professionals and Google Developer Experts.

Follow publication

Member-only story

How to smash a Jetpack Compose feature from Product — including testing! 🧪 🧐

Rafa
ProAndroidDev
Published in
7 min readOct 3, 2024

The Team Leaders feature for the NHL app on Google Play

Introduction

To create exceptional Jetpack Compose features, start by aligning them with your product goals and user needs. Design, prototype, and develop features that provide value. For this specific feature, Product aims to deliver interactive widgets and comprehensive player data, enhancing the user experience. 🏆🎉🥇💪

Key Points:

  • Define product goals.
  • Identify key features.
  • Leverage Jetpack Compose’s strengths.
  • Design and prototype.
  • Develop with best practices.
  • Test rigorously.
  • Iterate and refine!

Understanding the TeamLeadersViewModel

The TeamLeadersViewModel is a key component responsible for managing data and state in this Jetpack Compose app displaying team leader information.

What it Does:

  • collects team player data (getPlayers) and enriches it with player stats (enrichPlayersWithTeamData).
  • Manages UI state using a MutableStateFlow that emits different states:
  • Loading: While data is being fetched.
  • Success: When data is retrieved successfully, holding skater and goalie leader lists.
  • Error: If an error occurs during data fetching.

Key Points:

  • Uses dependency injection (@HiltViewModel) to access repositories and dispatchers.
  • Leverages runCatching for concise error handling.
  • Exposes a uiState StateFlow for UI components to observe data changes.
  • Encapsulates player data enrichment logic in a private testable function.

Benefits:

  • Improved separation of concerns by isolating data fetching and state management.
  • Reactive UI updates through StateFlow.
  • Testable code with private functions accessible for unit testing (@VisibleForTesting).
data class EnrichedPlayerData(
val

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Published in ProAndroidDev

The latest posts from Android Professionals and Google Developer Experts.

Written by Rafa

Fintech, Hockey & Veteran 🇺🇸

No responses yet

Write a response