|
1 | 1 | package com.sysadmindoc.callshield.data |
2 | 2 |
|
3 | 3 | import android.content.Context |
| 4 | +import com.sysadmindoc.callshield.R |
4 | 5 |
|
5 | | -/** |
6 | | - * Blocking profiles — preset configurations for different scenarios. |
7 | | - * Work: block all spam, allow unknown (clients may call) |
8 | | - * Personal: block spam + unknown numbers |
9 | | - * Sleep: block everything except contacts |
10 | | - * Off: disable all blocking |
11 | | - */ |
| 6 | +/** Presets for the call and message controls changed together by a profile. */ |
12 | 7 | object BlockingProfiles { |
| 8 | + data class Settings( |
| 9 | + val blockCalls: Boolean = true, |
| 10 | + val analyzeSms: Boolean = true, |
| 11 | + val blockHidden: Boolean = false, |
| 12 | + val aggressive: Boolean = false, |
| 13 | + val quietHours: Boolean = false, |
| 14 | + val contactsOnly: Boolean = false, |
| 15 | + ) |
| 16 | + |
| 17 | + data class Snapshot( |
| 18 | + val settings: Settings, |
| 19 | + val activeProfileName: String?, |
| 20 | + ) |
| 21 | + |
13 | 22 | enum class Profile( |
14 | | - val label: String, |
15 | | - val description: String, |
| 23 | + val labelRes: Int, |
| 24 | + val descriptionRes: Int, |
| 25 | + val settings: Settings, |
16 | 26 | ) { |
17 | | - WORK("Work", "Block spam, allow unknown callers"), |
18 | | - PERSONAL("Personal", "Block spam + unknown numbers"), |
19 | | - SLEEP("Sleep", "Block everything except contacts"), |
20 | | - MAX("Maximum", "Aggressive mode + block unknowns + quiet hours"), |
21 | | - OFF("Off", "Disable all blocking"), |
| 27 | + WORK(R.string.onboarding_profile_recommended, R.string.profile_work_description, Settings()), |
| 28 | + PERSONAL( |
| 29 | + R.string.dashboard_profile_personal, |
| 30 | + R.string.profile_personal_description, |
| 31 | + Settings(blockHidden = true), |
| 32 | + ), |
| 33 | + SLEEP( |
| 34 | + R.string.dashboard_profile_sleep, |
| 35 | + R.string.profile_sleep_description, |
| 36 | + Settings(blockHidden = true, quietHours = true), |
| 37 | + ), |
| 38 | + MAX( |
| 39 | + R.string.onboarding_profile_strict, |
| 40 | + R.string.profile_maximum_description, |
| 41 | + Settings(blockHidden = true, aggressive = true, quietHours = true), |
| 42 | + ), |
| 43 | + OFF( |
| 44 | + R.string.dashboard_profile_off, |
| 45 | + R.string.profile_off_description, |
| 46 | + Settings(blockCalls = false, analyzeSms = false), |
| 47 | + ), |
| 48 | + CONTACTS_ONLY( |
| 49 | + R.string.dashboard_profile_contacts_only, |
| 50 | + R.string.profile_contacts_only_description, |
| 51 | + Settings(blockHidden = true, contactsOnly = true), |
| 52 | + ), |
22 | 53 | } |
23 | 54 |
|
24 | 55 | suspend fun apply( |
25 | 56 | context: Context, |
26 | 57 | profile: Profile, |
27 | | - ) { |
28 | | - val repo = SpamRepository.getInstance(context) |
29 | | - when (profile) { |
30 | | - Profile.WORK -> { |
31 | | - repo.setBlockCalls(true) |
32 | | - repo.setBlockSms(true) |
33 | | - repo.setBlockUnknown(false) |
34 | | - repo.setAggressiveMode(false) |
35 | | - repo.setTimeBlock(false) |
36 | | - } |
37 | | - |
38 | | - Profile.PERSONAL -> { |
39 | | - repo.setBlockCalls(true) |
40 | | - repo.setBlockSms(true) |
41 | | - repo.setBlockUnknown(true) |
42 | | - repo.setAggressiveMode(false) |
43 | | - repo.setTimeBlock(false) |
44 | | - } |
| 58 | + ): Snapshot = SpamRepository.getInstance(context).replaceBlockingSettings(profile.settings, profile.name) |
45 | 59 |
|
46 | | - Profile.SLEEP -> { |
47 | | - repo.setBlockCalls(true) |
48 | | - repo.setBlockSms(true) |
49 | | - repo.setBlockUnknown(true) |
50 | | - repo.setAggressiveMode(false) |
51 | | - repo.setTimeBlock(true) |
52 | | - } |
53 | | - |
54 | | - Profile.MAX -> { |
55 | | - repo.setBlockCalls(true) |
56 | | - repo.setBlockSms(true) |
57 | | - repo.setBlockUnknown(true) |
58 | | - repo.setAggressiveMode(true) |
59 | | - repo.setTimeBlock(true) |
60 | | - } |
61 | | - |
62 | | - Profile.OFF -> { |
63 | | - repo.setBlockCalls(false) |
64 | | - repo.setBlockSms(false) |
65 | | - repo.setBlockUnknown(false) |
66 | | - repo.setAggressiveMode(false) |
67 | | - repo.setTimeBlock(false) |
68 | | - } |
69 | | - } |
| 60 | + suspend fun restore( |
| 61 | + context: Context, |
| 62 | + snapshot: Snapshot, |
| 63 | + ) { |
| 64 | + SpamRepository.getInstance(context).replaceBlockingSettings(snapshot.settings, snapshot.activeProfileName) |
70 | 65 | } |
71 | 66 | } |
0 commit comments