refactor(android): P2.1 Batch A - delegate status/permission methods to services
- Refactor checkStatus() to delegate to NotificationStatusChecker - Refactor getNotificationStatus() to delegate to NotificationStatusChecker - Refactor checkPermissionStatus() to delegate to PermissionManager - Add service instance variables and initialization in load() - Defer getExactAlarmStatus() (requires complex service initialization) Reduces plugin class complexity by ~130 lines. Services already exist - this is delegation, not extraction. Refs: docs/progress/P2.1-BATCH-1.md
This commit is contained in:
@@ -281,5 +281,30 @@ For release notes, see [CHANGELOG.md](../../CHANGELOG.md).
|
||||
|
||||
---
|
||||
|
||||
**Last Updated:** 2025-12-22
|
||||
### 2025-12-23
|
||||
|
||||
**Changed:**
|
||||
- `android/src/main/java/com/timesafari/dailynotification/DailyNotificationPlugin.kt`:
|
||||
- Added service instance variables (`statusChecker`, `permissionManager`, `channelManager`)
|
||||
- Updated `load()` method to initialize services with correct dependencies
|
||||
- Refactored `checkStatus()` to delegate to `NotificationStatusChecker.getComprehensiveStatus()`
|
||||
- Refactored `getNotificationStatus()` to delegate to `NotificationStatusChecker.getNotificationStatus()`
|
||||
- Refactored `checkPermissionStatus()` to delegate to `PermissionManager.checkPermissionStatus()`
|
||||
- Deferred `getExactAlarmStatus()` refactoring (requires complex service initialization)
|
||||
|
||||
**Added:**
|
||||
- `docs/progress/P2.1-BATCH-A-STATE.md` - State directive for reconstituting work on another machine
|
||||
|
||||
**Notes:**
|
||||
- P2.1 Batch A refactoring in progress (3 of ~10 methods completed)
|
||||
- Reduced plugin class complexity by ~130 lines
|
||||
- Services already exist - this is delegation, not extraction
|
||||
- `getExactAlarmStatus()` deferred due to `DailyNotificationExactAlarmManager` requiring `AlarmManager` and `DailyNotificationScheduler` for initialization
|
||||
|
||||
**Related Commits/PRs:**
|
||||
- P2.1 Batch A refactoring (in progress)
|
||||
|
||||
---
|
||||
|
||||
**Last Updated:** 2025-12-23
|
||||
|
||||
|
||||
197
docs/progress/P2.1-BATCH-A-STATE.md
Normal file
197
docs/progress/P2.1-BATCH-A-STATE.md
Normal file
@@ -0,0 +1,197 @@
|
||||
# P2.1 Batch A - Current State Directive
|
||||
|
||||
**Purpose:** State snapshot for reconstituting work on another machine
|
||||
**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 A)
|
||||
**Goal:** Refactor plugin methods to delegate to existing services (thin adapter pattern)
|
||||
**Status:** 3 of ~10 methods completed, 1 deferred
|
||||
|
||||
---
|
||||
|
||||
## Completed Refactorings
|
||||
|
||||
### ✅ Android: `checkStatus()`
|
||||
- **File:** `android/src/main/java/com/timesafari/dailynotification/DailyNotificationPlugin.kt`
|
||||
- **Change:** Delegated to `NotificationStatusChecker.getComprehensiveStatus()`
|
||||
- **Lines removed:** ~50 lines
|
||||
- **Service:** `NotificationStatusChecker` (initialized in `load()`)
|
||||
|
||||
### ✅ Android: `getNotificationStatus()`
|
||||
- **File:** `android/src/main/java/com/timesafari/dailynotification/DailyNotificationPlugin.kt`
|
||||
- **Change:** Delegated to `NotificationStatusChecker.getNotificationStatus()`
|
||||
- **Lines removed:** ~35 lines
|
||||
- **Service:** `NotificationStatusChecker` (initialized in `load()`)
|
||||
|
||||
### ✅ Android: `checkPermissionStatus()`
|
||||
- **File:** `android/src/main/java/com/timesafari/dailynotification/DailyNotificationPlugin.kt`
|
||||
- **Change:** Delegated to `PermissionManager.checkPermissionStatus(call)`
|
||||
- **Lines removed:** ~47 lines
|
||||
- **Service:** `PermissionManager` (initialized in `load()` with `ChannelManager` dependency)
|
||||
|
||||
---
|
||||
|
||||
## Deferred / Known Issues
|
||||
|
||||
### ⚠️ Android: `getExactAlarmStatus()` - Deferred
|
||||
- **Reason:** `DailyNotificationExactAlarmManager` requires complex initialization:
|
||||
- Needs `AlarmManager` (system service)
|
||||
- Needs `DailyNotificationScheduler` instance
|
||||
- Current initialization pattern doesn't support this easily
|
||||
- **Status:** Left original implementation with TODO comment
|
||||
- **Next Step:** Requires refactoring service initialization pattern or creating factory method
|
||||
- **File:** `android/src/main/java/com/timesafari/dailynotification/DailyNotificationPlugin.kt` (line ~285)
|
||||
|
||||
---
|
||||
|
||||
## Service Initialization State
|
||||
|
||||
### Current Service Instances (in `DailyNotificationPlugin.kt`)
|
||||
|
||||
```kotlin
|
||||
private var statusChecker: NotificationStatusChecker? = null
|
||||
private var permissionManager: PermissionManager? = null
|
||||
private var exactAlarmManager: DailyNotificationExactAlarmManager? = null // ⚠️ null (deferred)
|
||||
private var channelManager: ChannelManager? = null
|
||||
```
|
||||
|
||||
### Initialization in `load()` Method
|
||||
|
||||
```kotlin
|
||||
db = DailyNotificationDatabase.getDatabase(context)
|
||||
statusChecker = NotificationStatusChecker(context)
|
||||
channelManager = ChannelManager(context)
|
||||
permissionManager = PermissionManager(context, channelManager)
|
||||
exactAlarmManager = null // TODO: Requires AlarmManager + DailyNotificationScheduler
|
||||
```
|
||||
|
||||
**Note:** `exactAlarmManager` is set to `null` because it requires:
|
||||
- `AlarmManager` from `context.getSystemService(Context.ALARM_SERVICE)`
|
||||
- `DailyNotificationScheduler` instance (which itself needs initialization)
|
||||
|
||||
---
|
||||
|
||||
## Modified Files
|
||||
|
||||
### `android/src/main/java/com/timesafari/dailynotification/DailyNotificationPlugin.kt`
|
||||
- **Status:** Modified (unstaged)
|
||||
- **Changes:**
|
||||
- Added service instance variables (lines ~92-95)
|
||||
- Updated `load()` method to initialize services (lines ~104-108)
|
||||
- Refactored `checkStatus()` method (delegation)
|
||||
- Refactored `getNotificationStatus()` method (delegation)
|
||||
- Refactored `checkPermissionStatus()` method (delegation)
|
||||
- Left `getExactAlarmStatus()` with original implementation + TODO
|
||||
|
||||
---
|
||||
|
||||
## Next Steps (Batch A Continuation)
|
||||
|
||||
### Immediate Next Methods (Low Risk)
|
||||
|
||||
1. **`isChannelEnabled()`** - Delegate to `ChannelManager.isChannelEnabled()`
|
||||
- **Current:** ~77 lines of channel checking logic
|
||||
- **Target:** ~5 lines delegation
|
||||
- **Service:** `ChannelManager` (already initialized)
|
||||
|
||||
2. **`isAlarmScheduled()`** - Delegate to `DailyNotificationScheduler.isScheduled()`
|
||||
- **Current:** Direct AlarmManager access
|
||||
- **Target:** Service delegation
|
||||
- **Service:** Needs `DailyNotificationScheduler` instance (may need initialization)
|
||||
|
||||
3. **`getNextAlarmTime()`** - Delegate to `DailyNotificationScheduler.getNextAlarmTime()`
|
||||
- **Current:** Direct scheduler access
|
||||
- **Target:** Service delegation
|
||||
- **Service:** Needs `DailyNotificationScheduler` instance
|
||||
|
||||
4. **`getContentCache()`** - Delegate to `DailyNotificationStorage.getContentCache()`
|
||||
- **Current:** Direct database access
|
||||
- **Target:** Storage service delegation
|
||||
- **Service:** Needs `DailyNotificationStorage` instance
|
||||
|
||||
### Service Initialization Needs
|
||||
|
||||
Before continuing, may need to:
|
||||
- Initialize `DailyNotificationScheduler` (requires `AlarmManager`)
|
||||
- Initialize `DailyNotificationStorage` (may already exist via database)
|
||||
- Create factory method for `DailyNotificationExactAlarmManager` initialization
|
||||
|
||||
---
|
||||
|
||||
## Reference Documentation
|
||||
|
||||
- **Batch A Plan:** `docs/progress/P2.1-BATCH-1.md`
|
||||
- **Method-Service Map:** `docs/progress/P2.1-METHOD-SERVICE-MAP.md`
|
||||
- **Batch B Plan:** `docs/progress/P2.1-BATCH-2.md`
|
||||
- **Overall Status:** `docs/progress/00-STATUS.md`
|
||||
|
||||
---
|
||||
|
||||
## Verification Checklist
|
||||
|
||||
Before committing or continuing:
|
||||
|
||||
- [ ] Run `./ci/run.sh` (must pass)
|
||||
- [ ] Verify Android plugin compiles
|
||||
- [ ] Check that refactored methods still work (manual test or unit test)
|
||||
- [ ] Verify no breaking API changes
|
||||
- [ ] Update progress docs if needed
|
||||
|
||||
---
|
||||
|
||||
## Commit Message Template
|
||||
|
||||
```
|
||||
refactor(android): P2.1 Batch A - delegate status/permission methods to services
|
||||
|
||||
- Refactor checkStatus() to delegate to NotificationStatusChecker
|
||||
- Refactor getNotificationStatus() to delegate to NotificationStatusChecker
|
||||
- Refactor checkPermissionStatus() to delegate to PermissionManager
|
||||
- Add service instance variables and initialization in load()
|
||||
- Defer getExactAlarmStatus() (requires complex service initialization)
|
||||
|
||||
Reduces plugin class complexity by ~130 lines.
|
||||
Services already exist - this is delegation, not extraction.
|
||||
|
||||
Refs: docs/progress/P2.1-BATCH-1.md
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Key Decisions Made
|
||||
|
||||
1. **Delegation over Extraction:** Services already exist, so we're delegating, not extracting
|
||||
2. **Incremental Approach:** Batch A focuses on pure delegation (lowest risk)
|
||||
3. **Service Initialization:** Using lazy initialization pattern with null checks
|
||||
4. **Complex Services:** Deferring methods that require complex initialization (like `exactAlarmManager`)
|
||||
|
||||
---
|
||||
|
||||
## Testing Notes
|
||||
|
||||
- **Unit Tests:** Should verify service methods are called correctly
|
||||
- **Integration Tests:** Should verify plugin API behavior unchanged
|
||||
- **Manual Testing:** Test each refactored method to ensure behavior 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. No breaking changes to public API
|
||||
|
||||
---
|
||||
|
||||
**Last Updated:** 2025-12-23
|
||||
**Next Update:** After completing more Batch A methods or resolving `getExactAlarmStatus()` initialization
|
||||
|
||||
Reference in New Issue
Block a user