Skip to content

Conversation

MozhganPeivandianSharbaf
Copy link
Contributor

@MozhganPeivandianSharbaf MozhganPeivandianSharbaf commented Sep 26, 2025

I re-implemented the MainActivity of the Health SDK using Jetpack Compose. This was part of applying the new concepts and techniques I learned during my Compose course.

Instead of relying on XML layouts and ViewBinding, I moved the entire UI into a MainScreen() composable. This allowed me to:

  • Replace ConstraintLayout and ViewPager2 with Compose layouts and the new HorizontalPager API.
  • Use rememberLauncherForActivityResult to handle camera capture and document import in a declarative way.
  • Collect Flow state directly in Compose using collectAsState, so the UI automatically updates when the ViewModel state changes.
  • Add a custom dots indicator to replace the TabLayoutMediator.
  • Simplify button enable/disable logic by binding directly to state (Upload becomes active as soon as pages are present).

Through this exercise, I could demonstrate what I learned in the course: writing modern, declarative UI, managing lifecycle safely with Compose, and reducing boilerplate compared to XML + imperative View setup.

It was also a chance to share with the team how our existing SDK examples can be updated to Compose-first architecture, which makes the codebase cleaner, more maintainable, and aligned with current Android best practices.

@MozhganPeivandianSharbaf MozhganPeivandianSharbaf requested review from abolfazlimahdi, Copilot and obaidgini and removed request for Copilot September 26, 2025 09:45
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the MainActivity from XML layouts to Jetpack Compose by creating a new MainScreen composable. The refactoring modernizes the UI to use declarative Compose patterns while maintaining the same functionality as the original imperative View-based implementation.

Key changes:

  • Complete migration from XML ViewBinding to Compose UI with MainScreen composable
  • Replacement of ViewPager2/TabLayoutMediator with HorizontalPager and custom DotsIndicator
  • Integration of activity result launchers directly in Compose using rememberLauncherForActivityResult

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
MainViewModel.kt Adds contentPages StateFlow and Page data class to support Compose state management
MainScreen.kt New Compose UI implementation replacing XML layouts with declarative UI components
MainActivity.kt Simplified to use setContent with MainScreen composable, removing ViewBinding and listeners

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link

sonarqubecloud bot commented Oct 7, 2025

Quality Gate Failed Quality Gate failed

Failed conditions
5 New Code Smells (required ≤ 0)
1 New Critical Issues (required ≤ 0)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant