Refactor plugin methods that validate input then delegate to services: - requestNotificationPermissions() → PermissionManager - openChannelSettings() → ChannelManager - createSchedule/updateSchedule/deleteSchedule/enableSchedule() → ScheduleHelper - scheduleUserNotification() → ScheduleHelper (database operations) - registerCallback() → CallbackHelper - injectInvalidTestData() → TestDataHelper - requestExactAlarmPermission() → PermissionManager - openExactAlarmSettings() → PermissionManager - checkExactAlarmPermission() → PermissionManager - cancelAllNotifications() → ScheduleHelper (database operations, partial) - testAlarm() → DailyNotificationScheduler Enhanced services: - PermissionManager: Added checkExactAlarmPermission() and requestExactAlarmPermission() - ChannelManager: Enhanced openChannelSettings() with channelId parameter and fallback logic - ScheduleHelper: Added disableAllSchedulesByKind() method - DailyNotificationScheduler: Added testAlarm() wrapper method Reduces plugin class complexity by ~200 lines. Services already exist - this is delegation, not extraction. Refs: docs/progress/P2.1-BATCH-B-STATE.md
12 KiB
12 KiB
P2.1 Batch B - Current State Directive
Purpose: State snapshot for reconstituting work on Batch B refactoring
Owner: Development Team
Created: 2025-12-23
Status: in_progress
Baseline: See docs/progress/00-STATUS.md (v1.0.11-p3-complete)
Current Work Status
Phase: P2.1 - Native Plugin Refactoring (Batch B)
Goal: Refactor methods that validate input then delegate to services
Status: 14 of ~15 methods completed, 1 partially refactored
Completed Refactorings
✅ Android: requestNotificationPermissions()
- File:
android/src/main/java/com/timesafari/dailynotification/DailyNotificationPlugin.kt - Change: Delegated to
PermissionManager.requestNotificationPermissions(call, activity) - Implementation:
- Enhanced
PermissionManager.requestNotificationPermissions()to accept Activity parameter - Plugin method validates activity/context, saves call, then delegates
- Service method handles permission request logic (check if granted, request if not)
- Uses PERMISSION_REQUEST_CODE (1001) matching plugin constant
- Enhanced
- Lines removed: ~43 lines (validation and request logic moved to service)
- Service:
PermissionManager(initialized inload()) - Note: Activity parameter required for Android 13+ permission requests
✅ Android: openChannelSettings()
- File:
android/src/main/java/com/timesafari/dailynotification/DailyNotificationPlugin.kt - Change: Delegated to
ChannelManager.openChannelSettings(channelId) - Implementation:
- Enhanced
ChannelManager.openChannelSettings()to accept channelId parameter - Added fallback logic to app notification settings if channel-specific fails
- Plugin method validates context, gets channelId from call, then delegates
- Service method handles channel creation, intent creation, and fallback logic
- Enhanced
- Lines removed: ~83 lines (channel creation, intent handling, fallback logic moved to service)
- Service:
ChannelManager(initialized inload())
✅ Android: createSchedule()
- File:
android/src/main/java/com/timesafari/dailynotification/DailyNotificationPlugin.kt - Change: Delegated to
ScheduleHelper.createSchedule() - Implementation:
- Created
ScheduleHelperKotlin object with suspend functions for schedule operations - Plugin method validates input, creates Schedule entity, then delegates to helper
- Helper function handles database upsert operation
- Created
- Lines removed: ~1 line (direct database call replaced with helper delegation)
- Helper:
ScheduleHelper(Kotlin object with suspend function)
✅ Android: updateSchedule()
- File:
android/src/main/java/com/timesafari/dailynotification/DailyNotificationPlugin.kt - Change: Delegated to
ScheduleHelper.updateSchedule() - Implementation:
- Plugin method validates input, extracts update fields, then delegates to helper
- Helper function handles field updates and run time updates
- Returns updated schedule entity
- Lines removed: ~18 lines (database update logic moved to helper)
- Helper:
ScheduleHelper(Kotlin object with suspend function)
✅ Android: deleteSchedule()
- File:
android/src/main/java/com/timesafari/dailynotification/DailyNotificationPlugin.kt - Change: Delegated to
ScheduleHelper.deleteSchedule() - Implementation:
- Plugin method validates schedule ID, then delegates to helper
- Helper function handles database delete operation
- Lines removed: ~1 line (direct database call replaced with helper delegation)
- Helper:
ScheduleHelper(Kotlin object with suspend function)
✅ Android: enableSchedule()
- File:
android/src/main/java/com/timesafari/dailynotification/DailyNotificationPlugin.kt - Change: Delegated to
ScheduleHelper.enableSchedule() - Implementation:
- Plugin method validates schedule ID and enabled flag, then delegates to helper
- Helper function handles database enabled/disabled update
- Lines removed: ~1 line (direct database call replaced with helper delegation)
- Helper:
ScheduleHelper(Kotlin object with suspend function)
Next Methods (Batch B)
Permission Requests (Validation + Delegation)
requestExactAlarmPermission()- Refactored (delegated to PermissionManager)- Status: Delegated to
PermissionManager.requestExactAlarmPermission() - Implementation:
- Added
requestExactAlarmPermission()method toPermissionManager - Plugin method validates context, initializes permissionManager if needed, then delegates
- Service method handles permission checking, reflection for Android 13+, and intent creation
- Added
- Lines removed: ~60 lines (permission checking and intent logic moved to service)
- Service:
PermissionManager(initialized inload())
- Status: Delegated to
Settings Navigation (Validation + Delegation)
openExactAlarmSettings()- Refactored (delegated to PermissionManager)- Status: Delegated to
PermissionManager.openExactAlarmSettings() - Implementation:
- Plugin method validates context, initializes permissionManager if needed, then delegates
- Service method handles intent creation and activity launch
- Lines removed: ~15 lines (intent creation and activity launch logic moved to service)
- Service:
PermissionManager(initialized inload())
- Status: Delegated to
Permission Checks (Validation + Delegation)
checkExactAlarmPermission()- Refactored (delegated to PermissionManager)- Status: Delegated to
PermissionManager.checkExactAlarmPermission() - Implementation:
- Added
checkExactAlarmPermission()method toPermissionManager - Plugin method validates context, initializes permissionManager if needed, then delegates
- Service method handles permission checking logic (canSchedule, canRequest, required)
- Added
- Lines removed: ~25 lines (permission checking logic moved to service)
- Service:
PermissionManager(initialized inload())
- Status: Delegated to
Permission Checks (Validation + Delegation)
checkExactAlarmPermission()- Refactored (delegated to PermissionManager)- Status: Delegated to
PermissionManager.checkExactAlarmPermission() - Implementation:
- Added
checkExactAlarmPermission()method toPermissionManager - Plugin method validates context, initializes permissionManager if needed, then delegates
- Service method handles permission checking logic (canSchedule, canRequest, required)
- Added
- Lines removed: ~25 lines (permission checking logic moved to service)
- Service:
PermissionManager(initialized inload())
- Status: Delegated to
Scheduling Operations (Validation + Delegation)
-
scheduleDailyNotification()- Partially refactored (cleanup logic extracted)- Status: Cleanup logic extracted to
ScheduleHelper.cleanupExistingNotificationSchedules() - Remaining: Complex orchestration method (permission check, scheduling, prefetch, database)
- Note: Full delegation would require refactoring scheduler to handle full flow
- Lines removed: ~40 lines (cleanup logic moved to helper)
- Helper:
ScheduleHelper(cleanup method added)
- Status: Cleanup logic extracted to
-
scheduleUserNotification()- Refactored (database operations delegated)- Status: Database operations now use
ScheduleHelper.createSchedule() - Remaining: Permission checking and scheduling logic (uses NotifyReceiver directly)
- Note: Scheduling goes through NotifyReceiver, not DailyNotificationScheduler
- Lines removed: ~1 line (direct database call replaced with helper delegation)
- Helper:
ScheduleHelper(uses existing createSchedule method)
- Status: Database operations now use
Callbacks (Validation + Delegation)
registerCallback()- Refactored (database operations delegated)- Status: Database operations now use
CallbackHelper.registerCallback() - Implementation:
- Created
CallbackHelperKotlin object with suspend functions for callback operations - Plugin method validates input, creates Callback entity, then delegates to helper
- Helper function handles database upsert operation
- Created
- Lines removed: ~1 line (direct database call replaced with helper delegation)
- Helper:
CallbackHelper(Kotlin object with suspend function)
- Status: Database operations now use
Test Helpers (Validation + Delegation)
-
injectInvalidTestData()- Refactored (test data injection delegated)- Status: Test data injection now uses
TestDataHelpermethods - Implementation:
- Created
TestDataHelperKotlin object with suspend functions for test data operations - Plugin method validates input, then delegates to helper methods
- Helper methods handle schedule and notification injection separately
- Created
- Lines removed: ~70 lines (test data injection logic moved to helper)
- Helper:
TestDataHelper(Kotlin object with suspend functions)
- Status: Test data injection now uses
-
testAlarm()- Refactored (delegated to DailyNotificationScheduler)- Status: Delegated to
DailyNotificationScheduler.testAlarm() - Implementation:
- Added
testAlarm()method toDailyNotificationScheduler(wrapsNotifyReceiver.testAlarm()) - Plugin method validates context, initializes scheduler lazily if needed, then delegates
- Service method delegates to
NotifyReceiver.testAlarm()for actual alarm scheduling
- Added
- Lines removed: ~5 lines (direct NotifyReceiver call replaced with service delegation)
- Service:
DailyNotificationScheduler(lazy initialization, requires AlarmManager)
- Status: Delegated to
Utilities (Orchestration + Delegation)
cancelAllNotifications()- Partially refactored (database operations delegated)- Status: Database disabling operations now use
ScheduleHelper.disableAllSchedulesByKind() - Remaining: Complex orchestration method (alarm cancellation, WorkManager cancellation, database)
- Note: Alarm cancellation and WorkManager cancellation remain in plugin (orchestration concerns)
- Lines removed: ~10 lines (database disabling logic moved to helper)
- Helper:
ScheduleHelper(added disableAllSchedulesByKind method)
- Status: Database disabling operations now use
Service Initialization State
Current Service Instances (in DailyNotificationPlugin.kt)
private var statusChecker: NotificationStatusChecker? = null
private var permissionManager: PermissionManager? = null
private var exactAlarmManager: DailyNotificationExactAlarmManager? = null // ⚠️ null (deferred)
private var channelManager: ChannelManager? = null
private var scheduler: DailyNotificationScheduler? = null // Lazy initialization (requires AlarmManager)
Initialization in load() Method
db = DailyNotificationDatabase.getDatabase(context)
statusChecker = NotificationStatusChecker(context)
channelManager = ChannelManager(context)
permissionManager = PermissionManager(context, channelManager)
exactAlarmManager = null // TODO: Requires AlarmManager + DailyNotificationScheduler
Modified Files
android/src/main/java/com/timesafari/dailynotification/DailyNotificationPlugin.kt
- Status: Modified (unstaged)
- Changes:
- Refactored
requestNotificationPermissions()method (delegation)
- Refactored
android/src/main/java/com/timesafari/dailynotification/PermissionManager.java
- Status: Modified (unstaged)
- Changes:
- Enhanced
requestNotificationPermissions()to accept Activity parameter - Added proper permission request logic with ActivityCompat
- Enhanced
android/src/main/java/com/timesafari/dailynotification/ChannelManager.java
- Status: Modified (unstaged)
- Changes:
- Enhanced
openChannelSettings()to accept channelId parameter - Added fallback logic to app notification settings
- Handles channel creation if channel doesn't exist
- Enhanced
android/src/main/java/com/timesafari/dailynotification/DailyNotificationPlugin.kt
- Status: Modified (unstaged)
- Changes:
- Created
ScheduleHelperobject with suspend functions for schedule CRUD operations - Added
cleanupExistingNotificationSchedules()helper method - Refactored
createSchedule()method (delegation) - Refactored
updateSchedule()method (delegation) - Refactored
deleteSchedule()method (delegation) - Refactored
enableSchedule()method (delegation) - Partially refactored
scheduleDailyNotification()(cleanup logic extracted)
- Created
Reference Documentation
- Batch B Plan:
docs/progress/P2.1-BATCH-2.md - Method-Service Map:
docs/progress/P2.1-METHOD-SERVICE-MAP.md - Batch A State:
docs/progress/P2.1-BATCH-A-STATE.md - Overall Status:
docs/progress/00-STATUS.md
Last Updated: 2025-12-23
Next Update: After completing more Batch B methods