Skip to content

Remove resources from OfflineAreaSelectorViewModel#3540

Merged
andreia-ferreira merged 4 commits intomasterfrom
andreia/remove-resources-from-vm
Feb 11, 2026
Merged

Remove resources from OfflineAreaSelectorViewModel#3540
andreia-ferreira merged 4 commits intomasterfrom
andreia/remove-resources-from-vm

Conversation

@andreia-ferreira
Copy link
Collaborator

OfflineAreaSelectorViewModel depended on Resources to resolve string resources directly, creating a tight coupling with the Android framework

This PR removes that dependency by introducing a new sealed class BottomTextState so that the VM emits semantic UI state and the Fragment handles string resolution. During this, the databinding was also removed from the xml.

This should help decouple the VM from the Android framework and improve testability.

@shobhitagarwal1612 PTAL?

@auto-assign auto-assign bot requested a review from gino-m February 11, 2026 10:29
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @andreia-ferreira, 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 significantly refactors the offline area selection feature by removing the OfflineAreaSelectorViewModel's direct dependency on Android Resources. This change promotes a cleaner separation of concerns, where the ViewModel communicates abstract UI states using a new BottomTextState sealed class, and the OfflineAreaSelectorFragment handles the concrete string resolution and UI updates. The removal of data binding further centralizes UI logic within the Fragment, leading to a more modular and testable architecture.

Highlights

  • Decoupling ViewModel from Android Resources: The OfflineAreaSelectorViewModel no longer directly depends on Android Resources for string resolution, improving testability and reducing tight coupling.
  • Introduction of BottomTextState: A new sealed class BottomTextState was introduced to allow the ViewModel to emit semantic UI states, with the Fragment now responsible for translating these states into displayable strings.
  • Removal of Data Binding: Data binding was removed from offline_area_selector_frag.xml, shifting UI logic and event handling to the OfflineAreaSelectorFragment.
  • Improved Testability: The refactoring enhances the testability of the OfflineAreaSelectorViewModel by removing Android framework dependencies, as reflected in updated unit tests.

🧠 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/src/main/java/org/groundplatform/android/ui/offlineareas/selector/OfflineAreaSelectorFragment.kt
    • Imported new lifecycle and model classes, including Lifecycle, repeatOnLifecycle, BottomTextState, and UiState.
    • Removed data binding setup for viewModel and lifecycleOwner.
    • Added explicit setOnClickListener calls for download and cancel buttons.
    • Introduced setupObservers() to manage downloadButtonEnabled and bottomTextState updates.
    • Implemented observation of viewModel.bottomTextState using repeatOnLifecycle to resolve and display strings based on the BottomTextState.
  • app/src/main/java/org/groundplatform/android/ui/offlineareas/selector/OfflineAreaSelectorViewModel.kt
    • Removed android.content.res.Resources import and its injection from the constructor.
    • Replaced MutableLiveData<String?> bottomText with MutableStateFlow<BottomTextState?> _bottomTextState and exposed it as StateFlow<BottomTextState?> bottomTextState.
    • Updated all internal calls to bottomText.postValue to set the appropriate BottomTextState value to _bottomTextState.value.
    • Removed the offlineAreaSizeLoadingSymbol string resource usage.
  • app/src/main/java/org/groundplatform/android/ui/offlineareas/selector/model/BottomTextState.kt
    • Added a new sealed class BottomTextState to define distinct states for the bottom text, including Loading, AreaSize, NoImageryAvailable, AreaTooLarge, and NetworkError.
  • app/src/main/java/org/groundplatform/android/ui/offlineareas/selector/model/UiState.kt
    • Renamed and moved the UiState sealed class from org.groundplatform.android.ui.offlineareas.selector to org.groundplatform.android.ui.offlineareas.selector.model.
  • app/src/main/res/layout/offline_area_selector_frag.xml
    • Removed the <layout> and <data> tags, eliminating data binding from the XML layout.
    • Removed android:onClick, android:enabled, and android:clickable attributes from buttons, and android:text attribute from the bottom_text TextView.
  • app/src/test/java/org/groundplatform/android/ui/offlineareas/selector/OfflineAreaSelectorViewModelTest.kt
    • Removed imports for Context, Resources, ApplicationProvider, and R.
    • Removed the resources field and its initialization in the setUp() method.
    • Updated test assertions to check viewModel.bottomTextState.value against BottomTextState objects instead of string resources.
    • Added new test cases to verify behavior for 'area too large' and 'reset state on map drag'.
Activity
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.

@andreia-ferreira andreia-ferreira requested review from shobhitagarwal1612 and removed request for gino-m February 11, 2026 10:30
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 effectively refactors the OfflineAreaSelectorViewModel to remove its dependency on Android Resources, which is a great step towards better separation of concerns and improved testability. The introduction of the BottomTextState sealed class to model UI states is a commendable application of modern Android development patterns. The removal of data binding in favor of programmatic view updates is handled cleanly within the fragment. The accompanying test modifications and additions are thorough and validate the new implementation. I have a couple of minor suggestions to further enhance code clarity and user experience.

@codecov
Copy link

codecov bot commented Feb 11, 2026

Codecov Report

❌ Patch coverage is 65.85366% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.62%. Comparing base (155e1ac) to head (d3efcc7).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...flineareas/selector/OfflineAreaSelectorFragment.kt 50.00% 8 Missing and 6 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3540      +/-   ##
============================================
+ Coverage     70.57%   70.62%   +0.04%     
- Complexity     1615     1621       +6     
============================================
  Files           326      327       +1     
  Lines          8861     8889      +28     
  Branches        976      982       +6     
============================================
+ Hits           6254     6278      +24     
+ Misses         2024     2023       -1     
- Partials        583      588       +5     
Files with missing lines Coverage Δ
...lineareas/selector/OfflineAreaSelectorViewModel.kt 63.30% <100.00%> (+7.94%) ⬆️
.../ui/offlineareas/selector/model/BottomTextState.kt 100.00% <100.00%> (ø)
.../android/ui/offlineareas/selector/model/UiState.kt 0.00% <ø> (ø)
...flineareas/selector/OfflineAreaSelectorFragment.kt 54.16% <50.00%> (-2.98%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@shobhitagarwal1612 shobhitagarwal1612 left a comment

Choose a reason for hiding this comment

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

🧹 ✨

@andreia-ferreira andreia-ferreira merged commit 8305387 into master Feb 11, 2026
9 checks passed
@andreia-ferreira andreia-ferreira deleted the andreia/remove-resources-from-vm branch February 11, 2026 17:30
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.

2 participants