@@ -79,137 +79,129 @@ val LocalUserSettings = compositionLocalOf { UserSettings() }
79
79
@AndroidEntryPoint
80
80
class DashboardComposeActivity : AppCompatActivity () {
81
81
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
+ }
94
89
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))
101
108
}
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
+ })
118
110
}
111
+ }
119
112
}
120
113
121
114
@Composable
122
115
fun Dashboard () {
123
- val systemBackPress by selectState<KeyPassState , Boolean > { this .systemBackPress }
116
+ val systemBackPress by selectState<KeyPassState , Boolean > { this .systemBackPress }
124
117
125
- val context = LocalContext .current
126
- val dispatch = rememberDispatcher()
118
+ val context = LocalContext .current
119
+ val userSettings = LocalUserSettings .current
120
+ val dispatch = rememberDispatcher()
127
121
128
- BackHandler (! systemBackPress) {
129
- dispatch(GoBackAction )
130
- }
122
+ BackHandler (! systemBackPress) { dispatch(GoBackAction ) }
131
123
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 ))
137
129
}
130
+ }
138
131
139
- LaunchedEffect (key1 = systemBackPress, block = {
132
+ LaunchedEffect (
133
+ key1 = systemBackPress,
134
+ block = {
140
135
if (systemBackPress) {
141
- (context as ? ComponentActivity )?.finishAffinity()
136
+ (context as ? ComponentActivity )?.finishAffinity()
142
137
}
143
- })
138
+ })
144
139
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
+ }
151
144
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 ()
157
149
158
- DashboardBottomSheet ()
159
- }
150
+ DashboardBottomSheet ()
160
151
}
152
+ }
161
153
}
162
154
163
155
@Composable
164
156
fun CurrentPage () {
165
- val currentScreen by selectState<KeyPassState , KeyPassState > { this }
157
+ val currentScreen by selectState<KeyPassState , KeyPassState > { this }
166
158
167
- // val currentDialog by selectState<KeyPassState, DialogState?> { this.dialog }
159
+ // val currentDialog by selectState<KeyPassState, DialogState?> { this.dialog }
168
160
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
+ }
174
166
175
- is SettingsState -> {
176
- MySettingCompose ()
177
- }
167
+ is SettingsState -> {
168
+ MySettingCompose ()
169
+ }
178
170
179
- is AccountDetailState -> {
180
- AccountDetailPage (it.accountId)
181
- }
171
+ is AccountDetailState -> {
172
+ AccountDetailPage (it.accountId)
173
+ }
182
174
183
- is AuthState -> {
184
- AuthScreen (it)
185
- }
175
+ is AuthState -> {
176
+ AuthScreen (it)
177
+ }
186
178
187
- is BackupScreenState -> {
188
- BackupScreen (state = it)
189
- }
179
+ is BackupScreenState -> {
180
+ BackupScreen (state = it)
181
+ }
190
182
191
- is ChangeAppPasswordState -> {
192
- ChangePassword (it)
193
- }
183
+ is ChangeAppPasswordState -> {
184
+ ChangePassword (it)
185
+ }
194
186
195
- is ChangeDefaultPasswordLengthState -> {
196
- ChangeDefaultPasswordLengthScreen ()
197
- }
187
+ is ChangeDefaultPasswordLengthState -> {
188
+ ChangeDefaultPasswordLengthScreen ()
189
+ }
198
190
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 ()
204
195
}
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)
214
205
}
206
+ }
215
207
}
0 commit comments