Skip to content

Refactor settings screen to compose#3574

Open
shobhitagarwal1612 wants to merge 32 commits intomasterfrom
compose-settings
Open

Refactor settings screen to compose#3574
shobhitagarwal1612 wants to merge 32 commits intomasterfrom
compose-settings

Conversation

@shobhitagarwal1612
Copy link
Member

@shobhitagarwal1612 shobhitagarwal1612 commented Feb 20, 2026

Fixes #3573

Before:

settings-activity-compose-before.webm

After: (Removed icons after recording screencast)

settings-activity-compose-after.webm

@andreia-ferreira PTAL?

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @shobhitagarwal1612, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request modernizes the application's settings interface by migrating it from a traditional Android View system (Fragments and XML) to Jetpack Compose. This transition enhances the UI's maintainability and responsiveness, and integrates a more reactive data flow for user preferences using Kotlin Flows. The change also simplifies the ViewModel layer by leveraging direct interaction with the repository for settings management.

Highlights

  • Settings UI Refactor to Jetpack Compose: The entire settings screen UI has been rewritten using Jetpack Compose, replacing the previous Fragment-based implementation with PreferenceFragmentCompat and XML layouts.
  • Reactive Preference Observation with Kotlin Flows: The LocalValueStore now exposes preference changes as Kotlin Flows, enabling reactive updates in the UI and data layers. UserRepository has been updated to consume these flows.
  • Simplified Settings ViewModel: The SettingsViewModel has been streamlined to directly interact with UserRepository's reactive userSettingsFlow, removing the need for a separate GetUserSettingsUseCase and manual preference refreshing.
  • Dependency Updates: The androidx.fragment:fragment-compose dependency was added to support Compose integration within fragments (though SettingsActivity now uses setContent directly, this dependency might be for other Compose-Fragment interactions).
  • Removal of Legacy UI Components: The SettingsFragment.kt, settings_activity.xml, and preferences.xml files, along with their associated test files, have been removed as part of the migration to Compose.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • app/build.gradle
    • Added androidx.fragment.compose dependency.
  • app/src/main/java/org/groundplatform/android/data/local/LocalValueStore.kt
    • Introduced watchString and watchBoolean methods to expose SharedPreferences as Flows.
    • Converted shouldUploadMediaOverUnmeteredConnectionOnly to a var property with getter and setter.
    • Added selectedLanguageFlow, selectedLengthUnitFlow, and shouldUploadMediaOverUnmeteredConnectionOnlyFlow to provide reactive streams of preference changes.
  • app/src/main/java/org/groundplatform/android/data/sync/MediaUploadWorkManager.kt
    • Updated access to shouldUploadMediaOverUnmeteredConnectionOnly from a function call to a property.
  • app/src/main/java/org/groundplatform/android/di/ViewModelModule.kt
    • Removed the binding for SettingsViewModel.
  • app/src/main/java/org/groundplatform/android/repository/UserRepository.kt
    • Added imports for Flow and combine.
    • Introduced userSettingsFlow to combine and expose user settings as a reactive Flow.
    • Added updateSelectedLanguage, updateMeasurementUnits, and updateUploadMediaOverUnmeteredConnectionOnly methods to modify user preferences.
  • app/src/main/java/org/groundplatform/android/ui/settings/SettingsActivity.kt
    • Refactored to use setContent for hosting the new SettingsScreen Composable.
    • Removed the SettingsActivityBinding and XML layout inflation.
    • Added helper functions applyLocaleAndRestart and openWebsite for handling locale changes and external links.
  • app/src/main/java/org/groundplatform/android/ui/settings/SettingsFragment.kt
    • Removed the entire SettingsFragment file, as its functionality is replaced by Compose.
  • app/src/main/java/org/groundplatform/android/ui/settings/SettingsScreen.kt
    • Added a new Jetpack Compose SettingsScreen for rendering the settings UI.
    • Implemented UI components for general settings (upload media, language, measurement units) and help (visit website).
    • Included SettingsCategory, SettingsItem, SettingsSwitchItem, and SingleSelectionDialog composables.
  • app/src/main/java/org/groundplatform/android/ui/settings/SettingsViewModel.kt
    • Annotated with @HiltViewModel.
    • Injected UserRepository instead of GetUserSettingsUseCase.
    • Exposed userRepository.userSettingsFlow as uiState using stateIn.
    • Added updateUploadMediaOverUnmeteredConnectionOnly, updateMeasurementUnits, and updateSelectedLanguage methods to delegate updates to UserRepository.
  • app/src/main/res/layout/settings_activity.xml
    • Removed the XML layout file for SettingsActivity.
  • app/src/main/res/xml/preferences.xml
    • Removed the XML preferences definition file.
  • app/src/test/java/org/groundplatform/android/ui/settings/SettingsFragmentTest.kt
    • Removed the entire test file for SettingsFragment.
  • app/src/test/java/org/groundplatform/android/ui/settings/SettingsViewModelTest.kt
    • Updated tests to reflect the new SettingsViewModel implementation, using UserRepository and Flows for observing settings changes.
  • gradle/libs.versions.toml
    • Added androidx-fragment-compose library definition.
Activity
  • The settings screen has been fully refactored to Jetpack Compose.
  • The underlying data layer for preferences now uses Kotlin Flows for reactive updates.
  • The SettingsActivity now directly hosts the Compose UI.
  • Legacy Fragment and XML-based settings components have been removed.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the settings screen to use Jetpack Compose, replacing the old PreferenceFragmentCompat implementation. It introduces new Flow-based properties in LocalValueStore and UserRepository to observe changes in user settings, which is a good move towards reactive programming. The SettingsActivity is updated to use setContent for Compose, and the old SettingsFragment and its associated layout/XML files are removed. The SettingsViewModel is also updated to use the UserRepository directly, simplifying the data flow. Overall, this is a significant and positive refactoring that modernizes the settings UI.

@shobhitagarwal1612
Copy link
Member Author

/gemini review

@gemini-code-assist
Copy link
Contributor

Warning

Gemini encountered an error creating the review. You can try again by commenting /gemini review.

@shobhitagarwal1612
Copy link
Member Author

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request is a great initiative to refactor the settings screen to Jetpack Compose, which improves the codebase's modernity and maintainability. The reactive data flow from LocalValueStore up to the SettingsViewModel and SettingsScreen is well-implemented using Kotlin Flows. I've left a couple of suggestions: one to reduce some code duplication in LocalValueStore, and another regarding the addition of UI tests for the new composable screen, as per the repository's contribution guidelines.

@shobhitagarwal1612 shobhitagarwal1612 marked this pull request as ready for review February 26, 2026 11:14
# Conflicts:
#	app/src/test/java/org/groundplatform/android/ui/settings/SettingsFragmentTest.kt
@codecov
Copy link

codecov bot commented Feb 26, 2026

Codecov Report

❌ Patch coverage is 62.44131% with 80 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.86%. Comparing base (83b8d5f) to head (ec88031).

Files with missing lines Patch % Lines
...oundplatform/android/ui/settings/SettingsScreen.kt 53.03% 30 Missing and 1 partial ⚠️
...droid/ui/settings/components/SettingsSelectItem.kt 62.16% 10 Missing and 4 partials ⚠️
...orm/android/ui/settings/components/SettingsItem.kt 56.52% 8 Missing and 2 partials ⚠️
...droid/ui/settings/components/SettingsSwitchItem.kt 62.96% 8 Missing and 2 partials ⚠️
...id/ui/settings/components/SingleSelectionDialog.kt 67.74% 9 Missing and 1 partial ⚠️
...oundplatform/android/data/local/LocalValueStore.kt 25.00% 3 Missing ⚠️
...atform/android/data/sync/MediaUploadWorkManager.kt 0.00% 1 Missing ⚠️
...android/ui/settings/components/SettingsCategory.kt 90.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3574      +/-   ##
============================================
- Coverage     71.12%   70.86%   -0.27%     
+ Complexity     1631     1620      -11     
============================================
  Files           332      337       +5     
  Lines          8995     9129     +134     
  Branches        998     1013      +15     
============================================
+ Hits           6398     6469      +71     
- Misses         2001     2059      +58     
- Partials        596      601       +5     
Files with missing lines Coverage Δ
...roundplatform/android/repository/UserRepository.kt 75.47% <100.00%> (ø)
...dplatform/android/ui/settings/SettingsViewModel.kt 100.00% <100.00%> (ø)
...atform/android/data/sync/MediaUploadWorkManager.kt 14.28% <0.00%> (ø)
...android/ui/settings/components/SettingsCategory.kt 90.00% <90.00%> (ø)
...oundplatform/android/data/local/LocalValueStore.kt 82.05% <25.00%> (-3.67%) ⬇️
...orm/android/ui/settings/components/SettingsItem.kt 56.52% <56.52%> (ø)
...droid/ui/settings/components/SettingsSwitchItem.kt 62.96% <62.96%> (ø)
...id/ui/settings/components/SingleSelectionDialog.kt 67.74% <67.74%> (ø)
...droid/ui/settings/components/SettingsSelectItem.kt 62.16% <62.16%> (ø)
...oundplatform/android/ui/settings/SettingsScreen.kt 53.03% <53.03%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

Convert Settings Activity and Fragment to Compose

1 participant