SignInPromptViewModel

open class SignInPromptViewModel(authUserRepository: AuthUserRepository) : ViewModel

A view model for a sign-in prompt screen.

It checks if there is a user already signed in, and emits the appropriate states through the uiState property.

Samples

import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavHostController
import androidx.wear.compose.material.ChipDefaults
import androidx.wear.compose.material.Text
import androidx.wear.compose.navigation.rememberSwipeDismissableNavController
import androidx.wear.compose.ui.tooling.preview.WearPreviewDevices
import com.google.android.horologist.auth.composables.chips.GuestModeChip
import com.google.android.horologist.auth.composables.chips.SignInChip
import com.google.android.horologist.auth.sample.R
import com.google.android.horologist.auth.sample.Screen
import com.google.android.horologist.auth.ui.common.screens.prompt.SignInPromptScreen
import com.google.android.horologist.auth.ui.common.screens.prompt.SignInPromptViewModel
import com.google.android.horologist.auth.ui.googlesignin.prompt.GoogleSignInPromptViewModelFactory
import com.google.android.horologist.compose.layout.ScalingLazyColumnState
import com.google.android.horologist.compose.layout.rememberResponsiveColumnState
import com.google.android.horologist.compose.material.Confirmation

fun main() { 
   //sampleStart 
   var showAlreadySignedInDialog by rememberSaveable { mutableStateOf(false) }

SignInPromptScreen(
    message = stringResource(id = R.string.google_sign_in_prompt_message),
    onAlreadySignedIn = { showAlreadySignedInDialog = true },
    columnState = columnState,
    modifier = modifier,
    viewModel = viewModel,
) {
    item {
        SignInChip(
            onClick = {
                navController.navigate(Screen.GoogleSignInScreen.route) {
                    popUpTo(Screen.MainScreen.route)
                }
            },
            colors = ChipDefaults.secondaryChipColors(),
        )
    }
    item {
        GuestModeChip(
            onClick = navController::popBackStack,
            colors = ChipDefaults.secondaryChipColors(),
        )
    }
}

if (showAlreadySignedInDialog) {
    Confirmation(
        onTimeout = {
            showAlreadySignedInDialog = false
            navController.popBackStack()
        },
    ) {
        Text(
            modifier = Modifier.align(Alignment.CenterHorizontally),
            textAlign = TextAlign.Center,
            text = stringResource(id = R.string.google_sign_in_prompt_already_signed_in_message),
        )
    }
} 
   //sampleEnd
}

Constructors

Link copied to clipboard
constructor(authUserRepository: AuthUserRepository)

Properties

Link copied to clipboard

Functions

Link copied to clipboard
Link copied to clipboard

Indicate that the screen has observed the idle state and that the view model can start its work.