Skip to content

Comments

feat: Phase 6 - Battery Optimization Testing#422

Merged
hossain-khan merged 1 commit intomainfrom
feature/dev-portal-phase6-battery-optimization
Dec 11, 2025
Merged

feat: Phase 6 - Battery Optimization Testing#422
hossain-khan merged 1 commit intomainfrom
feature/dev-portal-phase6-battery-optimization

Conversation

@hossain-khan
Copy link
Owner

🎯 Phase 6: Battery Optimization Testing

This PR implements Phase 6 of the Developer Portal, adding comprehensive battery optimization testing controls to help developers test and verify the app's battery optimization status and user flow.

✨ Features Implemented

Battery Optimization Testing Card

  • Current Status Display: Shows whether battery optimization is enabled or disabled for the app
  • Visual Indicators:
    • Green checkmark ✓ when optimization is disabled (desired state)
    • Red warning when optimization is enabled
    • Info text explaining the importance of disabling optimization
  • Force Show Reminder Sheet: Button to trigger the battery optimization education bottom sheet on demand
  • Reset Preference: Button to reset the "Don't remind again" preference for testing
  • Open Settings: Button to directly open system battery optimization settings
  • Auto-Refresh: Status automatically refreshes after returning from settings

🏗️ Technical Implementation

State Management

// New state fields
val isBatteryOptimizationEnabled: Boolean  // Current optimization status
val showBatteryOptSheet: Boolean           // Bottom sheet visibility

New Events

data object ShowBatteryOptSheet : Event()
data object DismissBatteryOptSheet : Event()
data object ResetBatteryOptPreference : Event()
data object OpenBatterySettings : Event()

Integration Points

  • BatteryOptimizationHelper.isIgnoringBatteryOptimizations() - Check current status
  • AppPreferencesDataStore.setHideBatteryOptReminder() - Reset preference
  • BatteryOptimizationBottomSheet - Reused existing UI component
  • Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS - System intent

Dependencies Injected

  • AppPreferencesDataStore - Added to presenter constructor for preference management
  • LocalContext - Added to access Android context in Composable

📱 User Flow

  1. View Status: Developer sees current battery optimization state at a glance
  2. Test Reminder: Can trigger the reminder sheet to see what users see
  3. Reset & Retest: Reset the "don't show again" preference to test flow again
  4. Quick Settings: One-tap access to system battery optimization settings
  5. Auto-Refresh: Status updates automatically after changing settings (500ms delay)

🧪 Testing Controls Available

Control Purpose
Status Display Verify current optimization state
Show Reminder Sheet Test user education flow
Reset Preference Clear "don't remind again" flag
Open Settings Quick access to system settings

⚡ Key Implementation Details

  1. Context Handling: Added LocalContext.current in presenter for accessing Android APIs
  2. Coroutine Scoping: All suspend functions properly wrapped in scope.launch
  3. Analytics Integration: Screen views logged for tracking developer interactions
  4. Error Handling: Try-catch blocks with user-friendly error messages
  5. Intent Safety: Wrapped Settings intent in try-catch for edge cases

🎨 UI/UX Features

  • Color-Coded Status: Green for good, red for warning
  • Emoji Icons: 🔋 for battery, ⚙️ for settings, 📊 for status
  • Warning Messages: Clear explanation when optimization is enabled
  • Help Text: Informative notes about automatic status updates
  • Consistent Styling: Matches existing Material3 design system

🔧 Code Changes

Modified Files:

  • DeveloperPortalScreen.kt - Added 211 lines, removed 3 lines

New Imports:

  • android.content.Intent
  • android.net.Uri
  • android.provider.Settings
  • androidx.compose.ui.platform.LocalContext
  • dev.hossain.remotenotify.data.AppPreferencesDataStore
  • dev.hossain.remotenotify.ui.addalert.BatteryOptimizationBottomSheet
  • dev.hossain.remotenotify.utils.BatteryOptimizationHelper

✅ Validation Results

All quality checks passing:

✅ ./gradlew lintKotlin        # Code style checks
✅ ./gradlew test              # Unit tests (89 tests)
✅ ./gradlew assembleDebug     # Build verification
✅ Pre-commit hooks            # Auto-formatting

📸 What It Looks Like

The Battery Optimization Testing card appears in the Developer Portal with:

  • Current status indicator at the top
  • Three action buttons for testing different scenarios
  • Info text explaining auto-refresh behavior
  • Removed from "Coming Soon" section

🔗 Related Issues

Closes #412 - Battery Optimization Testing

Part of epic #416 - Developer Portal Implementation

📊 Progress

Completed: 6 of 7 phases (86%)

🧑‍💻 Testing Instructions

  1. Build and install debug variant
  2. Navigate to: About → Developer Portal (debug-only)
  3. Scroll to "Battery Optimization Testing" section
  4. Test each button:
    • Show Reminder Sheet: Verify bottom sheet appears
    • Reset Preference: Confirm snackbar shows success
    • Open Settings: Verify system settings open correctly
  5. Toggle battery optimization in settings and return to app
  6. Verify status updates automatically

🎓 Learning Points

This implementation demonstrates:

  • Integration with Android's PowerManager API
  • Proper context handling in Compose presenters
  • DataStore preference management
  • System intent handling with error recovery
  • Reusing existing UI components in new contexts
  • Reactive state management with auto-refresh

Ready for Review

All features implemented, tested, and validated. This completes Phase 6 of 7 in the Developer Portal implementation.

Adds Battery Optimization Testing section to Developer Portal with:
- Display current battery optimization status (Enabled/Disabled)
- Button to show battery optimization reminder bottom sheet
- Button to reset 'Don't remind again' preference
- Button to open system battery optimization settings
- Auto-refresh of status after settings changes
- Integration with BatteryOptimizationHelper and AppPreferencesDataStore

Changes:
- Added BatteryOptimizationTestingCard to DeveloperPortalScreen.kt
- New events: ShowBatteryOptSheet, DismissBatteryOptSheet, ResetBatteryOptPreference, OpenBatterySettings
- New state fields: isBatteryOptimizationEnabled, showBatteryOptSheet
- Integrated existing BatteryOptimizationBottomSheet component
- Uses Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS intent
- Removed Battery Optimization from 'Coming Soon' list
- Added proper context handling and coroutine scoping

Closes #412
@hossain-khan hossain-khan merged commit eff2d4d into main Dec 11, 2025
4 of 5 checks passed
@hossain-khan hossain-khan deleted the feature/dev-portal-phase6-battery-optimization branch December 11, 2025 13:11
@github-actions
Copy link

Code Coverage Report

View Coverage Report

@github-actions
Copy link

📊 APK Size Analysis

Comparing mainfeature/dev-portal-phase6-battery-optimization (this PR)

⚠️ Diffuse analysis failed. Check the workflow logs for details.


Generated by Diffuse via diffuse-action

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.

[Dev Portal] Phase 4: Notification Channel Testing

1 participant