From 4e4c960feab26d191b32a36beb17f0bd881a0dde Mon Sep 17 00:00:00 2001 From: dkhawk <107309+dkhawk@users.noreply.github.com> Date: Fri, 10 Oct 2025 09:27:20 -0600 Subject: [PATCH] feat: Refactor onClicks to View Binding Refactors the onClick attributes in the following activities to use programmatic click listeners with View Binding: - VisibleRegionDemoActivity - SnapshotDemoActivity - StreetViewPanoramaNavigationDemoActivity - CircleDemoActivity - MarkerDemoActivity This change centralizes event handling within the corresponding activities and fragments, improving code organization and maintainability. It also adds a basic Espresso test for VisibleRegionDemoActivity to verify the onClick functionality. --- ApiDemos/project/ON_CLICKS.md | 136 +++++++++--------- ApiDemos/project/PLAN.md | 38 ++--- ApiDemos/project/PROGRESS.md | 3 +- .../main/res/layout-land/snapshot_demo.xml | 5 +- .../src/main/res/layout/circle_demo.xml | 14 +- .../src/main/res/layout/marker_demo.xml | 22 ++- .../src/main/res/layout/snapshot_demo.xml | 10 +- .../street_view_panorama_navigation_demo.xml | 2 +- .../main/res/layout/visible_region_demo.xml | 5 - ApiDemos/project/java-app/build.gradle.kts | 1 + .../VisibleRegionDemoActivityTest.java | 65 +++++---- .../example/mapdemo/CircleDemoActivity.java | 79 +++++----- .../example/mapdemo/MarkerDemoActivity.java | 56 +++----- .../example/mapdemo/SnapshotDemoActivity.java | 30 ++-- ...eetViewPanoramaNavigationDemoActivity.java | 61 ++++---- .../mapdemo/VisibleRegionDemoActivity.java | 49 +++---- ApiDemos/project/kotlin-app/build.gradle.kts | 1 + .../example/kotlindemos/CircleDemoActivity.kt | 74 +++++----- .../example/kotlindemos/MarkerDemoActivity.kt | 51 +++---- .../kotlindemos/SnapshotDemoActivity.kt | 30 ++-- ...treetViewPanoramaNavigationDemoActivity.kt | 118 ++++++++++----- .../kotlindemos/VisibleRegionDemoActivity.kt | 91 ++++++------ 22 files changed, 468 insertions(+), 473 deletions(-) diff --git a/ApiDemos/project/ON_CLICKS.md b/ApiDemos/project/ON_CLICKS.md index 0e2eb2b4..01791d6f 100644 --- a/ApiDemos/project/ON_CLICKS.md +++ b/ApiDemos/project/ON_CLICKS.md @@ -2,58 +2,58 @@ This file tracks the progress of refactoring `android:onClick` attributes to use View Binding and programmatic click listeners. -- [ ] `setNoPadding` - - [ ] Replaced in `java-app` - - [ ] Replaced in `kotlin-app` - - [ ] Removed from XML -- [ ] `setMorePadding` - - [ ] Replaced in `java-app` - - [ ] Replaced in `kotlin-app` - - [ ] Removed from XML -- [ ] `moveToOperaHouse` - - [ ] Replaced in `java-app` - - [ ] Replaced in `kotlin-app` - - [ ] Removed from XML -- [ ] `moveToSFO` - - [ ] Replaced in `java-app` - - [ ] Replaced in `kotlin-app` - - [ ] Removed from XML -- [ ] `moveToAUS` - - [ ] Replaced in `java-app` - - [ ] Replaced in `kotlin-app` - - [ ] Removed from XML -- [ ] `onScreenshot` - - [ ] Replaced in `java-app` - - [ ] Replaced in `kotlin-app` - - [ ] Removed from XML -- [ ] `onClearScreenshot` - - [ ] Replaced in `java-app` - - [ ] Replaced in `kotlin-app` - - [ ] Removed from XML -- [ ] `onRequestPosition` - - [ ] Replaced in `java-app` - - [ ] Replaced in `kotlin-app` - - [ ] Removed from XML -- [ ] `onMovePosition` - - [ ] Replaced in `java-app` - - [ ] Replaced in `kotlin-app` - - [ ] Removed from XML -- [ ] `onPanLeft` - - [ ] Replaced in `java-app` - - [ ] Replaced in `kotlin-app` - - [ ] Removed from XML -- [ ] `onPanUp` - - [ ] Replaced in `java-app` - - [ ] Replaced in `kotlin-app` - - [ ] Removed from XML -- [ ] `onPanDown` - - [ ] Replaced in `java-app` - - [ ] Replaced in `kotlin-app` - - [ ] Removed from XML -- [ ] `onPanRight` - - [ ] Replaced in `java-app` - - [ ] Replaced in `kotlin-app` - - [ ] Removed from XML +- [x] `setNoPadding` + - [x] Replaced in `java-app` + - [x] Replaced in `kotlin-app` + - [x] Removed from XML +- [x] `setMorePadding` + - [x] Replaced in `java-app` + - [x] Replaced in `kotlin-app` + - [x] Removed from XML +- [x] `moveToOperaHouse` + - [x] Replaced in `java-app` + - [x] Replaced in `kotlin-app` + - [x] Removed from XML +- [x] `moveToSFO` + - [x] Replaced in `java-app` + - [x] Replaced in `kotlin-app` + - [x] Removed from XML +- [x] `moveToAUS` + - [x] Replaced in `java-app` + - [x] Replaced in `kotlin-app` + - [x] Removed from XML +- [x] `onScreenshot` + - [x] Replaced in `java-app` + - [x] Replaced in `kotlin-app` + - [x] Removed from XML +- [x] `onClearScreenshot` + - [x] Replaced in `java-app` + - [x] Replaced in `kotlin-app` + - [x] Removed from XML +- [x] `onRequestPosition` + - [x] Replaced in `java-app` + - [x] Replaced in `kotlin-app` + - [x] Removed from XML +- [x] `onMovePosition` + - [x] Replaced in `java-app` + - [x] Replaced in `kotlin-app` + - [x] Removed from XML +- [x] `onPanLeft` + - [x] Replaced in `java-app` + - [x] Replaced in `kotlin-app` + - [x] Removed from XML +- [x] `onPanUp` + - [x] Replaced in `java-app` + - [x] Replaced in `kotlin-app` + - [x] Removed from XML +- [x] `onPanDown` + - [x] Replaced in `java-app` + - [x] Replaced in `kotlin-app` + - [x] Removed from XML +- [x] `onPanRight` + - [x] Replaced in `java-app` + - [x] Replaced in `kotlin-app` + - [x] Removed from XML - [x] `onZoomIn` - [x] Replaced in `java-app` - [x] Replaced in `kotlin-app` @@ -66,22 +66,22 @@ This file tracks the progress of refactoring `android:onClick` attributes to use - [x] Replaced in `java-app` - [x] Replaced in `kotlin-app` - [x] Removed from XML -- [ ] `onGoToSanFran` - - [ ] Replaced in `java-app` - - [ ] Replaced in `kotlin-app` - - [ ] Removed from XML -- [ ] `onGoToSantorini` - - [ ] Replaced in `java-app` - - [ ] Replaced in `kotlin-app` - - [ ] Removed from XML -- [ ] `onGoToInvalid` - - [ ] Replaced in `java-app` - - [ ] Replaced in `kotlin-app` - - [ ] Removed from XML -- [ ] `toggleClickability` - - [ ] Replaced in `java-app` - - [ ] Replaced in `kotlin-app` - - [ ] Removed from XML +- [x] `onGoToSanFran` + - [x] Replaced in `java-app` + - [x] Replaced in `kotlin-app` + - [x] Removed from XML +- [x] `onGoToSantorini` + - [x] Replaced in `java-app` + - [x] Replaced in `kotlin-app` + - [x] Removed from XML +- [x] `onGoToInvalid` + - [x] Replaced in `java-app` + - [x] Replaced in `kotlin-app` + - [x] Removed from XML +- [x] `toggleClickability` + - [x] Replaced in `java-app` + - [x] Replaced in `kotlin-app` + - [x] Removed from XML - [ ] `onClearMap` - [ ] Replaced in `java-app` - [ ] Replaced in `kotlin-app` diff --git a/ApiDemos/project/PLAN.md b/ApiDemos/project/PLAN.md index eedf2648..2acee7b7 100644 --- a/ApiDemos/project/PLAN.md +++ b/ApiDemos/project/PLAN.md @@ -1,24 +1,24 @@ -### Plan for Refactoring `onClick` Attributes (Iterative Approach) +### Plan for Ensuring `onClick` Functionality with Tests -1. **Enable View Binding:** - * Ensure the `build.gradle.kts` files for `java-app`, `kotlin-app`, and `common-ui` modules have View Binding enabled. - * **Verification:** Run `./gradlew build` to confirm the project builds successfully. +**Primary Goal:** Work across all activities to ensure a basic level of testing, with the priority of verifying that all `onClick` functions work correctly. -2. **Track `onClick` Attributes:** - * Use the `ON_CLICKS.md` file as a checklist for all `onClick` attributes to be refactored. +1. **Project Stability Check:** + * Ensure View Binding is enabled in `java-app`, `kotlin-app`, and `common-ui` modules. + * **Verification:** Run `./gradlew build` to confirm the project builds successfully before starting. -3. **Iterative Refactoring and Committing:** - * For each `onClick` function listed in `ON_CLICKS.md` (skipping StreetView-related ones for now), perform the following steps: - a. **Select Target:** Choose a single `onClick` function to refactor. - b. **Refactor Java:** In the `java-app` module, locate the relevant Activity/Fragment, and replace the `onClick` attribute with a programmatic click listener using View Binding. - c. **Refactor Kotlin:** Repeat the process for the corresponding Activity/Fragment in the `kotlin-app` module. - d. **Remove from XML:** Remove the `android:onClick` attribute from the relevant XML layout file(s) in the `common-ui` module. - e. **Verification:** Run `./gradlew build` to ensure the project compiles and the changes are stable. - f. **Commit Changes:** Commit the successful refactoring with a clear, descriptive message (e.g., "Refactor: Replace onClick for onGoToBondi with View Binding"). - g. **Update Tracking File:** Mark the corresponding checkboxes in `ON_CLICKS.md` as complete. +2. **`onClick` Attribute Inventory:** + * Use `ON_CLICKS.md` as the master checklist for all `onClick` attributes to be refactored and tested. -4. **StreetView Activities:** - * Defer refactoring of `onClick` attributes in StreetView-related activities (`StreetViewPanoramaNavigationDemoActivity`, etc.) until a reliable testing strategy can be established for them. +3. **Iterative Refactoring, Testing, and Committing:** + * For each `onClick` function listed in `ON_CLICKS.md`: + a. **Target Selection:** Choose one `onClick` function to process. + b. **Refactor to View Binding (Java):** In the `java-app` module, replace the `android:onClick` XML attribute with a programmatic click listener using View Binding in the relevant Activity/Fragment. + c. **Refactor to View Binding (Kotlin):** Repeat the refactoring for the corresponding Activity/Fragment in the `kotlin-app` module. + d. **XML Cleanup:** Remove the `android:onClick` attribute from the layout file(s) in the `common-ui` module. + e. **Write Verification Test:** Create a basic Espresso test that simulates a click on the button/view and verifies a visible outcome (e.g., a toast message appears, a map camera moves, a UI element changes). This is the primary validation for the `onClick` functionality. + f. **Verification Build:** Run `./gradlew build` and `./gradlew connectedAndroidTest` to ensure the project compiles and the new test passes. + g. **Commit Progress:** Commit the successful refactoring and testing with a clear message (e.g., "Refactor & Test: Replace onClick for onGoToBondi with View Binding and Espresso test."). + h. **Update Checklist:** Mark the corresponding checkboxes in `ON_CLICKS.md` as complete. -5. **Logging:** - * Maintain a high-level summary of progress and lessons learned in `PROGRESS.md`. \ No newline at end of file +4. **Progress Logging:** + * Maintain a summary of progress in `PROGRESS.md`. \ No newline at end of file diff --git a/ApiDemos/project/PROGRESS.md b/ApiDemos/project/PROGRESS.md index ef3f5a8a..c047ad53 100644 --- a/ApiDemos/project/PROGRESS.md +++ b/ApiDemos/project/PROGRESS.md @@ -13,8 +13,9 @@ This file summarizes the progress, successful strategies, and lessons learned du 3. **Refactored Activities:** * **`VisibleRegionDemoActivity`**: Fully refactored for both `java-app` and `kotlin-app`. All `onClick` attributes (`setNoPadding`, `setMorePadding`, `moveToOperaHouse`, `moveToSFO`, `moveToAUS`) have been replaced. * **`SnapshotDemoActivity`**: Fully refactored for both `java-app` and `kotlin-app`. The `onScreenshot` and `onClearScreenshot` `onClick` attributes have been replaced. - * **`UiSettingsDemoActivity`**: Fully refactored. All `onClick` attributes have been replaced. * **`CameraDemoActivity`**: Fully refactored. All `onClick` attributes have been replaced. + * **`UiSettingsDemoActivity`**: Fully refactored. All `onClick` attributes have been replaced. + * **`LiteDemoActivity`**: Fully refactored. All `onClick` attributes have been replaced. * **`OptionsDemoActivity`**: Fixed a lint error that was blocking the build. ### Skipped Tasks diff --git a/ApiDemos/project/common-ui/src/main/res/layout-land/snapshot_demo.xml b/ApiDemos/project/common-ui/src/main/res/layout-land/snapshot_demo.xml index c40b5286..3f59eb7e 100755 --- a/ApiDemos/project/common-ui/src/main/res/layout-land/snapshot_demo.xml +++ b/ApiDemos/project/common-ui/src/main/res/layout-land/snapshot_demo.xml @@ -57,13 +57,10 @@