-
-
Notifications
You must be signed in to change notification settings - Fork 89
Handle when AccountActivity is started without account #1481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle when AccountActivity is started without account #1481
Conversation
Signed-off-by: Sunik Kupfer <kupfer@bitfire.at>
Signed-off-by: Sunik Kupfer <kupfer@bitfire.at>
…ts overview Signed-off-by: Sunik Kupfer <kupfer@bitfire.at>
d8da9d9
to
0794fb8
Compare
Signed-off-by: Sunik Kupfer <kupfer@bitfire.at>
Signed-off-by: Sunik Kupfer <kupfer@bitfire.at>
Signed-off-by: Sunik Kupfer <kupfer@bitfire.at>
66cc48a
to
8d5b29d
Compare
Signed-off-by: Sunik Kupfer <kupfer@bitfire.at>
cadcaa6
to
4b713ee
Compare
…countException in model
4b713ee
to
1215ca4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR redirects users to the accounts overview and shows a warning when AccountActivity
is started without a valid account, while also cleaning up parcelable handling and making account settings initialization safer.
- Redirect missing/nonexistent account to the overview with logging and a toast.
- Replace deprecated
getParcelableExtra
usage and add nullable fallback. - Catch
InvalidAccountException
inAccountScreenModel
to avoid crashes.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
app/src/main/res/values/strings.xml | Added account_invalid_account string for missing account error |
LoginActivity.kt | Refactored null-check to use let for newAccount |
AccountScreenModel.kt | Wrapped accountSettings creation in try/catch for invalid account |
AccountScreen.kt | Show toast on invalid account state and finish screen |
AccountActivity.kt | Handle missing EXTRA_ACCOUNT by logging and redirecting |
Comments suppressed due to low confidence (1)
app/src/main/kotlin/at/bitfire/davdroid/ui/setup/LoginActivity.kt:42
- [nitpick] The lambda parameter
newAccount
shadows the outer variable. Consider renaming the inner parameter to something likeaccount
ornonNullAccount
to avoid confusion.
newAccount?.let { newAccount ->
app/src/main/kotlin/at/bitfire/davdroid/ui/account/AccountScreenModel.kt
Show resolved
Hide resolved
app/src/main/kotlin/at/bitfire/davdroid/ui/account/AccountScreen.kt
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! I have adapted it a bit:
AccountScreenModel
already checks for invalid accounts, and as little logic as possible should be done in the Activity itself. So I removed the "account exists" check there.AccountScreenModel
actually had a bug (unhandledInvalidAccountException
) when called with an invalid account, fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR improves user flow when AccountActivity
is started without a valid account by logging a warning, showing a toast, and redirecting to the accounts overview instead of throwing. It also updates deprecated APIs and ensures null safety with Kotlin’s let
.
- Add a new string resource for invalid-account messaging
- Switch
LoginActivity
to uselet
for nullable account handling - Catch
InvalidAccountException
inAccountScreenModel
and makeaccountSettings
nullable - Show a toast and finish the screen via
LaunchedEffect
inAccountScreen
- Update
AccountActivity
to useIntentCompat.getParcelableExtra
, log missing accounts, and redirect
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
app/src/main/res/values/strings.xml | Added account_invalid_account string |
app/src/main/kotlin/at/bitfire/davdroid/ui/setup/LoginActivity.kt | Replaced null check with let |
app/src/main/kotlin/at/bitfire/davdroid/ui/account/AccountScreenModel.kt | Handle InvalidAccountException , make accountSettings nullable |
app/src/main/kotlin/at/bitfire/davdroid/ui/account/AccountScreen.kt | Added Toast inside LaunchedEffect for invalid-account case |
app/src/main/kotlin/at/bitfire/davdroid/ui/account/AccountActivity.kt | Use IntentCompat , inject logger, log & redirect on missing account |
Comments suppressed due to low confidence (3)
app/src/main/kotlin/at/bitfire/davdroid/ui/setup/LoginActivity.kt:42
- [nitpick] Lambda parameter shadows the outer
newAccount
. Rename the parameter toaccount
or use the defaultit
to improve readability.
newAccount?.let { newAccount ->
app/src/main/kotlin/at/bitfire/davdroid/ui/account/AccountScreen.kt:204
- The new invalid-account toast and redirect logic isn't covered by existing tests. Consider adding a Compose UI test to verify the toast is shown and
onFinish()
is called wheninvalidAccount
becomes true.
LaunchedEffect(invalidAccount) {
app/src/main/kotlin/at/bitfire/davdroid/ui/account/AccountActivity.kt:24
- [nitpick] Injecting
java.util.logging.Logger
may not be standard in Android. Consider usingandroid.util.Log
or ensure your DI setup provides this logger type as expected.
lateinit var logger: Logger
Purpose
If AccountActivity is started without or with a non-existing account, we throw an exception, but it makes mroe sense to redirect to accounts overview and notify the user/developer who started the activity, that the account was missing.
Short description
getParcelableExtra
.let
construct to ensure account is passed as non-nullable.Checklist