Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.aritra.notify.components.actions

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
Expand Down Expand Up @@ -57,10 +58,10 @@ fun SettingsSwitchCard(
fontSize = 18.sp,
fontFamily = FontFamily(Font(R.font.poppins_semibold))
)
Spacer(modifier = Modifier.weight(1f))
Switch(
modifier = Modifier
.semantics { contentDescription = "Theme Switch" }
.padding(start = 130.dp),
.semantics { contentDescription = "Theme Switch" },
checked = isChecked,
onCheckedChange = onCheckedChange
)
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/com/aritra/notify/di/DataStoreUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class DataStoreUtil @Inject constructor(context: Context) {
companion object {
private val Context.dataStore: DataStore<Preferences> by preferencesDataStore(name = "settings")
val IS_DARK_MODE_KEY = booleanPreferencesKey("dark_mode")
val IS_SECURE_ENV_KEY = booleanPreferencesKey("secure_env")
val IS_BIOMETRIC_AUTH_SET_KEY = booleanPreferencesKey("biometric_auth")
}
}
2 changes: 1 addition & 1 deletion app/src/main/java/com/aritra/notify/di/ThemeState.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package com.aritra.notify.di

data class ThemeState(val isDarkMode: Boolean)
data class ThemeState(val isDarkMode: Boolean, val isSecureEnv: Boolean)
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ fun SettingsScreen() {
fontFamily = FontFamily(Font(R.font.poppins_medium))
)
Spacer(modifier = Modifier.height(6.dp))
SettingsSwitchCard(
text = stringResource(id = R.string.secure_screen),
icon = painterResource(id = R.drawable.phonelink_lock),
isChecked = themeState.isSecureEnv,
onCheckedChange = {
themeViewModel.toggleSecureEnv()
}
)
Spacer(modifier = Modifier.height(6.dp))
SettingsSwitchCard(
text = stringResource(id = R.string.biometric),
icon = painterResource(id = R.drawable.ic_fingerprint),
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/com/aritra/notify/ui/theme/Theme.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.aritra.notify.ui.theme

import android.app.Activity
import android.os.Build
import android.view.WindowManager
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.darkColorScheme
import androidx.compose.material3.dynamicDarkColorScheme
Expand Down Expand Up @@ -93,6 +94,11 @@ fun NotifyTheme(
SideEffect {
val window = (view.context as Activity).window
window.statusBarColor = colorScheme.background.toArgb()
if (themeState.isSecureEnv) {
window.addFlags(WindowManager.LayoutParams.FLAG_SECURE)
} else {
window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE)
}
WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = !themeState.isDarkMode
}
}
Expand Down
16 changes: 14 additions & 2 deletions app/src/main/java/com/aritra/notify/viewmodel/ThemeViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.aritra.notify.di.DataStoreUtil
import com.aritra.notify.di.DataStoreUtil.Companion.IS_DARK_MODE_KEY
import com.aritra.notify.di.DataStoreUtil.Companion.IS_SECURE_ENV_KEY
import com.aritra.notify.di.ThemeState
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.Dispatchers
Expand All @@ -17,15 +18,18 @@ import javax.inject.Inject
@HiltViewModel
class ThemeViewModel @Inject constructor(dataStoreUtil: DataStoreUtil) : ViewModel() {

private val _themeState = MutableStateFlow(ThemeState(false))
private val _themeState = MutableStateFlow(ThemeState(isDarkMode = false, isSecureEnv = false))
val themeState: StateFlow<ThemeState> = _themeState

private val dataStore = dataStoreUtil.dataStore

init {
viewModelScope.launch(Dispatchers.IO) {
dataStore.data.map { preferences ->
ThemeState(preferences[IS_DARK_MODE_KEY] ?: false)
ThemeState(
isDarkMode = preferences[IS_DARK_MODE_KEY] ?: false,
isSecureEnv = preferences[IS_SECURE_ENV_KEY] ?: false
)
}.collect {
_themeState.value = it
}
Expand All @@ -39,4 +43,12 @@ class ThemeViewModel @Inject constructor(dataStoreUtil: DataStoreUtil) : ViewMod
}
}
}

fun toggleSecureEnv() {
viewModelScope.launch(Dispatchers.IO) {
dataStore.edit { preferences ->
preferences[IS_SECURE_ENV_KEY] = !(preferences[IS_SECURE_ENV_KEY] ?: false)
}
}
}
}
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/phonelink_lock.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="#000000"
android:pathData="M622,622Q608,622 597,611Q586,600 586,586L586,482Q586,468 597,457Q608,446 622,446L627,446L627,406Q627,377 646.5,357.5Q666,338 695,338Q724,338 743.5,357.5Q763,377 763,406L763,446L768,446Q782,446 792,457Q802,468 802,482L802,586Q802,600 791,611Q780,622 766,622L622,622ZM655,446L735,446L735,406Q735,389 723.5,377.5Q712,366 695,366Q678,366 666.5,377.5Q655,389 655,406L655,446ZM312,868Q287,868 269.5,850.5Q252,833 252,808L252,152Q252,127 269.5,109.5Q287,92 312,92L648,92Q673,92 690.5,109.5Q708,127 708,152L708,276L680,276L680,214L280,214L280,746L680,746L680,684L708,684L708,808Q708,833 690.5,850.5Q673,868 648,868L312,868ZM280,774L280,808Q280,820 290,830Q300,840 312,840L648,840Q660,840 670,830Q680,820 680,808L680,774L280,774ZM280,186L680,186L680,152Q680,140 670,130Q660,120 648,120L312,120Q300,120 290,130Q280,140 280,152L280,186ZM280,186L280,152Q280,140 280,130Q280,120 280,120L280,120Q280,120 280,130Q280,140 280,152L280,186L280,186ZM280,774L280,774L280,808Q280,820 280,830Q280,840 280,840L280,840Q280,840 280,830Q280,820 280,808L280,774Z"/>
</vector>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,5 @@
<string name="notification_permission_description">The notification permission is important for this app. Please grant the permission.</string>
<string name="notification_permission_settings">The notification permission is important for this app. Please navigate to your device settings and enable notifications for Make it So.</string>
<string name="ok">OK</string>
<string name="secure_screen">Secure Screen</string>
</resources>