-
-
Notifications
You must be signed in to change notification settings - Fork 48
CCCT-2438 Extract Post-Login Routing And Inline App Seating #3743
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
conroy-ricketts
merged 19 commits into
master
from
CCCT-2438-login-routing-extraction-and-inline-app-seating
Jun 11, 2026
+283
−122
Merged
Changes from 8 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
898d2e0
CCCT-2438 Login Routing Extraction And Inline App Seating
conroy-ricketts 1d3867a
CCCT-2438 Login Routing Extraction And Inline App Seating
conroy-ricketts 9ba972a
CCCT-2438 Login Routing Extraction And Inline App Seating
conroy-ricketts 73503bd
CCCT-2438 Login Routing Extraction And Inline App Seating
conroy-ricketts da47af5
CCCT-2438 Login Routing Extraction And Inline App Seating
conroy-ricketts 403e908
CCCT-2438 Login Routing Extraction And Inline App Seating
conroy-ricketts 507f6d7
CCCT-2438 Login Routing Extraction And Inline App Seating
conroy-ricketts 821ad82
CCCT-2438 Login Routing Extraction And Inline App Seating
conroy-ricketts 66dda6c
Merge remote-tracking branch 'origin/CCCT-2437-headless-login-engine'…
conroy-ricketts d165331
CCCT-2438 Login Routing Extraction And Inline App Seating
conroy-ricketts 94d61c1
CCCT-2438 Login Routing Extraction And Inline App Seating
conroy-ricketts 3f678f7
Merge branch 'CCCT-2437-headless-login-engine' of github.com:dimagi/c…
conroy-ricketts d8c695b
CCCT-2437 Headless Login Engine
conroy-ricketts 10285b8
Merge branch 'master' of github.com:dimagi/commcare-android into CCCT…
conroy-ricketts 48e226b
CCCT-2438 Login Routing Extraction And Inline App Seating
conroy-ricketts 3f67b5a
Merge branch 'master' of github.com:dimagi/commcare-android into CCCT…
conroy-ricketts 6fd3a51
Merge branch 'master' of github.com:dimagi/commcare-android into CCCT…
conroy-ricketts 128a2c9
Merge branch 'master' of github.com:dimagi/commcare-android into CCCT…
conroy-ricketts d6eed61
CCCT-2438 Login Routing Extraction And Inline App Seating
conroy-ricketts File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| package org.commcare.login | ||
|
|
||
| import androidx.lifecycle.LifecycleOwner | ||
| import androidx.lifecycle.lifecycleScope | ||
| import kotlinx.coroutines.CancellationException | ||
| import kotlinx.coroutines.CoroutineDispatcher | ||
| import kotlinx.coroutines.Dispatchers | ||
| import kotlinx.coroutines.Job | ||
| import kotlinx.coroutines.launch | ||
| import kotlinx.coroutines.withContext | ||
| import org.commcare.CommCareApp | ||
| import org.commcare.CommCareApplication | ||
| import org.commcare.android.database.global.models.ApplicationRecord | ||
| import org.commcare.utils.MultipleAppsUtil | ||
| import org.javarosa.core.services.Logger | ||
|
|
||
| sealed class SeatResult { | ||
| object Success : SeatResult() | ||
|
|
||
| data class Failed( | ||
| val reason: SeatFailure, | ||
| ) : SeatResult() | ||
| } | ||
|
|
||
| enum class SeatFailure { | ||
| APP_NOT_FOUND, | ||
| CORRUPTED, | ||
| SEAT_ERROR, | ||
| } | ||
|
|
||
| class AppSeater | ||
| @JvmOverloads | ||
| constructor( | ||
| private val recordLookup: (String) -> ApplicationRecord? = { MultipleAppsUtil.getAppById(it) }, | ||
| private val seatApp: (ApplicationRecord) -> Int = { record -> | ||
|
shubham1g5 marked this conversation as resolved.
|
||
| val app = CommCareApp(record) | ||
| CommCareApplication.instance().initializeAppResources(app) | ||
| app.appResourceState | ||
| }, | ||
| private val ioDispatcher: CoroutineDispatcher = Dispatchers.IO, | ||
| ) { | ||
| fun interface SeatResultCallback { | ||
| fun onResult(result: SeatResult) | ||
| } | ||
|
|
||
| fun start( | ||
| lifecycleOwner: LifecycleOwner, | ||
| appId: String, | ||
| sink: LoginProgressSink, | ||
| callback: SeatResultCallback, | ||
| ): Job = | ||
| lifecycleOwner.lifecycleScope.launch { | ||
| callback.onResult(seatIfNeeded(appId, sink)) | ||
| } | ||
|
|
||
| suspend fun seatIfNeeded( | ||
| appId: String, | ||
| sink: LoginProgressSink, | ||
| ): SeatResult { | ||
| sink.onProgress(LoginProgress(LoginPhase.Seating)) | ||
| return try { | ||
| val record = recordLookup(appId) ?: return SeatResult.Failed(SeatFailure.APP_NOT_FOUND) | ||
| val resourceState = withContext(ioDispatcher) { seatApp(record) } | ||
| if (resourceState == CommCareApplication.STATE_CORRUPTED) { | ||
| SeatResult.Failed(SeatFailure.CORRUPTED) | ||
| } else { | ||
| SeatResult.Success | ||
| } | ||
| } catch (e: CancellationException) { | ||
| throw e | ||
| } catch (e: Exception) { | ||
| Logger.exception("Unexpected error while seating app $appId", e) | ||
| SeatResult.Failed(SeatFailure.SEAT_ERROR) | ||
| } | ||
|
shubham1g5 marked this conversation as resolved.
Outdated
|
||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package org.commcare.login | ||
|
|
||
| import org.commcare.activities.LoginMode | ||
|
|
||
| sealed class PostLoginDestination { | ||
| data class Home( | ||
| val loginMode: LoginMode, | ||
| val startFromLogin: Boolean, | ||
| val manualSwitchToPwMode: Boolean, | ||
| val personalIdManagedLogin: Boolean, | ||
| ) : PostLoginDestination() | ||
|
|
||
| data class TerminalFailure( | ||
| val error: LoginError, | ||
| ) : PostLoginDestination() | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package org.commcare.login | ||
|
|
||
| data class LaunchContext( | ||
| val startFromLogin: Boolean, | ||
| val manualSwitchToPwMode: Boolean, | ||
| ) | ||
|
|
||
| object PostLoginRouter { | ||
| @JvmStatic | ||
| fun route( | ||
| result: LoginResult, | ||
| launchContext: LaunchContext, | ||
| ): PostLoginDestination = | ||
| when (result) { | ||
| is LoginResult.Success -> | ||
| PostLoginDestination.Home( | ||
| loginMode = result.loginMode, | ||
| startFromLogin = launchContext.startFromLogin, | ||
| manualSwitchToPwMode = launchContext.manualSwitchToPwMode, | ||
| personalIdManagedLogin = result.personalIdManagedLogin, | ||
| ) | ||
|
|
||
| is LoginResult.Failed -> | ||
| PostLoginDestination.TerminalFailure(result.error) | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.