Fixed baseline tag drift issue: - docs/00-INDEX.md now references docs/progress/00-STATUS.md as canonical baseline - docs/progress/00-STATUS.md marked as canonical baseline authority Created Priority 2.1 mapping and batch planning: - docs/progress/P2.1-METHOD-SERVICE-MAP.md: Complete method-to-service mapping - docs/progress/P2.1-BATCH-1.md: First batch (pure delegation, ~15 methods) - docs/progress/P2.1-BATCH-2.md: Second batch (validation + delegation, ~20 methods) Batch 1 focuses on read-only operations (lowest risk). Batch 2 focuses on validation + delegation (medium risk). Expected reduction: ~1,650-2,000 lines across both platforms. Verification: - Baseline authority fixed ✅ - Method mapping complete ✅ - Batch plans created ✅
310 lines
12 KiB
Markdown
310 lines
12 KiB
Markdown
# Priority 2.1: Batch 2 - Validation + Delegation Methods
|
|
|
|
**Purpose:** Second refactoring batch focusing on methods that validate input then delegate.
|
|
**Owner:** Development Team
|
|
**Last Updated:** 2025-12-23
|
|
**Status:** planned
|
|
**Baseline:** See `docs/progress/00-STATUS.md`
|
|
|
|
---
|
|
|
|
## Batch 2 Scope
|
|
|
|
**Goal:** Refactor methods that validate input, then delegate to services.
|
|
|
|
**Risk Level:** ⭐⭐ Medium (input validation must be preserved, then delegation)
|
|
|
|
**Estimated Impact:** ~20-25 methods across both platforms
|
|
|
|
**Prerequisites:** Batch 1 must be complete and verified
|
|
|
|
---
|
|
|
|
## Android Methods
|
|
|
|
### Permission Requests (Validation + Delegation)
|
|
|
|
1. **`requestNotificationPermissions()`**
|
|
- **Current:** Direct implementation with validation
|
|
- **Target:** `PermissionManager.requestNotificationPermission()`
|
|
- **Change:** Extract validation, delegate to manager
|
|
- **Files:** `DailyNotificationPlugin.kt` (~53 lines → ~10 lines)
|
|
|
|
2. **`requestPermissions()`** (override)
|
|
- **Current:** Direct implementation with validation
|
|
- **Target:** `PermissionManager.requestAllPermissions()`
|
|
- **Change:** Extract validation, delegate to manager
|
|
- **Files:** `DailyNotificationPlugin.kt` (~8 lines → ~5 lines)
|
|
|
|
3. **`requestExactAlarmPermission()`**
|
|
- **Current:** Direct implementation with validation
|
|
- **Target:** `DailyNotificationExactAlarmManager.requestPermission()`
|
|
- **Change:** Extract validation, delegate to manager
|
|
- **Files:** `DailyNotificationPlugin.kt` (~75 lines → ~10 lines)
|
|
|
|
### Settings Navigation (Validation + Delegation)
|
|
|
|
4. **`openExactAlarmSettings()`**
|
|
- **Current:** Direct implementation with activity check
|
|
- **Target:** `DailyNotificationExactAlarmManager.openSettings()`
|
|
- **Change:** Extract activity validation, delegate
|
|
- **Files:** `DailyNotificationPlugin.kt` (~18 lines → ~5 lines)
|
|
|
|
5. **`openChannelSettings()`**
|
|
- **Current:** Direct implementation with activity check
|
|
- **Target:** `ChannelManager.openSettings(channelId)`
|
|
- **Change:** Extract activity validation, delegate
|
|
- **Files:** `DailyNotificationPlugin.kt` (~83 lines → ~5 lines)
|
|
|
|
### Schedule Management CRUD (Validation + Delegation)
|
|
|
|
6. **`createSchedule()`**
|
|
- **Current:** Direct database access with validation
|
|
- **Target:** `DailyNotificationStorage.createSchedule(...)`
|
|
- **Change:** Extract validation, delegate to storage
|
|
- **Files:** `DailyNotificationPlugin.kt` (~25 lines → ~10 lines)
|
|
|
|
7. **`updateSchedule()`**
|
|
- **Current:** Direct database access with validation
|
|
- **Target:** `DailyNotificationStorage.updateSchedule(...)`
|
|
- **Change:** Extract validation, delegate to storage
|
|
- **Files:** `DailyNotificationPlugin.kt` (~39 lines → ~10 lines)
|
|
|
|
8. **`deleteSchedule()`**
|
|
- **Current:** Direct database access with validation
|
|
- **Target:** `DailyNotificationStorage.deleteSchedule(id)`
|
|
- **Change:** Extract validation, delegate to storage
|
|
- **Files:** `DailyNotificationPlugin.kt` (~15 lines → ~5 lines)
|
|
|
|
9. **`enableSchedule()`**
|
|
- **Current:** Direct database access with validation
|
|
- **Target:** `DailyNotificationStorage.enableSchedule(id, enabled)`
|
|
- **Change:** Extract validation, delegate to storage
|
|
- **Files:** `DailyNotificationPlugin.kt` (~15 lines → ~5 lines)
|
|
|
|
### Scheduling Operations (Validation + Delegation)
|
|
|
|
10. **`scheduleDailyNotification()`**
|
|
- **Current:** Direct scheduler access with validation
|
|
- **Target:** `DailyNotificationScheduler.schedule(...)`
|
|
- **Change:** Extract validation, delegate to scheduler
|
|
- **Files:** `DailyNotificationPlugin.kt` (~181 lines → ~15 lines)
|
|
|
|
11. **`scheduleUserNotification()`**
|
|
- **Current:** Direct scheduler access with validation
|
|
- **Target:** `DailyNotificationScheduler.scheduleUserNotification(...)`
|
|
- **Change:** Extract validation, delegate to scheduler
|
|
- **Files:** `DailyNotificationPlugin.kt` (~92 lines → ~15 lines)
|
|
|
|
12. **`scheduleDailyReminder()`**
|
|
- **Current:** Direct reminder manager access with validation
|
|
- **Target:** `DailyReminderManager.schedule(...)`
|
|
- **Change:** Extract validation, delegate to manager
|
|
- **Files:** `DailyNotificationPlugin.kt` (~13 lines → ~5 lines)
|
|
|
|
13. **`testAlarm()`**
|
|
- **Current:** Direct scheduler access with validation
|
|
- **Target:** `DailyNotificationScheduler.scheduleTest(...)`
|
|
- **Change:** Extract validation, delegate to scheduler
|
|
- **Files:** `DailyNotificationPlugin.kt` (~34 lines → ~10 lines)
|
|
|
|
### Callbacks (Validation + Delegation)
|
|
|
|
14. **`registerCallback()`**
|
|
- **Current:** Direct storage access with validation
|
|
- **Target:** `DailyNotificationStorage.registerCallback(...)`
|
|
- **Change:** Extract validation, delegate to storage
|
|
- **Files:** `DailyNotificationPlugin.kt` (~31 lines → ~10 lines)
|
|
|
|
### Test Helpers (Validation + Delegation)
|
|
|
|
15. **`injectInvalidTestData()`**
|
|
- **Current:** Direct database access with validation
|
|
- **Target:** `DailyNotificationStorage.injectTestData(...)`
|
|
- **Change:** Extract validation, delegate to storage
|
|
- **Files:** `DailyNotificationPlugin.kt` (~94 lines → ~10 lines)
|
|
|
|
---
|
|
|
|
## iOS Methods
|
|
|
|
### Permission Requests (Validation + Delegation)
|
|
|
|
1. **`requestNotificationPermissions()`**
|
|
- **Current:** Direct `UNUserNotificationCenter` access with async handling
|
|
- **Target:** Create `PermissionService.requestPermissions()` or use existing pattern
|
|
- **Change:** Extract async handling, delegate to service
|
|
- **Files:** `DailyNotificationPlugin.swift` (~97 lines → ~10 lines)
|
|
|
|
2. **`requestNotificationPermission()`**
|
|
- **Current:** Direct `UNUserNotificationCenter` access with async handling
|
|
- **Target:** Create `PermissionService.requestPermission()` or use existing pattern
|
|
- **Change:** Extract async handling, delegate to service
|
|
- **Files:** `DailyNotificationPlugin.swift` (~29 lines → ~10 lines)
|
|
|
|
### Settings Navigation (Validation + Delegation)
|
|
|
|
3. **`openNotificationSettings()`**
|
|
- **Current:** Direct `UIApplication` access
|
|
- **Target:** Create `SettingsService.openNotificationSettings()` or utility
|
|
- **Change:** Extract app context check, delegate
|
|
- **Files:** `DailyNotificationPlugin.swift` (~32 lines → ~5 lines)
|
|
|
|
4. **`openBackgroundAppRefreshSettings()`**
|
|
- **Current:** Direct `UIApplication` access
|
|
- **Target:** Create `SettingsService.openBackgroundRefreshSettings()` or utility
|
|
- **Change:** Extract app context check, delegate
|
|
- **Files:** `DailyNotificationPlugin.swift` (~32 lines → ~5 lines)
|
|
|
|
5. **`openChannelSettings()`**
|
|
- **Current:** Direct `UIApplication` access
|
|
- **Target:** Create `SettingsService.openChannelSettings()` or utility
|
|
- **Change:** Extract app context check, delegate
|
|
- **Files:** `DailyNotificationPlugin.swift` (~34 lines → ~5 lines)
|
|
|
|
### Schedule Management CRUD (Validation + Delegation)
|
|
|
|
6. **`scheduleDailyReminder()`**
|
|
- **Current:** Direct UserDefaults access with validation
|
|
- **Target:** `DailyNotificationStorage.storeReminder(...)`
|
|
- **Change:** Extract validation, delegate to storage
|
|
- **Files:** `DailyNotificationPlugin.swift` (~90 lines → ~15 lines)
|
|
|
|
7. **`cancelDailyReminder()`**
|
|
- **Current:** Direct UserDefaults access with validation
|
|
- **Target:** `DailyNotificationStorage.removeReminder(id)`
|
|
- **Change:** Extract validation, delegate to storage
|
|
- **Files:** `DailyNotificationPlugin.swift` (~17 lines → ~5 lines)
|
|
|
|
8. **`updateDailyReminder()`**
|
|
- **Current:** Direct UserDefaults access with validation
|
|
- **Target:** `DailyNotificationStorage.updateReminder(...)`
|
|
- **Change:** Extract validation, delegate to storage
|
|
- **Files:** `DailyNotificationPlugin.swift` (~97 lines → ~15 lines)
|
|
|
|
### Scheduling Operations (Validation + Delegation)
|
|
|
|
9. **`scheduleContentFetch()`**
|
|
- **Current:** Direct scheduler access with validation
|
|
- **Target:** `DailyNotificationScheduler.scheduleFetch(...)`
|
|
- **Change:** Extract validation, delegate to scheduler
|
|
- **Files:** `DailyNotificationPlugin.swift` (~17 lines → ~5 lines)
|
|
|
|
10. **`scheduleUserNotification()`**
|
|
- **Current:** Direct scheduler access with validation
|
|
- **Target:** `DailyNotificationScheduler.scheduleUserNotification(...)`
|
|
- **Change:** Extract validation, delegate to scheduler
|
|
- **Files:** `DailyNotificationPlugin.swift` (~17 lines → ~5 lines)
|
|
|
|
11. **`scheduleDailyNotification()`**
|
|
- **Current:** Direct scheduler access with validation
|
|
- **Target:** `DailyNotificationScheduler.schedule(...)`
|
|
- **Change:** Extract validation, delegate to scheduler
|
|
- **Files:** `DailyNotificationPlugin.swift` (~135 lines → ~15 lines)
|
|
|
|
### Configuration (Validation + Delegation)
|
|
|
|
12. **`configure()`**
|
|
- **Current:** Direct storage access with validation
|
|
- **Target:** `DailyNotificationStorage.configure(...)`
|
|
- **Change:** Extract validation, delegate to storage
|
|
- **Files:** `DailyNotificationPlugin.swift` (~75 lines → ~10 lines)
|
|
|
|
13. **`updateSettings()`**
|
|
- **Current:** Direct storage access with validation
|
|
- **Target:** `DailyNotificationStorage.updateSettings(...)`
|
|
- **Change:** Extract validation, delegate to storage
|
|
- **Files:** `DailyNotificationPlugin.swift` (~60 lines → ~10 lines)
|
|
|
|
---
|
|
|
|
## Implementation Steps
|
|
|
|
### Step 1: Verify Service Methods Exist or Create Them
|
|
|
|
- [ ] Verify `PermissionManager.requestNotificationPermission()` exists (Android)
|
|
- [ ] Verify `DailyNotificationExactAlarmManager.requestPermission()` exists (Android)
|
|
- [ ] Verify `DailyNotificationStorage.createSchedule()` exists (Android)
|
|
- [ ] Verify `DailyNotificationScheduler.schedule()` exists (Android)
|
|
- [ ] Create or verify iOS `PermissionService` methods
|
|
- [ ] Create or verify iOS `SettingsService` methods (or utility class)
|
|
|
|
### Step 2: Extract Validation Logic
|
|
|
|
- [ ] Document current validation rules for each method
|
|
- [ ] Create validation helper methods in services (if needed)
|
|
- [ ] Ensure validation errors map to plugin errors correctly
|
|
|
|
### Step 3: Refactor Android Methods
|
|
|
|
- [ ] Refactor permission request methods
|
|
- [ ] Refactor settings navigation methods
|
|
- [ ] Refactor schedule CRUD methods
|
|
- [ ] Refactor scheduling operations
|
|
- [ ] Refactor callback registration
|
|
- [ ] Refactor test helpers
|
|
|
|
### Step 4: Refactor iOS Methods
|
|
|
|
- [ ] Refactor permission request methods
|
|
- [ ] Refactor settings navigation methods
|
|
- [ ] Refactor schedule CRUD methods
|
|
- [ ] Refactor scheduling operations
|
|
- [ ] Refactor configuration methods
|
|
|
|
### Step 5: Testing
|
|
|
|
- [ ] Run Android unit tests (focus on validation)
|
|
- [ ] Run iOS unit tests (focus on validation)
|
|
- [ ] Test invalid input handling
|
|
- [ ] Test valid input flows
|
|
- [ ] Manual smoke test on both platforms
|
|
- [ ] Verify error messages are preserved
|
|
|
|
### Step 6: Verification
|
|
|
|
- [ ] Run `./ci/run.sh` (must pass)
|
|
- [ ] Check plugin class line count reduction
|
|
- [ ] Verify validation logic is preserved
|
|
- [ ] Verify service methods handle validation correctly
|
|
- [ ] Update progress docs
|
|
|
|
---
|
|
|
|
## Expected Outcomes
|
|
|
|
### Metrics
|
|
|
|
- **Android plugin:** ~600-700 lines removed
|
|
- **iOS plugin:** ~500-600 lines removed
|
|
- **Total reduction:** ~1,100-1,300 lines across both platforms
|
|
- **Test coverage:** Maintained (validation logic preserved)
|
|
|
|
### Benefits
|
|
|
|
- ✅ Plugin classes become significantly thinner
|
|
- ✅ Validation logic moves to services (testable)
|
|
- ✅ No breaking API changes
|
|
- ✅ Error handling preserved
|
|
|
|
---
|
|
|
|
## Rollback Plan
|
|
|
|
If issues arise:
|
|
|
|
1. Revert commits for this batch
|
|
2. Service methods remain unchanged (no risk)
|
|
3. Plugin methods can be restored from git history
|
|
4. Validation logic can be re-extracted if needed
|
|
|
|
---
|
|
|
|
## Next Batch
|
|
|
|
After Batch 2 completes successfully:
|
|
|
|
- **Batch 3:** Glue methods (orchestration across multiple services)
|
|
- **Batch 4:** Complex initialization and lifecycle methods
|
|
|