Coverage / app/src/main/java/io/oxygenhub/android/MainActivity.kt 0.0%
0 of 34 lines run, 0 of 10 functions, 0 of 18 branches · run #1642 on main · run missed
| 1 | package io.oxygenhub.android | |
| 2 | ||
| 3 | import android.content.Intent | |
| 4 | import android.os.Bundle | |
| 5 | import androidx.activity.ComponentActivity | |
| 6 | import androidx.activity.compose.setContent | |
| 7 | import androidx.activity.enableEdgeToEdge | |
| 8 | import androidx.compose.runtime.getValue | |
| 9 | import androidx.compose.runtime.key | |
| 10 | import androidx.compose.runtime.mutableStateOf | |
| 11 | import io.oxygenhub.android.alerts.LandAlerts | |
| 12 | import io.oxygenhub.android.ui.nav.ProposalRoute | |
| 13 | import androidx.lifecycle.compose.collectAsStateWithLifecycle | |
| 14 | import io.oxygenhub.android.ui.nav.SignedInApp | |
| 15 | import io.oxygenhub.android.ui.nav.rememberViewModel | |
| 16 | import io.oxygenhub.android.ui.signin.SignInScreen | |
| 17 | import io.oxygenhub.android.ui.signin.SignInViewModel | |
| 18 | import io.oxygenhub.android.ui.theme.OxygenHubTheme | |
| 19 | import uniffi.rust_core.oxygenGreeting | |
| 20 | ||
| 21 | class MainActivity : ComponentActivity() { | |
| 22 | /** A proposal a notification asked to open (#20), until it is shown. */ | |
| 23 | private val opening = mutableStateOf<ProposalRoute?>(null) | |
| 24 | ||
| 25 | override fun onCreate(savedInstanceState: Bundle?) { | |
| 26 | super.onCreate(savedInstanceState) | |
| 27 | if (savedInstanceState == null) opening.value = proposalIn(intent) | |
| 28 | enableEdgeToEdge() | |
| 29 | val container = (application as OxygenHubApp).container | |
| 30 | val sessions = container.sessions | |
| 31 | setContent { | |
| 32 | OxygenHubTheme { | |
| 33 | val session by sessions.session.collectAsStateWithLifecycle() | |
| 34 | val signedIn = session | |
| 35 | val api = signedIn?.let { sessions.api() } | |
| 36 | if (signedIn == null || api == null) { | |
| 37 | SignInScreen( | |
| 38 | rememberViewModel { SignInViewModel(sessions, container::deviceAuth, container.clientName, DEFAULT_HUB) }, | |
| 39 | ) | |
| 40 | } else { | |
| 41 | // A new session starts the signed-in app afresh: nothing of the last account's is kept. | |
| 42 | key(signedIn) { | |
| 43 | SignedInApp( | |
| 44 | session = signedIn, | |
| 45 | api = api, | |
| 46 | nativeCore = { oxygenGreeting(signedIn.username) }, | |
| 47 | onSignOut = { sessions.signOut() }, | |
| 48 | open = opening.value, | |
| 49 | onOpened = { opening.value = null }, | |
| 50 | ) | |
| 51 | } | |
| 52 | } | |
| 53 | } | |
| 54 | } | |
| 55 | } | |
| 56 | ||
| 57 | override fun onNewIntent(intent: Intent) { | |
| 58 | super.onNewIntent(intent) | |
| 59 | proposalIn(intent)?.let { opening.value = it } | |
| 60 | } | |
| 61 | ||
| 62 | private fun proposalIn(intent: Intent?): ProposalRoute? { | |
| 63 | val repository = intent?.getStringExtra(LandAlerts.EXTRA_REPOSITORY) ?: return null | |
| 64 | val number = intent.getLongExtra(LandAlerts.EXTRA_NUMBER, 0) | |
| 65 | if ('/' !in repository || number <= 0) return null | |
| 66 | return ProposalRoute(repository.substringBefore('/'), repository.substringAfter('/'), number) | |
| 67 | } | |
| 68 | } |