Skip to content

Commit 9bbc901

Browse files
Merge pull request #1179 from yogeshpaliyal/addOptionTODisableAutoLock
feat: add option to disable auto lock
2 parents 06dd6b5 + fd70e75 commit 9bbc901

File tree

4 files changed

+288
-306
lines changed

4 files changed

+288
-306
lines changed

app/src/main/java/com/yogeshpaliyal/keypass/ui/nav/DashboardComposeActivity.kt

+92-100
Original file line numberDiff line numberDiff line change
@@ -79,137 +79,129 @@ val LocalUserSettings = compositionLocalOf { UserSettings() }
7979
@AndroidEntryPoint
8080
class DashboardComposeActivity : AppCompatActivity() {
8181

82-
override fun onCreate(savedInstanceState: Bundle?) {
83-
super.onCreate(savedInstanceState)
84-
enableEdgeToEdge()
85-
if (BuildConfig.DEBUG.not()) {
86-
window.setFlags(
87-
WindowManager.LayoutParams.FLAG_SECURE,
88-
WindowManager.LayoutParams.FLAG_SECURE
89-
)
90-
}
91-
92-
setContent {
93-
val localUserSettings by getUserSettingsFlow().collectAsState(initial = UserSettings())
82+
override fun onCreate(savedInstanceState: Bundle?) {
83+
super.onCreate(savedInstanceState)
84+
enableEdgeToEdge()
85+
if (BuildConfig.DEBUG.not()) {
86+
window.setFlags(
87+
WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE)
88+
}
9489

95-
CompositionLocalProvider(LocalUserSettings provides localUserSettings) {
96-
KeyPassTheme {
97-
StoreProvider(store = KeyPassRedux.createStore()) {
98-
Dashboard()
99-
}
100-
}
90+
setContent {
91+
val localUserSettings by getUserSettingsFlow().collectAsState(initial = UserSettings())
92+
93+
CompositionLocalProvider(LocalUserSettings provides localUserSettings) {
94+
KeyPassTheme { StoreProvider(store = KeyPassRedux.createStore()) { Dashboard() } }
95+
}
96+
97+
LaunchedEffect(
98+
key1 = Unit,
99+
block = {
100+
migrateOldDataToNewerDataStore()
101+
val userSettings = getUserSettings()
102+
val buildConfigVersion = BuildConfig.VERSION_CODE
103+
val currentAppVersion = userSettings.currentAppVersion
104+
if (buildConfigVersion != currentAppVersion) {
105+
applicationContext.setUserSettings(
106+
userSettings.copy(
107+
lastAppVersion = currentAppVersion, currentAppVersion = buildConfigVersion))
101108
}
102-
103-
LaunchedEffect(key1 = Unit, block = {
104-
migrateOldDataToNewerDataStore()
105-
val userSettings = getUserSettings()
106-
val buildConfigVersion = BuildConfig.VERSION_CODE
107-
val currentAppVersion = userSettings.currentAppVersion
108-
if (buildConfigVersion != currentAppVersion) {
109-
applicationContext.setUserSettings(
110-
userSettings.copy(
111-
lastAppVersion = currentAppVersion,
112-
currentAppVersion = buildConfigVersion
113-
)
114-
)
115-
}
116-
})
117-
}
109+
})
118110
}
111+
}
119112
}
120113

121114
@Composable
122115
fun Dashboard() {
123-
val systemBackPress by selectState<KeyPassState, Boolean> { this.systemBackPress }
116+
val systemBackPress by selectState<KeyPassState, Boolean> { this.systemBackPress }
124117

125-
val context = LocalContext.current
126-
val dispatch = rememberDispatcher()
118+
val context = LocalContext.current
119+
val userSettings = LocalUserSettings.current
120+
val dispatch = rememberDispatcher()
127121

128-
BackHandler(!systemBackPress) {
129-
dispatch(GoBackAction)
130-
}
122+
BackHandler(!systemBackPress) { dispatch(GoBackAction) }
131123

132-
// Call this like any other SideEffect in your composable
133-
LifecycleEventEffect(Lifecycle.Event.ON_PAUSE) {
134-
if((context.applicationContext as? MyApplication)?.isActivityLaunchTriggered() == false) {
135-
dispatch(NavigationAction(AuthState.Login))
136-
}
124+
// Call this like any other SideEffect in your composable
125+
LifecycleEventEffect(Lifecycle.Event.ON_PAUSE) {
126+
if (userSettings.autoLockEnabled == true &&
127+
(context.applicationContext as? MyApplication)?.isActivityLaunchTriggered() == false) {
128+
dispatch(NavigationAction(AuthState.Login))
137129
}
130+
}
138131

139-
LaunchedEffect(key1 = systemBackPress, block = {
132+
LaunchedEffect(
133+
key1 = systemBackPress,
134+
block = {
140135
if (systemBackPress) {
141-
(context as? ComponentActivity)?.finishAffinity()
136+
(context as? ComponentActivity)?.finishAffinity()
142137
}
143-
})
138+
})
144139

145-
DisposableEffect(KeyPassRedux, context) {
146-
dispatch(UpdateContextAction(context))
147-
onDispose {
148-
dispatch(UpdateContextAction(null))
149-
}
150-
}
140+
DisposableEffect(KeyPassRedux, context) {
141+
dispatch(UpdateContextAction(context))
142+
onDispose { dispatch(UpdateContextAction(null)) }
143+
}
151144

152-
Scaffold(bottomBar = {
153-
KeyPassBottomBar()
154-
}, modifier = Modifier.safeDrawingPadding()) { paddingValues ->
155-
Surface(modifier = Modifier.padding(paddingValues)) {
156-
CurrentPage()
145+
Scaffold(bottomBar = { KeyPassBottomBar() }, modifier = Modifier.safeDrawingPadding()) {
146+
paddingValues ->
147+
Surface(modifier = Modifier.padding(paddingValues)) {
148+
CurrentPage()
157149

158-
DashboardBottomSheet()
159-
}
150+
DashboardBottomSheet()
160151
}
152+
}
161153
}
162154

163155
@Composable
164156
fun CurrentPage() {
165-
val currentScreen by selectState<KeyPassState, KeyPassState> { this }
157+
val currentScreen by selectState<KeyPassState, KeyPassState> { this }
166158

167-
// val currentDialog by selectState<KeyPassState, DialogState?> { this.dialog }
159+
// val currentDialog by selectState<KeyPassState, DialogState?> { this.dialog }
168160

169-
currentScreen.currentScreen.let {
170-
when (it) {
171-
is HomeState -> {
172-
Homepage(homeState = it)
173-
}
161+
currentScreen.currentScreen.let {
162+
when (it) {
163+
is HomeState -> {
164+
Homepage(homeState = it)
165+
}
174166

175-
is SettingsState -> {
176-
MySettingCompose()
177-
}
167+
is SettingsState -> {
168+
MySettingCompose()
169+
}
178170

179-
is AccountDetailState -> {
180-
AccountDetailPage(it.accountId)
181-
}
171+
is AccountDetailState -> {
172+
AccountDetailPage(it.accountId)
173+
}
182174

183-
is AuthState -> {
184-
AuthScreen(it)
185-
}
175+
is AuthState -> {
176+
AuthScreen(it)
177+
}
186178

187-
is BackupScreenState -> {
188-
BackupScreen(state = it)
189-
}
179+
is BackupScreenState -> {
180+
BackupScreen(state = it)
181+
}
190182

191-
is ChangeAppPasswordState -> {
192-
ChangePassword(it)
193-
}
183+
is ChangeAppPasswordState -> {
184+
ChangePassword(it)
185+
}
194186

195-
is ChangeDefaultPasswordLengthState -> {
196-
ChangeDefaultPasswordLengthScreen()
197-
}
187+
is ChangeDefaultPasswordLengthState -> {
188+
ChangeDefaultPasswordLengthScreen()
189+
}
198190

199-
is BackupImporterState -> BackupImporter(state = it)
200-
is AboutState -> AboutScreen()
201-
is PasswordGeneratorState -> GeneratePasswordScreen()
202-
is ChangeAppHintState -> PasswordHintScreen()
203-
}
191+
is BackupImporterState -> BackupImporter(state = it)
192+
is AboutState -> AboutScreen()
193+
is PasswordGeneratorState -> GeneratePasswordScreen()
194+
is ChangeAppHintState -> PasswordHintScreen()
204195
}
205-
206-
currentScreen.dialog?.let {
207-
when (it) {
208-
is ValidateKeyPhrase -> ValidateKeyPhraseDialog()
209-
is ForgotKeyPhraseState -> ForgotKeyPhraseDialog()
210-
is RestoreKeyPassBackupState -> RestoreKeyPassBackupDialog(it)
211-
is RestoreChromeBackupState -> RestoreChromeBackupDialog(it)
212-
is RestoreKeePassBackupState -> RestoreKeePassBackupDialog(it)
213-
}
196+
}
197+
198+
currentScreen.dialog?.let {
199+
when (it) {
200+
is ValidateKeyPhrase -> ValidateKeyPhraseDialog()
201+
is ForgotKeyPhraseState -> ForgotKeyPhraseDialog()
202+
is RestoreKeyPassBackupState -> RestoreKeyPassBackupDialog(it)
203+
is RestoreChromeBackupState -> RestoreChromeBackupDialog(it)
204+
is RestoreKeePassBackupState -> RestoreKeePassBackupDialog(it)
214205
}
206+
}
215207
}

0 commit comments

Comments
 (0)