- Add ScheduleHelper.cancelAlarmsForSchedules() helper method - Add ScheduleHelper.cancelAllWorkManagerJobs() helper method - Refactor cancelAllNotifications() to delegate to helpers - Keep orchestration in plugin (appropriate for multi-service coordination) Reduces plugin method from ~85 lines to ~45 lines. Batch B complete: 15 methods refactored to thin adapter pattern. Refs: docs/progress/P2.1-BATCH-B-STATE.md
13 KiB
13 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: ✅ BATCH B COMPLETE — 15 methods 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()- ✅ COMPLETE- File:
android/src/main/java/com/timesafari/dailynotification/DailyNotificationPlugin.kt - Change: Delegated alarm cancellation and WorkManager cancellation to
ScheduleHelper - Implementation:
- Added
ScheduleHelper.cancelAlarmsForSchedules()to cancel alarms for a list of schedules - Added
ScheduleHelper.cancelAllWorkManagerJobs()to cancel all WorkManager jobs by tags - Plugin method orchestrates: get schedules → cancel alarms → cancel WorkManager → disable schedules
- Keeps orchestration in plugin (appropriate for coordinating multiple services)
- Added
- Lines removed: ~60 lines (alarm cancellation and WorkManager cancellation logic moved to helpers)
- Helper:
ScheduleHelper(addedcancelAlarmsForSchedules()andcancelAllWorkManagerJobs()methods)
- File:
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