-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate provisioning from using legacy APIs to the new apis (#344)
- Loading branch information
1 parent
9798871
commit dd2fcf7
Showing
78 changed files
with
2,994 additions
and
4,110 deletions.
There are no files selected for viewing
This file contains 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
40 changes: 0 additions & 40 deletions
40
appholder/src/main/java/com/android/mdl/app/adapter/ColorAdapter.kt
This file was deleted.
Oops, something went wrong.
This file contains 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 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
6 changes: 6 additions & 0 deletions
6
appholder/src/main/java/com/android/mdl/app/authconfirmation/PassphraseAuthResult.kt
This file contains 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,6 @@ | ||
package com.android.mdl.app.authconfirmation | ||
|
||
sealed class PassphraseAuthResult { | ||
object Idle: PassphraseAuthResult() | ||
data class Success(val userPassphrase: String): PassphraseAuthResult() | ||
} |
103 changes: 103 additions & 0 deletions
103
appholder/src/main/java/com/android/mdl/app/authconfirmation/PassphrasePrompt.kt
This file contains 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,103 @@ | ||
package com.android.mdl.app.authconfirmation | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material3.Card | ||
import androidx.compose.material3.CardDefaults | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.OutlinedTextField | ||
import androidx.compose.material3.Text | ||
import androidx.compose.material3.TextButton | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.platform.ComposeView | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import androidx.fragment.app.DialogFragment | ||
import androidx.fragment.app.activityViewModels | ||
import androidx.navigation.fragment.findNavController | ||
import androidx.navigation.fragment.navArgs | ||
import com.android.mdl.app.R | ||
import com.android.mdl.app.theme.HolderAppTheme | ||
|
||
class PassphrasePrompt : DialogFragment() { | ||
|
||
private val viewModel by activityViewModels<PassphrasePromptViewModel>() | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View { | ||
return ComposeView(requireContext()).apply { | ||
setContent { | ||
HolderAppTheme { | ||
PassphrasePromptUI( | ||
onDone = { passphrase -> | ||
viewModel.authorize(userPassphrase = passphrase) | ||
findNavController().navigateUp() | ||
} | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
private fun PassphrasePromptUI( | ||
onDone: (passphrase: String) -> Unit | ||
) { | ||
var value by remember { mutableStateOf("") } | ||
Card( | ||
modifier = Modifier.fillMaxWidth(), | ||
) { | ||
Column( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.padding(12.dp), | ||
verticalArrangement = Arrangement.spacedBy(12.dp) | ||
) { | ||
Text( | ||
text = stringResource(id = R.string.passphrase_prompt_title), | ||
style = MaterialTheme.typography.displaySmall | ||
) | ||
Text( | ||
text = stringResource(id = R.string.passphrase_prompt_message), | ||
style = MaterialTheme.typography.titleSmall | ||
) | ||
OutlinedTextField( | ||
modifier = Modifier.fillMaxWidth(), | ||
value = value, | ||
onValueChange = { value = it }, | ||
textStyle = MaterialTheme.typography.bodyMedium | ||
) | ||
TextButton( | ||
modifier = Modifier | ||
.align(Alignment.End), | ||
onClick = { onDone(value) }) { | ||
Text(text = stringResource(id = R.string.bt_ok)) | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
@Preview | ||
private fun PreviewPassphrasePrompt() { | ||
HolderAppTheme { | ||
PassphrasePromptUI(onDone = {}) | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
appholder/src/main/java/com/android/mdl/app/authconfirmation/PassphrasePromptViewModel.kt
This file contains 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,21 @@ | ||
package com.android.mdl.app.authconfirmation | ||
|
||
import androidx.lifecycle.ViewModel | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.coroutines.flow.update | ||
|
||
class PassphrasePromptViewModel : ViewModel() { | ||
|
||
private val _authorizationState = | ||
MutableStateFlow<PassphraseAuthResult>(PassphraseAuthResult.Idle) | ||
val authorizationState: StateFlow<PassphraseAuthResult> = _authorizationState | ||
|
||
fun authorize(userPassphrase: String) { | ||
_authorizationState.update { PassphraseAuthResult.Success(userPassphrase) } | ||
} | ||
|
||
fun reset() { | ||
_authorizationState.update { PassphraseAuthResult.Idle } | ||
} | ||
} |
This file contains 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
Oops, something went wrong.