Skip to content

Refactor EditPostActivity by extracting helper classes#22492

Closed
nbradbury wants to merge 7 commits intotrunkfrom
nick/editpostactivity
Closed

Refactor EditPostActivity by extracting helper classes#22492
nbradbury wants to merge 7 commits intotrunkfrom
nick/editpostactivity

Conversation

@nbradbury
Copy link
Contributor

@nbradbury nbradbury commented Jan 16, 2026

Summary

Refactors EditPostActivity by extracting cohesive responsibilities into smaller, testable helper classes.

Phase 1 (Initial commit):

  • MediaUploadCoordinator - Coordinates media upload events between FluxC and the editor
  • PostLoadingStateManager - Manages post loading states and progress dialogs
  • EditorIntentProcessor - Processes editor intents and determines post setup actions

Phase 2:

  • EditorMediaPickerHandler - Handles media picker launching for the post editor
  • EditorActivityResultHandler - Handles activity result processing
  • ShareContentHandler - Handles setting post content from share intents

Phase 3:

  • EditorModeHandler - Manages editor mode switching (HTML/Visual/Gutenberg)
  • EditorNavigationManager - Manages ViewPager navigation and UI updates for destinations

Phase 4:

  • PostPublishingCoordinator - Handles post publishing workflow, email verification, and upload validation

Each handler follows the existing @Reusable Dagger pattern with callback interfaces for Activity-level operations. This approach:

  • Improves testability through dependency injection
  • Reduces EditPostActivity complexity
  • Creates clear separation of concerns
  • Enables independent unit testing of each component

Test plan

Build verification:

  • ./gradlew assembleWordPressVanillaDebug passes
  • ./gradlew detekt passes
  • ./gradlew checkstyle passes
  • ./gradlew :WordPress:testWordPressVanillaDebugUnitTest passes

Manual testing:

Media upload flow:

  1. Create a new post
  2. Add images/videos from device, WP media library, stock photos, and GIFs
  • Verify upload progress shows correctly
  • Verify uploads complete successfully
  • Verify retry works on failed uploads

Activity result handling:

  1. Add media from various sources (camera, gallery, stock media, GIFs)
  • Verify media is added to post correctly
  • Verify cancellation is handled properly

Share content:

  1. Share text/images to WordPress from another app
  • Verify shared content appears in new post

Editor mode switching:

  1. Open a post in the editor
  2. Toggle HTML mode via the menu
  • Verify mode switches and notice appears
  • Verify toggling back to visual mode works

Navigation:

  1. Open post settings
  • Verify title changes appropriately
  • Verify navigation between Editor/Settings/PublishSettings/History works

Publishing flow:

  1. Create a new post with content
  2. Tap the publish button
  • Verify prepublishing bottom sheet appears
  • Verify publishing workflow completes successfully

🤖 Generated with Claude Code

Extract three cohesive responsibilities from EditPostActivity into
testable helper classes, reducing the Activity by ~130 lines:

- MediaUploadCoordinator: Handles media upload event coordination
  between FluxC and the editor (progress, success, error, retry)
- PostLoadingStateManager: Manages post loading state machine and
  progress dialog visibility
- EditorIntentProcessor: Processes editor intents and determines
  appropriate actions (new post, existing post, share, reblog, etc.)

Each helper follows existing patterns using @reusable Dagger injection
with callback interfaces for Activity-level handling.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@dangermattic
Copy link
Collaborator

1 Warning
⚠️ This PR is larger than 300 lines of changes. Please consider splitting it into smaller PRs for easier and faster reviews.
1 Message
📖 This PR is still a Draft: some checks will be skipped.

Generated by 🚫 Danger

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Jan 16, 2026

App Icon📲 You can test the changes from this Pull Request in Jetpack by scanning the QR code below to install the corresponding build.
App NameJetpack
FlavorJalapeno
Build TypeDebug
Versionpr22492-f866f81
Commitf866f81
Direct Downloadjetpack-prototype-build-pr22492-f866f81.apk
Note: Google Login is not supported on these builds.

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Jan 16, 2026

App Icon📲 You can test the changes from this Pull Request in WordPress by scanning the QR code below to install the corresponding build.
App NameWordPress
FlavorJalapeno
Build TypeDebug
Versionpr22492-f866f81
Commitf866f81
Direct Downloadwordpress-prototype-build-pr22492-f866f81.apk
Note: Google Login is not supported on these builds.

Continues refactoring EditPostActivity by extracting three more
cohesive responsibilities into testable helper classes:

- EditorMediaPickerHandler: Handles media picker launching
- EditorActivityResultHandler: Handles activity result processing
- ShareContentHandler: Handles share content from intents

Each handler follows the existing @reusable Dagger pattern with
callback interfaces for Activity-level operations.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@codecov
Copy link

codecov bot commented Jan 16, 2026

Codecov Report

❌ Patch coverage is 51.92630% with 287 lines in your changes missing coverage. Please review.
✅ Project coverage is 39.12%. Comparing base (19696a3) to head (f866f81).
⚠️ Report is 20 commits behind head on trunk.

Files with missing lines Patch % Lines
...droid/ui/posts/editor/PostPublishingCoordinator.kt 21.95% 61 Missing and 3 partials ⚠️
...oid/ui/posts/editor/EditorActivityResultHandler.kt 39.36% 37 Missing and 20 partials ⚠️
...ndroid/ui/posts/editor/EditorMediaPickerHandler.kt 47.36% 17 Missing and 33 partials ⚠️
...s/android/ui/posts/editor/EditorIntentProcessor.kt 68.60% 19 Missing and 8 partials ⚠️
...id/ui/posts/editor/media/MediaUploadCoordinator.kt 52.94% 14 Missing and 10 partials ⚠️
...ess/android/ui/posts/editor/ShareContentHandler.kt 45.00% 12 Missing and 10 partials ⚠️
...press/android/ui/posts/editor/EditorModeHandler.kt 48.71% 17 Missing and 3 partials ⚠️
...android/ui/posts/editor/PostLoadingStateManager.kt 79.68% 9 Missing and 4 partials ⚠️
...android/ui/posts/editor/EditorNavigationManager.kt 78.26% 1 Missing and 9 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##            trunk   #22492      +/-   ##
==========================================
+ Coverage   38.93%   39.12%   +0.19%     
==========================================
  Files        2190     2199       +9     
  Lines      105425   106022     +597     
  Branches    14952    15164     +212     
==========================================
+ Hits        41052    41486     +434     
- Misses      60940    60997      +57     
- Partials     3433     3539     +106     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

nbradbury and others added 3 commits January 16, 2026 17:16
…tivity

Extracts two more helper classes:
- EditorModeHandler - Manages editor mode switching (HTML/Visual/Gutenberg)
- EditorNavigationManager - Manages ViewPager navigation and UI updates

Reduces EditPostActivity by 79 lines with full unit test coverage.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Extracts post publishing and upload coordination logic:
- PostPublishingCoordinator handles primary action, upload, validation, and publish
- Manages email verification checks and empty post validation
- Delegates to StorePostViewModel for actual saving

Reduces EditPostActivity by 91 lines with unit test coverage.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@sonarqubecloud
Copy link

@nbradbury
Copy link
Contributor Author

Closing this as it was just an experiment.

@nbradbury nbradbury closed this Jan 22, 2026
@nbradbury nbradbury deleted the nick/editpostactivity branch February 13, 2026 18:21
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.

3 participants