feat: double-back-to-exit on root tab screens#457
feat: double-back-to-exit on root tab screens#457torlando-tech merged 2 commits intotorlando-tech:mainfrom
Conversation
When on a root tab (Chats, Contacts, Map, Settings), pressing back shows a "Press back again to exit" toast instead of navigating between tabs. A second press within 2 seconds finishes the activity. Uses BackHandler with LaunchedEffect for lifecycle-aware timer reset.
Greptile SummaryThis PR adds a double-back-to-exit pattern for root tab screens (Chats, Contacts, Map, Settings) in
Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant BackHandler
participant State as backPressedOnce State
participant Toast
participant LaunchedEffect
participant Activity as ComponentActivity
User->>BackHandler: Press back (on root tab)
BackHandler->>State: Check backPressedOnce
alt First press (backPressedOnce = false)
State-->>BackHandler: false
BackHandler->>State: Set backPressedOnce = true
BackHandler->>Toast: Show "Press back again to exit"
BackHandler->>LaunchedEffect: Triggered (key changed)
LaunchedEffect->>LaunchedEffect: delay(2000ms)
LaunchedEffect->>State: Reset backPressedOnce = false
else Second press within 2s (backPressedOnce = true)
State-->>BackHandler: true
BackHandler->>Activity: finish()
end
Note over User,Activity: Tab switch resets state via remember(currentRoute)
Last reviewed commit: c316aa7 |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Key remember on currentRoute so the "press back again" flag resets when the user navigates to a different tab.
| // Auto-reset the flag after 2 seconds | ||
| LaunchedEffect(backPressedOnce) { | ||
| if (backPressedOnce) { | ||
| kotlinx.coroutines.delay(2000) |
There was a problem hiding this comment.
Use an import for delay
kotlinx.coroutines.delay is used with a fully-qualified name here, while kotlinx.coroutines.launch is already imported at line 109. For consistency, add import kotlinx.coroutines.delay and use the short name.
| kotlinx.coroutines.delay(2000) | |
| delay(2000) |
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Prompt To Fix With AI
This is a comment left during a code review.
Path: app/src/main/java/com/lxmf/messenger/MainActivity.kt
Line: 896:896
Comment:
**Use an import for `delay`**
`kotlinx.coroutines.delay` is used with a fully-qualified name here, while `kotlinx.coroutines.launch` is already imported at line 109. For consistency, add `import kotlinx.coroutines.delay` and use the short name.
```suggestion
delay(2000)
```
<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>
How can I resolve this? If you propose a fix, please make it concise.| import android.widget.Toast | ||
| import android.provider.Settings |
There was a problem hiding this comment.
Import ordering is non-alphabetical
android.widget.Toast should come after android.provider.Settings to maintain alphabetical ordering within the android.* import group.
| import android.widget.Toast | |
| import android.provider.Settings | |
| import android.provider.Settings | |
| import android.widget.Toast |
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Prompt To Fix With AI
This is a comment left during a code review.
Path: app/src/main/java/com/lxmf/messenger/MainActivity.kt
Line: 13:14
Comment:
**Import ordering is non-alphabetical**
`android.widget.Toast` should come after `android.provider.Settings` to maintain alphabetical ordering within the `android.*` import group.
```suggestion
import android.provider.Settings
import android.widget.Toast
```
<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>
How can I resolve this? If you propose a fix, please make it concise.
Summary
Prevents accidental exits and annoying back-navigation between tabs. When on a root tab screen (Chats, Contacts, Map, Settings), pressing the system back button now shows a "Press back again to exit" toast instead of navigating to the previous tab. A second press within 2 seconds closes the app.
How it works
BackHandleris enabled only on root tab screensToastand sets a flagLaunchedEffectauto-resets the flag after 2 secondsfinish()on the activityFiles changed
app/src/main/java/com/lxmf/messenger/MainActivity.kt— addedBackHandler+LaunchedEffectinColumbaNavigation()Testing
compileNoSentryDebugKotlin)