Skip to content

Commit fd553d2

Browse files
committed
Multi accounts - incoming share with account selection
1 parent 30f6db8 commit fd553d2

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

appnav/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ dependencies {
2525
allFeaturesApi(project)
2626

2727
implementation(projects.libraries.core)
28+
implementation(projects.libraries.accountselect.api)
2829
implementation(projects.libraries.androidutils)
2930
implementation(projects.libraries.architecture)
3031
implementation(projects.libraries.deeplink.api)

appnav/src/main/kotlin/io/element/android/appnav/RootFlowNode.kt

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import io.element.android.features.rageshake.api.bugreport.BugReportEntryPoint
4040
import io.element.android.features.rageshake.api.reporter.BugReporter
4141
import io.element.android.features.signedout.api.SignedOutEntryPoint
4242
import io.element.android.features.viewfolder.api.ViewFolderEntryPoint
43+
import io.element.android.libraries.accountselect.api.AccountSelectEntryPoint
4344
import io.element.android.libraries.architecture.BackstackView
4445
import io.element.android.libraries.architecture.BaseFlowNode
4546
import io.element.android.libraries.architecture.createNode
@@ -58,6 +59,7 @@ import io.element.android.libraries.sessionstorage.api.SessionStore
5859
import kotlinx.coroutines.flow.distinctUntilChanged
5960
import kotlinx.coroutines.flow.launchIn
6061
import kotlinx.coroutines.flow.onEach
62+
import kotlinx.coroutines.launch
6163
import kotlinx.parcelize.Parcelize
6264
import timber.log.Timber
6365

@@ -74,6 +76,7 @@ class RootFlowNode(
7476
private val bugReportEntryPoint: BugReportEntryPoint,
7577
private val viewFolderEntryPoint: ViewFolderEntryPoint,
7678
private val signedOutEntryPoint: SignedOutEntryPoint,
79+
private val accountSelectEntryPoint: AccountSelectEntryPoint,
7780
private val intentResolver: IntentResolver,
7881
private val oidcActionFlow: OidcActionFlow,
7982
private val bugReporter: BugReporter,
@@ -184,6 +187,12 @@ class RootFlowNode(
184187
@Parcelize
185188
data object SplashScreen : NavTarget
186189

190+
@Parcelize
191+
data class AccountSelect(
192+
val currentSessionId: SessionId,
193+
val intent: Intent,
194+
) : NavTarget
195+
187196
@Parcelize
188197
data class NotLoggedInFlow(
189198
val params: LoginParams?
@@ -278,6 +287,29 @@ class RootFlowNode(
278287
.callback(callback)
279288
.build()
280289
}
290+
is NavTarget.AccountSelect -> {
291+
val callback: AccountSelectEntryPoint.Callback = object : AccountSelectEntryPoint.Callback {
292+
override fun onAccountSelected(sessionId: SessionId) {
293+
lifecycleScope.launch {
294+
if (sessionId == navTarget.currentSessionId) {
295+
// Ensure that the account selection Node is removed from the backstack
296+
// Do not pop when the account is changed to avoid a UI flicker.
297+
backstack.pop()
298+
}
299+
attachSession(sessionId)
300+
.attachIncomingShare(navTarget.intent)
301+
}
302+
}
303+
304+
override fun onCancel() {
305+
backstack.pop()
306+
}
307+
}
308+
accountSelectEntryPoint
309+
.nodeBuilder(this, buildContext)
310+
.callback(callback)
311+
.build()
312+
}
281313
}
282314
}
283315

@@ -328,9 +360,20 @@ class RootFlowNode(
328360
// No session, open login
329361
switchToNotLoggedInFlow(null)
330362
} else {
331-
// TODO Multi-account: show a screen to select an account
332-
attachSession(latestSessionId)
333-
.attachIncomingShare(intent)
363+
// wait for the current session to be restored
364+
val loggedInFlowNode = attachSession(latestSessionId)
365+
if (sessionStore.getAllSessions().size > 1) {
366+
// Several accounts, let the user choose which one to use
367+
backstack.push(
368+
NavTarget.AccountSelect(
369+
currentSessionId = latestSessionId,
370+
intent = intent,
371+
)
372+
)
373+
} else {
374+
// Only one account, directly attach the incoming share node.
375+
loggedInFlowNode.attachIncomingShare(intent)
376+
}
334377
}
335378
}
336379

0 commit comments

Comments
 (0)