Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6b5cf8a1 authored by Helen Qin's avatar Helen Qin Committed by Android (Google) Code Review
Browse files

Merge "UX impovements: removed navigation & smoothen dialog transition."

parents 94444a89 b802ce00
Loading
Loading
Loading
Loading
+0 −1
Original line number Original line Diff line number Diff line
@@ -26,7 +26,6 @@ android_app {
        "androidx.lifecycle_lifecycle-livedata",
        "androidx.lifecycle_lifecycle-livedata",
        "androidx.lifecycle_lifecycle-runtime-ktx",
        "androidx.lifecycle_lifecycle-runtime-ktx",
        "androidx.lifecycle_lifecycle-viewmodel-compose",
        "androidx.lifecycle_lifecycle-viewmodel-compose",
        "androidx.navigation_navigation-compose",
        "androidx.recyclerview_recyclerview",
        "androidx.recyclerview_recyclerview",
    ],
    ],


+84 −64
Original line number Original line Diff line number Diff line
@@ -2,14 +2,19 @@ package com.android.credentialmanager


import android.content.Context
import android.content.Context
import com.android.credentialmanager.createflow.CreateOptionInfo
import com.android.credentialmanager.createflow.CreateOptionInfo
import com.android.credentialmanager.createflow.CreatePasskeyUiState
import com.android.credentialmanager.createflow.CreateScreenState
import com.android.credentialmanager.createflow.ProviderInfo
import com.android.credentialmanager.createflow.ProviderInfo
import com.android.credentialmanager.createflow.ProviderList
import com.android.credentialmanager.getflow.CredentialOptionInfo
import com.android.credentialmanager.getflow.CredentialOptionInfo
import com.android.credentialmanager.getflow.GetCredentialUiState
import com.android.credentialmanager.getflow.GetScreenState


// Consider repo per screen, similar to view model?
class CredentialManagerRepo(
class CredentialManagerRepo(
  private val context: Context
  private val context: Context
) {
) {
  fun getCredentialProviderList(): List<com.android.credentialmanager.getflow.ProviderInfo> {
  private fun getCredentialProviderList():
    List<com.android.credentialmanager.getflow.ProviderInfo> {
      return listOf(
      return listOf(
        com.android.credentialmanager.getflow.ProviderInfo(
        com.android.credentialmanager.getflow.ProviderInfo(
          icon = context.getDrawable(R.drawable.ic_passkey)!!,
          icon = context.getDrawable(R.drawable.ic_passkey)!!,
@@ -62,9 +67,8 @@ class CredentialManagerRepo(
      )
      )
  }
  }


  fun createCredentialProviderList(): ProviderList {
  private fun createCredentialProviderList(): List<ProviderInfo> {
    return ProviderList(
    return listOf(
      listOf(
      ProviderInfo(
      ProviderInfo(
        icon = context.getDrawable(R.drawable.ic_passkey)!!,
        icon = context.getDrawable(R.drawable.ic_passkey)!!,
        name = "Google Password Manager",
        name = "Google Password Manager",
@@ -114,6 +118,22 @@ class CredentialManagerRepo(
        )
        )
      ),
      ),
    )
    )
  }

  fun getCredentialInitialUiState(): GetCredentialUiState {
    val providerList = getCredentialProviderList()
    return GetCredentialUiState(
      providerList,
      GetScreenState.CREDENTIAL_SELECTION,
      providerList.first()
    )
  }

  fun createPasskeyInitialUiState(): CreatePasskeyUiState {
    val providerList = createCredentialProviderList()
    return CreatePasskeyUiState(
      providers = providerList,
      currentScreenState = CreateScreenState.PASSKEY_INTRO,
    )
    )
  }
  }


+24 −35
Original line number Original line Diff line number Diff line
package com.android.credentialmanager
package com.android.credentialmanager


import android.os.Bundle
import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.compose.setContent
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import com.android.credentialmanager.common.DialogType
import androidx.navigation.NavHostController
import com.android.credentialmanager.createflow.CreatePasskeyScreen
import androidx.navigation.compose.NavHost
import com.android.credentialmanager.getflow.GetCredentialScreen
import androidx.navigation.compose.rememberNavController
import com.android.credentialmanager.createflow.CreatePasskeyViewModel
import com.android.credentialmanager.createflow.createPasskeyGraph
import com.android.credentialmanager.getflow.GetCredentialViewModel
import com.android.credentialmanager.getflow.getCredentialsGraph
import com.android.credentialmanager.ui.theme.CredentialSelectorTheme
import com.android.credentialmanager.ui.theme.CredentialSelectorTheme


@ExperimentalMaterialApi
@ExperimentalMaterialApi
@@ -22,42 +18,35 @@ class CredentialSelectorActivity : ComponentActivity() {
    CredentialManagerRepo.setup(this)
    CredentialManagerRepo.setup(this)
    val startDestination = intent.extras?.getString(
    val startDestination = intent.extras?.getString(
      "start_destination",
      "start_destination",
      "getCredentials"
      "CREATE_PASSKEY"
    ) ?: "getCredentials"
    ) ?: "CREATE_PASSKEY"


    setContent {
    setContent {
      CredentialSelectorTheme {
      CredentialSelectorTheme {
        AppNavHost(
        CredentialManagerBottomSheet(startDestination)
          startDestination = startDestination,
          onCancel = {this.finish()}
        )
      }
      }
    }
    }
  }
  }


  @ExperimentalMaterialApi
  @ExperimentalMaterialApi
  @Composable
  @Composable
  fun AppNavHost(
  fun CredentialManagerBottomSheet(operationType: String) {
    modifier: Modifier = Modifier,
    val dialogType = DialogType.toDialogType(operationType)
    navController: NavHostController = rememberNavController(),
    when (dialogType) {
    startDestination: String,
      DialogType.CREATE_PASSKEY -> {
    onCancel: () -> Unit,
        CreatePasskeyScreen(cancelActivity = onCancel)
  ) {
    NavHost(
      modifier = modifier,
      navController = navController,
      startDestination = startDestination
    ) {
      createPasskeyGraph(
        navController = navController,
        viewModel = CreatePasskeyViewModel(CredentialManagerRepo.repo),
        onCancel = onCancel
      )
      getCredentialsGraph(
        navController = navController,
        viewModel = GetCredentialViewModel(CredentialManagerRepo.repo),
        onCancel = onCancel
      )
      }
      }
      DialogType.GET_CREDENTIALS -> {
        GetCredentialScreen(cancelActivity = onCancel)
      }
      else -> {
        Log.w("AccountSelector", "Unknown type, not rendering any UI")
        this.finish()
      }
    }
  }

  private val onCancel = {
    this@CredentialSelectorActivity.finish()
  }
  }
}
}
+18 −0
Original line number Original line Diff line number Diff line
package com.android.credentialmanager.common

enum class DialogType {
  CREATE_PASSKEY,
  GET_CREDENTIALS,
  CREATE_PASSWORD,
  UNKNOWN;

  companion object {
    fun toDialogType(value: String): DialogType {
      return try {
        valueOf(value)
      } catch (e: IllegalArgumentException) {
        UNKNOWN
      }
    }
  }
}
+7 −4
Original line number Original line Diff line number Diff line
@@ -10,13 +10,16 @@ data class ProviderInfo(
  val createOptions: List<CreateOptionInfo>,
  val createOptions: List<CreateOptionInfo>,
)
)


data class ProviderList(
  val providers: List<ProviderInfo>,
)

data class CreateOptionInfo(
data class CreateOptionInfo(
  val icon: Drawable,
  val icon: Drawable,
  val title: String,
  val title: String,
  val subtitle: String,
  val subtitle: String,
  val id: String,
  val id: String,
)
)

/** The name of the current screen. */
enum class CreateScreenState {
  PASSKEY_INTRO,
  PROVIDER_SELECTION,
  CREATION_OPTION_SELECTION,
}
Loading