Commit 1f0df04
authored
feat: battery optimization prompt for bulk downloads (R539) (#566)
* feat(539): BatteryOptimizationPromptRequest signal class — all tests passing (autoloop iter 1)
* feat(539): BatteryOptimizationChecker utility — all tests passing (autoloop iter 2)
* R539: Fix battery optimization flow emissions in tests
Resolved timing issue where test emissions weren't reaching collectors due to
dispatcher mismatch. The manager's scope was using Dispatchers.IO which the
test's runTest couldn't control.
Changes:
- Added scopeForTesting parameter to AnimeDownloadManager allowing test
environment to inject test's CoroutineScope
- Manager now uses test scope when provided, otherwise uses production scope
with SupervisorJob + Dispatchers.IO
- Updated checkBatteryOptimization() to use scope.launch() for emissions,
which now runs on the test dispatcher in tests
- Updated all 5 battery prompt tests to pass test scope via constructor
- Added advanceUntilIdle() calls to ensure flow emissions complete before
assertions run
All 5 tests now pass:
✓ flow emits when 10+ items queued with optimization enabled
✓ flow does not emit when optimization disabled
✓ flow does not emit when prompt already shown
✓ flow does not emit when fewer than 10 items
✓ flow emits at most once even with multiple rapid calls
This fixes the root cause by making the manager testable via dependency
injection of the coroutine scope, rather than attempting workarounds with
tryEmit() or arbitrary delays.
* R539: Implement battery optimization prompts for MangaDownloadManager
- Add BatteryOptimizationChecker dependency injection to MangaDownloadManager
- Add batteryOptimizationPromptFlow for UI signal emissions
- Implement checkBatteryOptimization() to emit signals when 10+ chapters queued
- Add scope testability via downloaderForTesting and scopeForTesting parameters
- Create MangaDownloadManagerBatteryPromptTest with 5 test scenarios
- All 10 battery prompt tests passing (5 anime + 5 manga)
* R539: Integrate battery optimization dialog into MainActivity
Completes R539 battery optimization prompt feature:
## Changes
- Created BatteryOptimizationDialog Composable: Shows when user queues 10+ downloads with battery optimization enabled
- Displays title, description, and action buttons (Cancel, Open Settings)
- Opens device battery optimization settings via Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)
- Handles API level differences: Android S+ uses app-specific action, earlier versions use general battery settings
- Includes fallback to battery saver settings if device doesn't support the primary intent
- Integrated battery optimization observers into MainActivity
- Injected AnimeDownloadManager and MangaDownloadManager
- Added LaunchedEffect blocks collecting from batteryOptimizationPromptFlow
- Displays dialog separately for anime/manga downloads using state management
- Added localized string resources:
- battery_optimization_title: "Battery Optimization Enabled"
- battery_optimization_description: Explains impact on bulk downloads
- battery_optimization_settings: "Open Settings" button text
## Testing
- All 10 battery optimization prompt tests pass (5 anime + 5 manga):
- Emission with 10+ items and optimization enabled
- No emission with <10 items
- No emission when optimization disabled
- No emission when prompt already shown
- Emission at most once with multiple rapid calls
- No regressions in existing tests
## Architecture Notes
- Dialog follows existing pattern in MainActivity (similar to changelog dialog)
- String keys use existing keys (action_cancel) where available
- Respects owned coroutine scope pattern (viewModelScope in DownloadManager)
* chore(539): fix ktlint max-line-length in battery prompt test files
* docs(539): update changelog (autoloop)
* style(r539): spotless import reorder in MangaDownloadManager
---------
Co-authored-by: ryacub <ryacub@users.noreply.github.com>1 parent 17ac22a commit 1f0df04
12 files changed
Lines changed: 1020 additions & 13 deletions
File tree
- app/src
- main/java/eu/kanade
- presentation/components
- tachiyomi
- data/download
- anime
- core
- manga
- ui/main
- test/java/eu/kanade/tachiyomi/data/download
- anime
- core
- manga
- i18n/src/commonMain/moko-resources/base
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| 23 | + | |
22 | 24 | | |
23 | 25 | | |
24 | 26 | | |
| 27 | + | |
25 | 28 | | |
26 | 29 | | |
27 | 30 | | |
| |||
49 | 52 | | |
50 | 53 | | |
51 | 54 | | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
52 | 58 | | |
53 | 59 | | |
54 | 60 | | |
| |||
Lines changed: 72 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
Lines changed: 42 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
| 10 | + | |
9 | 11 | | |
10 | 12 | | |
11 | 13 | | |
| |||
15 | 17 | | |
16 | 18 | | |
17 | 19 | | |
| 20 | + | |
| 21 | + | |
18 | 22 | | |
19 | 23 | | |
20 | 24 | | |
| |||
53 | 57 | | |
54 | 58 | | |
55 | 59 | | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
56 | 66 | | |
57 | 67 | | |
58 | | - | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
59 | 72 | | |
60 | 73 | | |
61 | 74 | | |
| |||
69 | 82 | | |
70 | 83 | | |
71 | 84 | | |
72 | | - | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
73 | 99 | | |
74 | 100 | | |
75 | 101 | | |
| |||
517 | 543 | | |
518 | 544 | | |
519 | 545 | | |
| 546 | + | |
520 | 547 | | |
521 | 548 | | |
522 | | - | |
523 | | - | |
524 | | - | |
525 | | - | |
| 549 | + | |
526 | 550 | | |
527 | 551 | | |
528 | 552 | | |
529 | 553 | | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
530 | 566 | | |
531 | 567 | | |
532 | 568 | | |
| |||
Lines changed: 14 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
Lines changed: 9 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
Lines changed: 52 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
6 | 8 | | |
7 | 9 | | |
8 | 10 | | |
9 | 11 | | |
10 | 12 | | |
11 | 13 | | |
| 14 | + | |
12 | 15 | | |
13 | 16 | | |
14 | 17 | | |
| 18 | + | |
15 | 19 | | |
| 20 | + | |
| 21 | + | |
16 | 22 | | |
17 | 23 | | |
18 | 24 | | |
| |||
53 | 59 | | |
54 | 60 | | |
55 | 61 | | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
56 | 68 | | |
57 | 69 | | |
58 | | - | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
59 | 73 | | |
60 | 74 | | |
61 | 75 | | |
| |||
65 | 79 | | |
66 | 80 | | |
67 | 81 | | |
68 | | - | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
69 | 108 | | |
70 | 109 | | |
71 | 110 | | |
| |||
506 | 545 | | |
507 | 546 | | |
508 | 547 | | |
509 | | - | |
510 | | - | |
511 | | - | |
512 | | - | |
| 548 | + | |
513 | 549 | | |
514 | 550 | | |
515 | 551 | | |
516 | 552 | | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
517 | 563 | | |
518 | 564 | | |
519 | | - | |
520 | 565 | | |
521 | 566 | | |
522 | 567 | | |
Lines changed: 34 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
| 64 | + | |
64 | 65 | | |
65 | 66 | | |
66 | 67 | | |
| |||
75 | 76 | | |
76 | 77 | | |
77 | 78 | | |
| 79 | + | |
78 | 80 | | |
| 81 | + | |
79 | 82 | | |
80 | 83 | | |
81 | 84 | | |
| |||
130 | 133 | | |
131 | 134 | | |
132 | 135 | | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
133 | 139 | | |
134 | 140 | | |
135 | 141 | | |
| |||
338 | 344 | | |
339 | 345 | | |
340 | 346 | | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
341 | 375 | | |
342 | 376 | | |
343 | 377 | | |
| |||
0 commit comments