Skip to content

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

Merged

Conversation

sunkup
Copy link
Member

@sunkup sunkup commented May 21, 2025

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

  • if started without or non-existing account, redirect to accounts overview
  • also log warning and show toast message
  • handle deprecated getParcelableExtra
  • Use .let construct to ensure account is passed as non-nullable.

Checklist

  • The PR has a proper title, description and label.
  • I have self-reviewed the PR.
  • I have added documentation to complex functions and functions that can be used by other modules.
  • I have added reasonable tests or consciously decided to not add tests.

@sunkup sunkup self-assigned this May 21, 2025
@sunkup sunkup added the bug Something isn't working label May 21, 2025
@sunkup sunkup linked an issue May 21, 2025 that may be closed by this pull request
sunkup added 3 commits May 22, 2025 10:19
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>
@sunkup sunkup force-pushed the 1384-illegalargumentexception-in-accountactivityoncreate branch from d8da9d9 to 0794fb8 Compare May 22, 2025 09:02
sunkup added 3 commits May 22, 2025 11:41
Signed-off-by: Sunik Kupfer <kupfer@bitfire.at>
Signed-off-by: Sunik Kupfer <kupfer@bitfire.at>
Signed-off-by: Sunik Kupfer <kupfer@bitfire.at>
@sunkup sunkup force-pushed the 1384-illegalargumentexception-in-accountactivityoncreate branch from 66cc48a to 8d5b29d Compare May 22, 2025 09:43
Signed-off-by: Sunik Kupfer <kupfer@bitfire.at>
@sunkup sunkup marked this pull request as ready for review May 22, 2025 10:25
@sunkup sunkup requested review from ArnyminerZ and removed request for ArnyminerZ May 22, 2025 10:25
@sunkup sunkup marked this pull request as draft May 22, 2025 10:26
@sunkup sunkup changed the title Pass new account as non-nullable Redirect and notify user when account activity was started without account May 22, 2025
@sunkup sunkup changed the title Redirect and notify user when account activity was started without account Redirect and notify user when account activity is started without account May 22, 2025
@sunkup sunkup requested a review from ArnyminerZ May 22, 2025 10:31
@sunkup sunkup marked this pull request as ready for review May 22, 2025 10:31
@rfc2822 rfc2822 self-assigned this May 22, 2025
@rfc2822 rfc2822 force-pushed the 1384-illegalargumentexception-in-accountactivityoncreate branch from cadcaa6 to 4b713ee Compare May 22, 2025 15:05
@rfc2822 rfc2822 force-pushed the 1384-illegalargumentexception-in-accountactivityoncreate branch from 4b713ee to 1215ca4 Compare May 22, 2025 15:07
@rfc2822 rfc2822 requested a review from Copilot May 22, 2025 15:08
Copy link
Contributor

@Copilot Copilot AI left a 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 in AccountScreenModel 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 like account or nonNullAccount to avoid confusion.
newAccount?.let { newAccount ->

rfc2822
rfc2822 previously approved these changes May 22, 2025
Copy link
Member

@rfc2822 rfc2822 left a 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 (unhandled InvalidAccountException) when called with an invalid account, fixed.

@rfc2822 rfc2822 requested a review from Copilot May 22, 2025 15:13
@rfc2822 rfc2822 removed the request for review from ArnyminerZ May 22, 2025 15:13
Copy link
Contributor

@Copilot Copilot AI left a 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 use let for nullable account handling
  • Catch InvalidAccountException in AccountScreenModel and make accountSettings nullable
  • Show a toast and finish the screen via LaunchedEffect in AccountScreen
  • Update AccountActivity to use IntentCompat.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 to account or use the default it 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 when invalidAccount 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 using android.util.Log or ensure your DI setup provides this logger type as expected.
lateinit var logger: Logger

@rfc2822 rfc2822 changed the title Redirect and notify user when account activity is started without account Handle when AccountActivity is started without account May 22, 2025
@rfc2822 rfc2822 merged commit a835557 into main-ose May 22, 2025
9 checks passed
@rfc2822 rfc2822 deleted the 1384-illegalargumentexception-in-accountactivityoncreate branch May 22, 2025 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

IllegalArgumentException in AccountActivity.onCreate
2 participants