Skip to content

Commit 4293f0d

Browse files
committed
feat(settings): add a settings option to disable AOD
disabled by default
1 parent 518f172 commit 4293f0d

File tree

10 files changed

+142
-78
lines changed

10 files changed

+142
-78
lines changed

app/src/main/java/org/nsh07/pomodoro/MainActivity.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ class MainActivity : ComponentActivity() {
5151
appContainer.appTimerRepository.colorScheme = colorScheme
5252
}
5353

54-
AppScreen(timerViewModel = timerViewModel, isAODEnabled = true)
54+
AppScreen(
55+
timerViewModel = timerViewModel,
56+
isAODEnabled = preferencesState.aodEnabled
57+
)
5558
}
5659
}
5760
}

app/src/main/java/org/nsh07/pomodoro/ui/AlwaysOnDisplay.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ fun SharedTransitionScope.AlwaysOnDisplay(
177177
}
178178
}
179179

180-
val x by animateIntAsState(randomX)
181-
val y by animateIntAsState(randomY)
180+
val x by animateIntAsState(randomX, motionScheme.slowSpatialSpec())
181+
val y by animateIntAsState(randomY, motionScheme.slowSpatialSpec())
182182

183183
Box(
184184
modifier = modifier

app/src/main/java/org/nsh07/pomodoro/ui/settingsScreen/SettingsScreen.kt

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import android.os.Build
1515
import androidx.activity.compose.rememberLauncherForActivityResult
1616
import androidx.activity.result.contract.ActivityResultContracts
1717
import androidx.annotation.DrawableRes
18+
import androidx.annotation.StringRes
1819
import androidx.compose.animation.AnimatedVisibility
1920
import androidx.compose.foundation.background
2021
import androidx.compose.foundation.clickable
@@ -143,6 +144,7 @@ fun SettingsScreenRoot(
143144
onAlarmEnabledChange = viewModel::saveAlarmEnabled,
144145
onVibrateEnabledChange = viewModel::saveVibrateEnabled,
145146
onBlackThemeChange = viewModel::saveBlackTheme,
147+
onAodEnabledChange = viewModel::saveAodEnabled,
146148
onAlarmSoundChanged = {
147149
viewModel.saveAlarmSound(it)
148150
Intent(context, TimerService::class.java).apply {
@@ -170,6 +172,7 @@ private fun SettingsScreen(
170172
onAlarmEnabledChange: (Boolean) -> Unit,
171173
onVibrateEnabledChange: (Boolean) -> Unit,
172174
onBlackThemeChange: (Boolean) -> Unit,
175+
onAodEnabledChange: (Boolean) -> Unit,
173176
onAlarmSoundChanged: (Uri?) -> Unit,
174177
onThemeChange: (String) -> Unit,
175178
onColorSchemeChange: (Color) -> Unit,
@@ -181,14 +184,14 @@ private fun SettingsScreen(
181184
checkedIconColor = colorScheme.primary,
182185
)
183186

184-
val themeMap: Map<String, Pair<Int, String>> = remember {
187+
val themeMap: Map<String, Pair<Int, Int>> = remember {
185188
mapOf(
186189
"auto" to Pair(
187190
R.drawable.brightness_auto,
188-
context.getString(R.string.system_default)
191+
R.string.system_default
189192
),
190-
"light" to Pair(R.drawable.light_mode, context.getString(R.string.light)),
191-
"dark" to Pair(R.drawable.dark_mode, context.getString(R.string.dark))
193+
"light" to Pair(R.drawable.light_mode, R.string.light),
194+
"dark" to Pair(R.drawable.dark_mode, R.string.dark)
192195
)
193196
}
194197
val reverseThemeMap: Map<String, String> = remember {
@@ -232,27 +235,39 @@ private fun SettingsScreen(
232235
putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, alarmSound.toUri())
233236
}
234237

235-
val switchItems = remember(preferencesState.blackTheme, alarmEnabled, vibrateEnabled) {
238+
val switchItems = remember(
239+
preferencesState.blackTheme,
240+
preferencesState.aodEnabled,
241+
alarmEnabled,
242+
vibrateEnabled
243+
) {
236244
listOf(
237245
SettingsSwitchItem(
238246
checked = preferencesState.blackTheme,
239247
icon = R.drawable.contrast,
240-
label = context.getString(R.string.black_theme),
241-
description = context.getString(R.string.black_theme_desc),
248+
label = R.string.black_theme,
249+
description = R.string.black_theme_desc,
242250
onClick = onBlackThemeChange
243251
),
252+
SettingsSwitchItem(
253+
checked = preferencesState.aodEnabled,
254+
icon = R.drawable.aod,
255+
label = R.string.always_on_display,
256+
description = R.string.always_on_display_desc,
257+
onClick = onAodEnabledChange
258+
),
244259
SettingsSwitchItem(
245260
checked = alarmEnabled,
246261
icon = R.drawable.alarm_on,
247-
label = context.getString(R.string.alarm),
248-
description = context.getString(R.string.alarm_desc),
262+
label = R.string.alarm,
263+
description = R.string.alarm_desc,
249264
onClick = onAlarmEnabledChange
250265
),
251266
SettingsSwitchItem(
252267
checked = vibrateEnabled,
253268
icon = R.drawable.mobile_vibrate,
254-
label = context.getString(R.string.vibrate),
255-
description = context.getString(R.string.vibrate_desc),
269+
label = R.string.vibrate,
270+
description = R.string.vibrate_desc,
256271
onClick = onVibrateEnabledChange
257272
)
258273
)
@@ -404,14 +419,13 @@ private fun SettingsScreen(
404419
.clip(middleListItemShape)
405420
)
406421
}
407-
item {
408-
val item = switchItems[0]
422+
itemsIndexed(switchItems.take(2)) { index, item ->
409423
ListItem(
410424
leadingContent = {
411425
Icon(painterResource(item.icon), contentDescription = null)
412426
},
413-
headlineContent = { Text(item.label) },
414-
supportingContent = { Text(item.description) },
427+
headlineContent = { Text(stringResource(item.label)) },
428+
supportingContent = { Text(stringResource(item.description)) },
415429
trailingContent = {
416430
Switch(
417431
checked = item.checked,
@@ -435,7 +449,9 @@ private fun SettingsScreen(
435449
)
436450
},
437451
colors = listItemColors,
438-
modifier = Modifier.clip(bottomListItemShape)
452+
modifier = Modifier
453+
.padding(top = if (index != 0) 16.dp else 0.dp)
454+
.clip(if (index == 0) bottomListItemShape else cardShape)
439455
)
440456
}
441457

@@ -454,13 +470,13 @@ private fun SettingsScreen(
454470
.clickable(onClick = { ringtonePickerLauncher.launch(intent) })
455471
)
456472
}
457-
itemsIndexed(switchItems.drop(1)) { index, item ->
473+
itemsIndexed(switchItems.drop(2)) { index, item ->
458474
ListItem(
459475
leadingContent = {
460476
Icon(painterResource(item.icon), contentDescription = null)
461477
},
462-
headlineContent = { Text(item.label) },
463-
supportingContent = { Text(item.description) },
478+
headlineContent = { Text(stringResource(item.label)) },
479+
supportingContent = { Text(stringResource(item.description)) },
464480
trailingContent = {
465481
Switch(
466482
checked = item.checked,
@@ -487,7 +503,7 @@ private fun SettingsScreen(
487503
modifier = Modifier
488504
.clip(
489505
when (index) {
490-
switchItems.lastIndex - 1 -> bottomListItemShape
506+
switchItems.lastIndex - 2 -> bottomListItemShape
491507
else -> middleListItemShape
492508
}
493509
)
@@ -546,6 +562,7 @@ fun SettingsScreenPreview() {
546562
onAlarmEnabledChange = {},
547563
onVibrateEnabledChange = {},
548564
onBlackThemeChange = {},
565+
onAodEnabledChange = {},
549566
onAlarmSoundChanged = {},
550567
onThemeChange = {},
551568
onColorSchemeChange = {},
@@ -557,7 +574,7 @@ fun SettingsScreenPreview() {
557574
data class SettingsSwitchItem(
558575
val checked: Boolean,
559576
@param:DrawableRes val icon: Int,
560-
val label: String,
561-
val description: String,
577+
@param:StringRes val label: Int,
578+
@param:StringRes val description: Int,
562579
val onClick: (Boolean) -> Unit
563580
)

app/src/main/java/org/nsh07/pomodoro/ui/settingsScreen/ThemeDialog.kt

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@ import androidx.compose.material3.Surface
3131
import androidx.compose.material3.Text
3232
import androidx.compose.material3.TextButton
3333
import androidx.compose.runtime.Composable
34-
import androidx.compose.runtime.mutableStateOf
34+
import androidx.compose.runtime.mutableIntStateOf
3535
import androidx.compose.runtime.remember
3636
import androidx.compose.ui.Alignment
3737
import androidx.compose.ui.Modifier
3838
import androidx.compose.ui.draw.clip
39+
import androidx.compose.ui.platform.LocalContext
3940
import androidx.compose.ui.res.painterResource
4041
import androidx.compose.ui.res.stringResource
4142
import androidx.compose.ui.semantics.Role
@@ -50,14 +51,16 @@ import org.nsh07.pomodoro.ui.theme.TomatoShapeDefaults.topListItemShape
5051
@OptIn(ExperimentalMaterial3Api::class, ExperimentalMaterial3ExpressiveApi::class)
5152
@Composable
5253
fun ThemeDialog(
53-
themeMap: Map<String, Pair<Int, String>>,
54+
themeMap: Map<String, Pair<Int, Int>>,
5455
reverseThemeMap: Map<String, String>,
5556
theme: String,
5657
setShowThemeDialog: (Boolean) -> Unit,
5758
onThemeChange: (String) -> Unit
5859
) {
5960
val selectedOption =
60-
remember { mutableStateOf(themeMap[theme]!!.second) }
61+
remember { mutableIntStateOf(themeMap[theme]!!.second) }
62+
63+
val context = LocalContext.current
6164

6265
BasicAlertDialog(
6366
onDismissRequest = { setShowThemeDialog(false) }
@@ -80,7 +83,7 @@ fun ThemeDialog(
8083
verticalArrangement = Arrangement.spacedBy(2.dp),
8184
modifier = Modifier.selectableGroup()
8285
) {
83-
themeMap.entries.forEachIndexed { index: Int, pair: Map.Entry<String, Pair<Int, String>> ->
86+
themeMap.entries.forEachIndexed { index: Int, pair: Map.Entry<String, Pair<Int, Int>> ->
8487
val text = pair.value.second
8588
val selected = text == selectedOption.value
8689

@@ -94,7 +97,10 @@ fun ThemeDialog(
9497
}
9598
},
9699
headlineContent = {
97-
Text(text = text, style = MaterialTheme.typography.bodyLarge)
100+
Text(
101+
text = stringResource(text),
102+
style = MaterialTheme.typography.bodyLarge
103+
)
98104
},
99105
colors = if (!selected) listItemColors else selectedListItemColors,
100106
modifier = Modifier
@@ -110,7 +116,11 @@ fun ThemeDialog(
110116
selected = (text == selectedOption.value),
111117
onClick = {
112118
selectedOption.value = text
113-
onThemeChange(reverseThemeMap[selectedOption.value]!!)
119+
onThemeChange(
120+
reverseThemeMap[context.getString(
121+
selectedOption.intValue
122+
)]!!
123+
)
114124
},
115125
role = Role.RadioButton
116126
)

app/src/main/java/org/nsh07/pomodoro/ui/settingsScreen/ThemePickerListItem.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import org.nsh07.pomodoro.ui.theme.CustomColors.listItemColors
2525
@Composable
2626
fun ThemePickerListItem(
2727
theme: String,
28-
themeMap: Map<String, Pair<Int, String>>,
28+
themeMap: Map<String, Pair<Int, Int>>,
2929
reverseThemeMap: Map<String, String>,
3030
items: Int,
3131
index: Int,
@@ -53,7 +53,7 @@ fun ThemePickerListItem(
5353
},
5454
headlineContent = { Text(stringResource(R.string.theme)) },
5555
supportingContent = {
56-
Text(themeMap[theme]!!.second)
56+
Text(stringResource(themeMap[theme]!!.second))
5757
},
5858
colors = listItemColors,
5959
items = items,

app/src/main/java/org/nsh07/pomodoro/ui/settingsScreen/viewModel/PreferencesState.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ import androidx.compose.ui.graphics.Color
1414
data class PreferencesState(
1515
val theme: String = "auto",
1616
val colorScheme: String = Color.White.toString(),
17-
val blackTheme: Boolean = false
17+
val blackTheme: Boolean = false,
18+
val aodEnabled: Boolean = false
1819
)

app/src/main/java/org/nsh07/pomodoro/ui/settingsScreen/viewModel/SettingsViewModel.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,15 @@ class SettingsViewModel(
8080
?: preferenceRepository.saveStringPreference("color_scheme", Color.White.toString())
8181
val blackTheme = preferenceRepository.getBooleanPreference("black_theme")
8282
?: preferenceRepository.saveBooleanPreference("black_theme", false)
83+
val aodEnabled = preferenceRepository.getBooleanPreference("aod_enabled")
84+
?: preferenceRepository.saveBooleanPreference("aod_enabled", false)
8385

8486
_preferencesState.update { currentState ->
8587
currentState.copy(
8688
theme = theme,
8789
colorScheme = colorScheme,
88-
blackTheme = blackTheme
90+
blackTheme = blackTheme,
91+
aodEnabled = aodEnabled
8992
)
9093
}
9194
}
@@ -196,6 +199,15 @@ class SettingsViewModel(
196199
}
197200
}
198201

202+
fun saveAodEnabled(aodEnabled: Boolean) {
203+
viewModelScope.launch {
204+
_preferencesState.update { currentState ->
205+
currentState.copy(aodEnabled = aodEnabled)
206+
}
207+
preferenceRepository.saveBooleanPreference("aod_enabled", aodEnabled)
208+
}
209+
}
210+
199211
companion object {
200212
val Factory: ViewModelProvider.Factory = viewModelFactory {
201213
initializer {

app/src/main/java/org/nsh07/pomodoro/ui/timerScreen/viewModel/TimerViewModel.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ class TimerViewModel(
9595
)
9696
).toUri()
9797

98+
preferenceRepository.getBooleanPreference("aod_enabled")
99+
?: preferenceRepository.saveBooleanPreference("aod_enabled", false)
100+
98101
_time.update { timerRepository.focusTime }
99102
cycles = 0
100103
startTime = 0L

app/src/main/res/drawable/aod.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!--
2+
~ Copyright (c) 2025 Nishant Mishra
3+
~
4+
~ You should have received a copy of the GNU General Public License
5+
~ along with this program. If not, see <https://www.gnu.org/licenses/>.
6+
-->
7+
8+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
9+
android:width="24dp"
10+
android:height="24dp"
11+
android:viewportWidth="960"
12+
android:viewportHeight="960">
13+
<path
14+
android:fillColor="#e3e3e3"
15+
android:pathData="M360,480h240q17,0 28.5,-11.5T640,440q0,-17 -11.5,-28.5T600,400L360,400q-17,0 -28.5,11.5T320,440q0,17 11.5,28.5T360,480ZM400,620h160q17,0 28.5,-11.5T600,580q0,-17 -11.5,-28.5T560,540L400,540q-17,0 -28.5,11.5T360,580q0,17 11.5,28.5T400,620ZM280,920q-33,0 -56.5,-23.5T200,840v-720q0,-33 23.5,-56.5T280,40h400q33,0 56.5,23.5T760,120v124q18,7 29,22t11,34v80q0,19 -11,34t-29,22v404q0,33 -23.5,56.5T680,920L280,920Z" />
16+
</vector>

0 commit comments

Comments
 (0)